2
2
Chain as WormholeChain ,
3
3
chainToChainId ,
4
4
NativeAddress ,
5
- ChainId ,
5
+ ChainId as WormholeChainId ,
6
6
} from '@wormhole-foundation/sdk' ;
7
7
import { TransferWallet } from '.' ;
8
8
import {
@@ -12,7 +12,7 @@ import {
12
12
import { Dispatch } from '@reduxjs/toolkit' ;
13
13
import { ConnectedWallet } from './wallet' ;
14
14
import React from 'react' ;
15
- import { Context } from 'sdklegacy' ;
15
+ import { ChainConfig , Context } from 'sdklegacy' ;
16
16
import config from 'config' ;
17
17
import EventEmitter from 'eventemitter3' ;
18
18
@@ -40,10 +40,6 @@ export class ReadOnlyWallet extends EventEmitter {
40
40
return ReadOnlyWallet . NAME ;
41
41
}
42
42
43
- getUrl ( ) : string {
44
- return '' ;
45
- }
46
-
47
43
async connect ( ) : Promise < string [ ] > {
48
44
this . _isConnected = true ;
49
45
return [ this . _address . toString ( ) ] ;
@@ -53,13 +49,8 @@ export class ReadOnlyWallet extends EventEmitter {
53
49
this . _isConnected = false ;
54
50
}
55
51
56
- getChainId ( ) : ChainId {
57
- // TODO: wallet aggregator should use SDK ChainId type
58
- return chainToChainId ( this . _chain ) as ChainId ;
59
- }
60
-
61
- getNetworkInfo ( ) {
62
- throw new Error ( 'Method not implemented.' ) ;
52
+ getChainId ( ) : WormholeChainId {
53
+ return chainToChainId ( this . _chain ) ;
63
54
}
64
55
65
56
getAddress ( ) : string {
@@ -70,42 +61,29 @@ export class ReadOnlyWallet extends EventEmitter {
70
61
return [ this . getAddress ( ) ] ;
71
62
}
72
63
73
- setMainAddress ( address : string ) : void {
74
- // No-op: can't change address for read-only wallet
75
- }
76
-
77
- async getBalance ( ) : Promise < string > {
78
- // Could implement this to fetch balance from RPC if needed
79
- throw new Error ( 'Address only wallet cannot fetch balance' ) ;
80
- }
81
-
82
64
isConnected ( ) : boolean {
83
65
return this . _isConnected ;
84
66
}
85
67
86
- async signTransaction ( tx : any ) : Promise < any > {
87
- throw new Error ( 'Address only wallet cannot sign transactions' ) ;
88
- }
89
-
90
- async sendTransaction ( tx : any ) : Promise < any > {
91
- throw new Error ( 'Address only wallet cannot send transactions' ) ;
92
- }
93
-
94
- async signMessage ( msg : any ) : Promise < any > {
95
- throw new Error ( 'Address only wallet cannot sign messages' ) ;
96
- }
97
-
98
- async signAndSendTransaction ( tx : any ) : Promise < any > {
99
- throw new Error ( 'Address only wallet cannot sign or send transactions' ) ;
68
+ supportsChain ( chainId : WormholeChainId ) : boolean {
69
+ return this . getChainId ( ) === chainId ;
100
70
}
71
+ }
101
72
102
- getFeatures ( ) : string [ ] {
103
- return [ ] ;
104
- }
73
+ export function createReadOnlyWalletData (
74
+ address : NativeAddress < WormholeChain > ,
75
+ chain : WormholeChain ,
76
+ chainConfig : ChainConfig
77
+ ) : ReadOnlyWalletData {
78
+ const wallet = new ReadOnlyWallet ( address , chain ) ;
105
79
106
- supportsChain ( chainId : ChainId ) : boolean {
107
- return this . getChainId ( ) === chainId ;
108
- }
80
+ return {
81
+ name : wallet . getName ( ) ,
82
+ type : chainConfig . context ,
83
+ icon : '' ,
84
+ isReady : true ,
85
+ wallet,
86
+ } ;
109
87
}
110
88
111
89
export function isReadOnlyWallet ( wallet : any ) : wallet is ReadOnlyWalletData {
0 commit comments