Skip to content

Commit af6f86e

Browse files
committed
Separe ReadOnlyWallet creation
1 parent db0833e commit af6f86e

File tree

2 files changed

+22
-53
lines changed

2 files changed

+22
-53
lines changed

wormhole-connect/src/utils/wallet/ReadOnlyWallet.ts

+20-42
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
Chain as WormholeChain,
33
chainToChainId,
44
NativeAddress,
5-
ChainId,
5+
ChainId as WormholeChainId,
66
} from '@wormhole-foundation/sdk';
77
import { TransferWallet } from '.';
88
import {
@@ -12,7 +12,7 @@ import {
1212
import { Dispatch } from '@reduxjs/toolkit';
1313
import { ConnectedWallet } from './wallet';
1414
import React from 'react';
15-
import { Context } from 'sdklegacy';
15+
import { ChainConfig, Context } from 'sdklegacy';
1616
import config from 'config';
1717
import EventEmitter from 'eventemitter3';
1818

@@ -40,10 +40,6 @@ export class ReadOnlyWallet extends EventEmitter {
4040
return ReadOnlyWallet.NAME;
4141
}
4242

43-
getUrl(): string {
44-
return '';
45-
}
46-
4743
async connect(): Promise<string[]> {
4844
this._isConnected = true;
4945
return [this._address.toString()];
@@ -53,13 +49,8 @@ export class ReadOnlyWallet extends EventEmitter {
5349
this._isConnected = false;
5450
}
5551

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);
6354
}
6455

6556
getAddress(): string {
@@ -70,42 +61,29 @@ export class ReadOnlyWallet extends EventEmitter {
7061
return [this.getAddress()];
7162
}
7263

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-
8264
isConnected(): boolean {
8365
return this._isConnected;
8466
}
8567

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;
10070
}
71+
}
10172

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);
10579

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+
};
10987
}
11088

11189
export function isReadOnlyWallet(wallet: any): wallet is ReadOnlyWalletData {

wormhole-connect/src/views/v2/Bridge/WalletConnector/Sidebar.tsx

+2-11
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import AlertBannerV2 from 'components/v2/AlertBanner';
2626
import { useAvailableWallets } from 'hooks/useAvailableWallets';
2727
import { validateWalletAddress } from 'utils/address';
2828
import { SANCTIONED_WALLETS } from 'consts/wallet';
29-
import { ReadOnlyWallet, ReadOnlyWalletData } from 'utils/wallet/ReadOnlyWallet';
29+
import { createReadOnlyWalletData } from 'utils/wallet/ReadOnlyWallet';
3030

3131
const useStyles = makeStyles()((theme) => ({
3232
listButton: {
@@ -136,16 +136,7 @@ const WalletSidebar = (props: Props) => {
136136
}
137137
}
138138

139-
// TODO: Move this code to ReadOnlyWallet file
140-
const wallet = new ReadOnlyWallet(nativeAddress, selectedChain);
141-
142-
const walletInfo: ReadOnlyWalletData = {
143-
name: wallet.getName(),
144-
type: chainConfig.context,
145-
icon: '',
146-
isReady: true,
147-
wallet,
148-
};
139+
const walletInfo = createReadOnlyWalletData(nativeAddress, selectedChain, chainConfig)
149140

150141
await props.onConnectWallet(walletInfo, props.type, selectedChain)
151142
props.onClose?.();

0 commit comments

Comments
 (0)