11import { Chain } from '@chain-registry/types' ;
2+ import type { StdSignature } from '@interchainjs/amino' ;
23import { AminoSignResponse , DirectSignResponse , SignOptions } from '@interchainjs/cosmos' ;
34import { StdSignDoc } from '@interchainjs/types' ;
45import { PairingTypes , SessionTypes , SignClientTypes } from '@walletconnect/types' ;
56import UniversalProvider , { ConnectParams , UniversalProviderOpts } from '@walletconnect/universal-provider' ;
67import { fromByteArray , toByteArray } from 'base64-js' ;
7-
8-
9- import type { Algo , StdSignature } from '@interchainjs/amino' ;
10- import { MultiChainWallet } from '../multichain-wallet' ;
118import { BroadcastMode } from 'interchainjs' ;
9+
1210import { WalletConnectIcon } from '../../constant' ;
13- import { WalletAccount , Wallet , SignType , DirectSignDoc , WCDirectSignResponse , WcEventTypes , WcProviderEventType } from '../../types' ;
11+ import { DirectSignDoc , SignType , Wallet , WalletAccount , WCDirectSignResponse , WcEventTypes , WcProviderEventType } from '../../types' ;
12+ import { MultiChainWallet } from '../multichain-wallet' ;
1413import { isWCCommon } from './wc-common' ;
1514
1615
@@ -83,7 +82,7 @@ export class WCWallet extends MultiChainWallet {
8382 wallet . setWCProvider ( this . provider ) ;
8483 wallet . setWCWallet ( this ) ;
8584 }
86- wallet . info = this . info
85+ wallet . info = this . info ;
8786 wallet . chainMap = this . chainMap ;
8887 } ) ;
8988
@@ -159,13 +158,8 @@ export class WCWallet extends MultiChainWallet {
159158 if ( solanaChainNS . length ) {
160159 connectParam . namespaces . solana = {
161160 methods : [
162- 'solana_accounts' ,
163161 'solana_signTransaction' ,
164- 'solana_signAllTransactions' ,
165- 'solana_signAndSendTransaction' ,
166- 'solana_signAndSendAllTransactions' ,
167162 'solana_signMessage' ,
168- 'solana_signIn' ,
169163 ] ,
170164 chains : solanaChainNS ,
171165 events : [ ]
@@ -227,43 +221,12 @@ export class WCWallet extends MultiChainWallet {
227221 }
228222
229223 async getAccount ( chainId : Chain [ 'chainId' ] ) : Promise < WalletAccount > {
230-
231- if ( this . accountToRestore ) {
232- return this . accountToRestore ;
233- }
234-
235- const account = await this . getCosmosAccount ( chainId ) ;
236-
237- return {
238- address : account . address ,
239- algo : 'secp256k1' ,
240- pubkey : toByteArray ( account . pubkey ) ,
241- username : '' ,
242- isNanoLedger : null ,
243- isSmartContract : null
244- } ;
224+ const chain = this . getChainById ( chainId ) ;
225+ const wallet = this . getWalletByChainType ( chain . chainType ) ;
226+ return wallet . getAccount ( chainId ) ;
245227 }
246228
247- async getCosmosAccount ( chainId : string ) : Promise < { address : string , algo : Algo , pubkey : string } > {
248-
249- try {
250229
251- const accounts = await this . provider . request ( {
252- method : 'cosmos_getAccounts' ,
253- params : [ ]
254- } , `cosmos:${ chainId } ` ) as any [ ] ;
255-
256- const { address, algo, pubkey } = accounts [ 0 ] ;
257- return {
258- address,
259- algo : algo as Algo ,
260- pubkey : pubkey ,
261- } ;
262- } catch ( error ) {
263- console . log ( 'get cosmos account error' , error ) ;
264- throw error ;
265- }
266- }
267230
268231 async getOfflineSigner ( chainId : string , preferredSignType ?: SignType ) {
269232 if ( preferredSignType === 'amino' ) {
@@ -272,14 +235,14 @@ export class WCWallet extends MultiChainWallet {
272235 signAmino : async ( signer : string , signDoc : StdSignDoc ) => {
273236 return this . signAmino ( chainId , signer , signDoc ) ;
274237 }
275- }
238+ } ;
276239 } else if ( preferredSignType === 'direct' ) {
277240 return {
278241 getAccounts : async ( ) => [ await this . getAccount ( chainId ) ] ,
279242 signDirect : async ( signer : string , signDoc : DirectSignDoc ) => {
280243 return this . signDirect ( chainId , signer , signDoc ) ;
281244 }
282- }
245+ } ;
283246 }
284247 }
285248
@@ -370,12 +333,12 @@ export class WCWallet extends MultiChainWallet {
370333 console . error ( 'disconnect:' , error ) ;
371334 } ) ;
372335
373- this . provider . on ( " session_delete" , ( error : { message : string ; code : number } ) => {
374- console . log ( " session_delete:" , error ) ;
375- localStorage . removeItem ( 'wc-session' )
336+ this . provider . on ( ' session_delete' , ( error : { message : string ; code : number } ) => {
337+ console . log ( ' session_delete:' , error ) ;
338+ localStorage . removeItem ( 'wc-session' ) ;
376339
377340 // Emit disconnect event to notify StatefulWallet
378- this . events . emit ( 'disconnect' , '' )
341+ this . events . emit ( 'disconnect' , '' ) ;
379342 } ) ;
380343
381344 this . provider . on ( 'session_event' , ( error : { message : string ; code : number } ) => {
0 commit comments