@manahippo/aptos-wallet-adapter 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/WalletAdapters/BaseAdapter.d.ts +6 -6
- package/dist/WalletAdapters/BaseAdapter.d.ts.map +1 -1
- package/dist/WalletAdapters/BitkeepWallet.d.ts +1 -1
- package/dist/WalletAdapters/BitkeepWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/BloctoWallet.d.ts +1 -1
- package/dist/WalletAdapters/BloctoWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/BloctoWallet.js +2 -2
- package/dist/WalletAdapters/BloctoWallet.js.map +1 -1
- package/dist/WalletAdapters/CloverWallet.d.ts +57 -0
- package/dist/WalletAdapters/CloverWallet.d.ts.map +1 -0
- package/dist/WalletAdapters/CloverWallet.js +213 -0
- package/dist/WalletAdapters/CloverWallet.js.map +1 -0
- package/dist/WalletAdapters/Coin98Wallet.d.ts +1 -1
- package/dist/WalletAdapters/Coin98Wallet.d.ts.map +1 -1
- package/dist/WalletAdapters/FoxWallet.d.ts +1 -1
- package/dist/WalletAdapters/FoxWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/MsafeWallet.d.ts +0 -38
- package/dist/WalletAdapters/MsafeWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/MsafeWallet.js +226 -224
- package/dist/WalletAdapters/MsafeWallet.js.map +1 -1
- package/dist/WalletAdapters/NightlyWallet.js +8 -8
- package/dist/WalletAdapters/NightlyWallet.js.map +1 -1
- package/dist/WalletAdapters/ONTOWallet.d.ts +1 -1
- package/dist/WalletAdapters/ONTOWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/OpenBlockWallet.d.ts +56 -0
- package/dist/WalletAdapters/OpenBlockWallet.d.ts.map +1 -0
- package/dist/WalletAdapters/OpenBlockWallet.js +243 -0
- package/dist/WalletAdapters/OpenBlockWallet.js.map +1 -0
- package/dist/WalletAdapters/PetraWallet.d.ts +1 -1
- package/dist/WalletAdapters/PetraWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/PetraWallet.js +1 -1
- package/dist/WalletAdapters/PetraWallet.js.map +1 -1
- package/dist/WalletAdapters/PontemWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/PontemWallet.js +8 -7
- package/dist/WalletAdapters/PontemWallet.js.map +1 -1
- package/dist/WalletAdapters/index.d.ts +2 -1
- package/dist/WalletAdapters/index.d.ts.map +1 -1
- package/dist/WalletAdapters/index.js +3 -1
- package/dist/WalletAdapters/index.js.map +1 -1
- package/dist/WalletProviders/WalletProvider.d.ts.map +1 -1
- package/dist/WalletProviders/WalletProvider.js +6 -7
- package/dist/WalletProviders/WalletProvider.js.map +1 -1
- package/package.json +3 -3
- package/src/WalletAdapters/BloctoWallet.ts +3 -4
- package/src/WalletAdapters/CloverWallet.ts +274 -0
- package/src/WalletAdapters/MsafeWallet.ts +261 -261
- package/src/WalletAdapters/OpenBlockWallet.ts +293 -0
- package/src/WalletAdapters/PetraWallet.ts +1 -1
- package/src/WalletAdapters/PontemWallet.ts +14 -11
- package/src/WalletAdapters/index.ts +3 -1
- package/src/WalletProviders/WalletProvider.tsx +5 -6
@@ -0,0 +1,293 @@
|
|
1
|
+
import { Types } from 'aptos';
|
2
|
+
import {
|
3
|
+
WalletAccountChangeError,
|
4
|
+
WalletDisconnectionError,
|
5
|
+
WalletNetworkChangeError,
|
6
|
+
WalletNotConnectedError,
|
7
|
+
WalletNotReadyError,
|
8
|
+
WalletSignAndSubmitMessageError,
|
9
|
+
WalletSignMessageError,
|
10
|
+
WalletSignTransactionError
|
11
|
+
} from '../WalletProviders/errors';
|
12
|
+
|
13
|
+
import {
|
14
|
+
AccountKeys,
|
15
|
+
BaseWalletAdapter,
|
16
|
+
NetworkInfo,
|
17
|
+
scopePollingDetectionStrategy,
|
18
|
+
SignMessagePayload,
|
19
|
+
SignMessageResponse,
|
20
|
+
WalletAdapterNetwork,
|
21
|
+
WalletName,
|
22
|
+
WalletReadyState
|
23
|
+
} from './BaseAdapter';
|
24
|
+
|
25
|
+
type AddressInfo = { address: string; publicKey: string; authKey?: string };
|
26
|
+
|
27
|
+
interface IOpenBlockWallet {
|
28
|
+
connect: () => Promise<AddressInfo>;
|
29
|
+
account: () => Promise<AddressInfo>;
|
30
|
+
network: () => Promise<NetworkInfo>;
|
31
|
+
isConnected: () => Promise<boolean>;
|
32
|
+
signAndSubmitTransaction(transaction: any): Promise<{ hash: string }>;
|
33
|
+
signTransaction(payload: any): Promise<string>;
|
34
|
+
signMessage(message: SignMessagePayload): Promise<SignMessageResponse>;
|
35
|
+
disconnect(): Promise<void>;
|
36
|
+
onAccountChange: (listener: (newAddress: AddressInfo) => void) => void;
|
37
|
+
onNetworkChange: (listener: (network: NetworkInfo) => void) => void;
|
38
|
+
}
|
39
|
+
|
40
|
+
interface OpenBlockWindow extends Window {
|
41
|
+
openblock?: {
|
42
|
+
aptos?: IOpenBlockWallet;
|
43
|
+
};
|
44
|
+
}
|
45
|
+
|
46
|
+
declare const window: OpenBlockWindow;
|
47
|
+
|
48
|
+
export const OpenBlockWalletName = 'OpenBlock' as WalletName<'OpenBlock'>;
|
49
|
+
|
50
|
+
export interface OpenBlockWalletAdapterConfig {
|
51
|
+
provider?: IOpenBlockWallet;
|
52
|
+
// network?: WalletAdapterNetwork;
|
53
|
+
timeout?: number;
|
54
|
+
}
|
55
|
+
|
56
|
+
export class OpenBlockWalletAdapter extends BaseWalletAdapter {
|
57
|
+
name = OpenBlockWalletName;
|
58
|
+
|
59
|
+
url = 'https://openblock.com/';
|
60
|
+
|
61
|
+
icon = 'https://obstatic.243096.com/download/dapp/sdk/images/logo_blue.svg';
|
62
|
+
|
63
|
+
protected _provider: IOpenBlockWallet;
|
64
|
+
|
65
|
+
protected _network: WalletAdapterNetwork;
|
66
|
+
|
67
|
+
protected _chainId: string;
|
68
|
+
|
69
|
+
protected _api: string;
|
70
|
+
|
71
|
+
protected _timeout: number;
|
72
|
+
|
73
|
+
protected _readyState: WalletReadyState =
|
74
|
+
typeof window === 'undefined' || typeof document === 'undefined'
|
75
|
+
? WalletReadyState.Unsupported
|
76
|
+
: WalletReadyState.NotDetected;
|
77
|
+
|
78
|
+
protected _connecting: boolean;
|
79
|
+
|
80
|
+
protected _wallet: any | null;
|
81
|
+
|
82
|
+
constructor({
|
83
|
+
// provider,
|
84
|
+
// network = WalletAdapterNetwork.Testnet,
|
85
|
+
timeout = 10000
|
86
|
+
}: OpenBlockWalletAdapterConfig = {}) {
|
87
|
+
super();
|
88
|
+
|
89
|
+
this._provider = typeof window !== 'undefined' ? window.openblock?.aptos : undefined;
|
90
|
+
this._network = undefined;
|
91
|
+
this._timeout = timeout;
|
92
|
+
this._connecting = false;
|
93
|
+
this._wallet = null;
|
94
|
+
|
95
|
+
if (typeof window !== 'undefined' && this._readyState !== WalletReadyState.Unsupported) {
|
96
|
+
require('@openblockhq/dappsdk');
|
97
|
+
scopePollingDetectionStrategy(() => {
|
98
|
+
if (window.openblock?.aptos) {
|
99
|
+
this._readyState = WalletReadyState.Installed;
|
100
|
+
this.emit('readyStateChange', this._readyState);
|
101
|
+
return true;
|
102
|
+
}
|
103
|
+
return false;
|
104
|
+
});
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
get publicAccount(): AccountKeys {
|
109
|
+
return {
|
110
|
+
publicKey: this._wallet?.publicKey || null,
|
111
|
+
address: this._wallet?.address || null,
|
112
|
+
authKey: this._wallet?.authKey || null
|
113
|
+
};
|
114
|
+
}
|
115
|
+
|
116
|
+
get network(): NetworkInfo {
|
117
|
+
return {
|
118
|
+
name: this._network,
|
119
|
+
api: this._api,
|
120
|
+
chainId: this._chainId
|
121
|
+
};
|
122
|
+
}
|
123
|
+
|
124
|
+
get connecting(): boolean {
|
125
|
+
return this._connecting;
|
126
|
+
}
|
127
|
+
|
128
|
+
get connected(): boolean {
|
129
|
+
return !!this._wallet?.isConnected;
|
130
|
+
}
|
131
|
+
|
132
|
+
get readyState(): WalletReadyState {
|
133
|
+
return this._readyState;
|
134
|
+
}
|
135
|
+
|
136
|
+
async connect(): Promise<void> {
|
137
|
+
try {
|
138
|
+
if (this.connected || this.connecting) return;
|
139
|
+
if (
|
140
|
+
!(
|
141
|
+
this._readyState === WalletReadyState.Loadable ||
|
142
|
+
this._readyState === WalletReadyState.Installed
|
143
|
+
)
|
144
|
+
)
|
145
|
+
throw new WalletNotReadyError();
|
146
|
+
this._connecting = true;
|
147
|
+
|
148
|
+
const provider = this._provider || window?.openblock?.aptos;
|
149
|
+
const isConnected = await this._provider?.isConnected();
|
150
|
+
if (isConnected === true) {
|
151
|
+
await provider?.disconnect();
|
152
|
+
}
|
153
|
+
|
154
|
+
const response = await provider?.connect();
|
155
|
+
if (response.address) {
|
156
|
+
this._wallet = {
|
157
|
+
address: response?.address,
|
158
|
+
publicKey: response?.publicKey,
|
159
|
+
isConnected: true
|
160
|
+
};
|
161
|
+
const network = await provider?.network();
|
162
|
+
|
163
|
+
this._network = network.name;
|
164
|
+
this._chainId = network.chainId;
|
165
|
+
this._api = network.api;
|
166
|
+
} else {
|
167
|
+
throw new Error('failed to connect');
|
168
|
+
}
|
169
|
+
this.emit('connect', this._wallet.publicKey);
|
170
|
+
} catch (error: any) {
|
171
|
+
this.emit('error', error);
|
172
|
+
throw error;
|
173
|
+
} finally {
|
174
|
+
this._connecting = false;
|
175
|
+
}
|
176
|
+
}
|
177
|
+
|
178
|
+
async disconnect(): Promise<void> {
|
179
|
+
const wallet = this._wallet;
|
180
|
+
const provider = this._provider || window?.openblock?.aptos;
|
181
|
+
if (wallet) {
|
182
|
+
this._wallet = null;
|
183
|
+
|
184
|
+
try {
|
185
|
+
await provider?.disconnect();
|
186
|
+
} catch (error: any) {
|
187
|
+
this.emit('error', new WalletDisconnectionError(error?.message, error));
|
188
|
+
}
|
189
|
+
}
|
190
|
+
|
191
|
+
this.emit('disconnect');
|
192
|
+
}
|
193
|
+
|
194
|
+
async signTransaction(transaction: Types.TransactionPayload): Promise<Uint8Array> {
|
195
|
+
try {
|
196
|
+
const wallet = this._wallet;
|
197
|
+
const provider = this._provider || window?.openblock?.aptos;
|
198
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
199
|
+
|
200
|
+
const response = await provider.signTransaction(transaction);
|
201
|
+
if (response) {
|
202
|
+
return new TextEncoder().encode(response);
|
203
|
+
}
|
204
|
+
throw new Error('failed to SignTransaction');
|
205
|
+
} catch (error: any) {
|
206
|
+
const errMsg = error.message;
|
207
|
+
this.emit('error', new WalletSignTransactionError(errMsg));
|
208
|
+
throw error;
|
209
|
+
}
|
210
|
+
}
|
211
|
+
|
212
|
+
async signAndSubmitTransaction(
|
213
|
+
transaction: Types.TransactionPayload
|
214
|
+
): Promise<{ hash: Types.HexEncodedBytes }> {
|
215
|
+
try {
|
216
|
+
const wallet = this._wallet;
|
217
|
+
const provider = this._provider || window?.openblock?.aptos;
|
218
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
219
|
+
const response = await provider.signAndSubmitTransaction(transaction);
|
220
|
+
if (response) {
|
221
|
+
return response;
|
222
|
+
}
|
223
|
+
throw new Error('Failed to SignAndSubmitTransaction');
|
224
|
+
} catch (error: any) {
|
225
|
+
const errMsg = error.message;
|
226
|
+
this.emit('error', new WalletSignAndSubmitMessageError(errMsg));
|
227
|
+
throw error;
|
228
|
+
}
|
229
|
+
}
|
230
|
+
|
231
|
+
async signMessage(msgPayload: SignMessagePayload): Promise<SignMessageResponse> {
|
232
|
+
try {
|
233
|
+
const wallet = this._wallet;
|
234
|
+
const provider = this._provider || window?.openblock?.aptos;
|
235
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
236
|
+
if (typeof msgPayload !== 'object' || !msgPayload.nonce) {
|
237
|
+
throw new WalletSignMessageError('Invalid signMessage Payload');
|
238
|
+
}
|
239
|
+
|
240
|
+
const response = await provider?.signMessage(msgPayload);
|
241
|
+
if (response) {
|
242
|
+
return response;
|
243
|
+
}
|
244
|
+
|
245
|
+
throw new Error('Failed to signMessage');
|
246
|
+
} catch (error: any) {
|
247
|
+
const errMsg = error.message;
|
248
|
+
this.emit('error', new WalletSignMessageError(errMsg));
|
249
|
+
throw error;
|
250
|
+
}
|
251
|
+
}
|
252
|
+
|
253
|
+
async onAccountChange(): Promise<void> {
|
254
|
+
try {
|
255
|
+
const wallet = this._wallet;
|
256
|
+
const provider = this._provider || window?.openblock?.aptos;
|
257
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
258
|
+
const handleAccountChange = async (newAccount: AddressInfo) => {
|
259
|
+
this._wallet = {
|
260
|
+
...this._wallet,
|
261
|
+
publicKey: newAccount.publicKey || this._wallet?.publicKey,
|
262
|
+
authKey: newAccount.authKey || this._wallet?.authKey,
|
263
|
+
address: newAccount.address || this._wallet?.address
|
264
|
+
};
|
265
|
+
this.emit('accountChange', newAccount.publicKey);
|
266
|
+
};
|
267
|
+
provider?.onAccountChange(handleAccountChange);
|
268
|
+
} catch (error: any) {
|
269
|
+
const errMsg = error.message;
|
270
|
+
this.emit('error', new WalletAccountChangeError(errMsg));
|
271
|
+
throw error;
|
272
|
+
}
|
273
|
+
}
|
274
|
+
|
275
|
+
async onNetworkChange(): Promise<void> {
|
276
|
+
try {
|
277
|
+
const wallet = this._wallet;
|
278
|
+
const provider = this._provider || window?.openblock?.aptos;
|
279
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
280
|
+
const handleNetworkChange = async (newNetwork: NetworkInfo) => {
|
281
|
+
this._network = newNetwork.name;
|
282
|
+
this._api = newNetwork.api;
|
283
|
+
this._chainId = newNetwork.chainId;
|
284
|
+
this.emit('networkChange', this._network);
|
285
|
+
};
|
286
|
+
provider?.onNetworkChange(handleNetworkChange);
|
287
|
+
} catch (error: any) {
|
288
|
+
const errMsg = error.message;
|
289
|
+
this.emit('error', new WalletNetworkChangeError(errMsg));
|
290
|
+
throw error;
|
291
|
+
}
|
292
|
+
}
|
293
|
+
}
|
@@ -175,7 +175,7 @@ export class AptosWalletAdapter extends BaseWalletAdapter {
|
|
175
175
|
throw error;
|
176
176
|
}
|
177
177
|
|
178
|
-
this.emit('connect', this._wallet.
|
178
|
+
this.emit('connect', this._wallet.address);
|
179
179
|
} catch (error: any) {
|
180
180
|
this.emit('error', error);
|
181
181
|
throw error;
|
@@ -287,18 +287,21 @@ export class PontemWalletAdapter extends BaseWalletAdapter {
|
|
287
287
|
if (!wallet || !provider) throw new WalletNotConnectedError();
|
288
288
|
const handleAccountChange = async (newAccount: string | undefined) => {
|
289
289
|
// disconnect wallet if newAccount is undefined
|
290
|
-
if (newAccount
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
290
|
+
if (newAccount) {
|
291
|
+
const newPublicKey = await provider?.publicKey();
|
292
|
+
this._wallet = {
|
293
|
+
...this._wallet,
|
294
|
+
address: newAccount,
|
295
|
+
publicKey: newPublicKey
|
296
|
+
};
|
297
|
+
} else {
|
298
|
+
const response = await provider?.connect();
|
299
|
+
this._wallet = {
|
300
|
+
...this._wallet,
|
301
|
+
address: response?.address || this._wallet?.address,
|
302
|
+
publicKey: response?.publicKey || this._wallet?.publicKey
|
303
|
+
};
|
295
304
|
}
|
296
|
-
const newPublicKey = await provider?.publicKey();
|
297
|
-
this._wallet = {
|
298
|
-
...this._wallet,
|
299
|
-
address: newAccount,
|
300
|
-
publicKey: newPublicKey
|
301
|
-
};
|
302
305
|
this.emit('accountChange', newAccount);
|
303
306
|
};
|
304
307
|
await provider?.onAccountChange(handleAccountChange);
|
@@ -18,4 +18,6 @@ export * from './BloctoWallet';
|
|
18
18
|
export * from './Coin98Wallet';
|
19
19
|
export * from './SafePalWallet';
|
20
20
|
export * from './FoxWallet';
|
21
|
-
export * from './MsafeWallet';
|
21
|
+
// export * from './MsafeWallet';
|
22
|
+
export * from './OpenBlockWallet';
|
23
|
+
export * from './CloverWallet';
|
@@ -58,7 +58,7 @@ export const WalletProvider: FC<WalletProviderProps> = ({
|
|
58
58
|
const readyState = adapter?.readyState || WalletReadyState.Unsupported;
|
59
59
|
const [connecting, setConnecting] = useState(false);
|
60
60
|
const [disconnecting, setDisconnecting] = useState(false);
|
61
|
-
const isConnecting = useRef(false);
|
61
|
+
// const isConnecting = useRef(false);
|
62
62
|
const isDisconnecting = useRef(false);
|
63
63
|
const isUnloading = useRef(false);
|
64
64
|
|
@@ -226,7 +226,7 @@ export const WalletProvider: FC<WalletProviderProps> = ({
|
|
226
226
|
// Connect the adapter to the wallet
|
227
227
|
const connect = useCallback(
|
228
228
|
async (walletName?) => {
|
229
|
-
if (
|
229
|
+
if (isDisconnecting.current || connected || !walletName) return;
|
230
230
|
let walletToConnect = initialState;
|
231
231
|
if (!adapter || walletName !== adapter?.name) {
|
232
232
|
const selectedWallet = wallets.find((wAdapter) => wAdapter.adapter.name === walletName);
|
@@ -266,7 +266,7 @@ export const WalletProvider: FC<WalletProviderProps> = ({
|
|
266
266
|
|
267
267
|
throw handleError(new WalletNotReadyError('Wallet Not Ready'));
|
268
268
|
}
|
269
|
-
isConnecting.current = true;
|
269
|
+
// isConnecting.current = true;
|
270
270
|
setConnecting(true);
|
271
271
|
try {
|
272
272
|
const timeout = timeoutPromise(TIMEOUT * 1000);
|
@@ -282,7 +282,7 @@ export const WalletProvider: FC<WalletProviderProps> = ({
|
|
282
282
|
}
|
283
283
|
} finally {
|
284
284
|
setConnecting(false);
|
285
|
-
isConnecting.current = false;
|
285
|
+
// isConnecting.current = false;
|
286
286
|
}
|
287
287
|
},
|
288
288
|
[connected, adapter, handleError, wallets, setName, wallet, account, network]
|
@@ -291,7 +291,6 @@ export const WalletProvider: FC<WalletProviderProps> = ({
|
|
291
291
|
// If autoConnect is enabled, try to connect when the adapter changes and is ready
|
292
292
|
useEffect(() => {
|
293
293
|
if (
|
294
|
-
isConnecting.current ||
|
295
294
|
connected ||
|
296
295
|
!autoConnect ||
|
297
296
|
!name ||
|
@@ -300,7 +299,7 @@ export const WalletProvider: FC<WalletProviderProps> = ({
|
|
300
299
|
)
|
301
300
|
return;
|
302
301
|
connect(name);
|
303
|
-
}, [
|
302
|
+
}, [connected, autoConnect, name, connect, adapter, readyState]);
|
304
303
|
|
305
304
|
// Disconnect the adapter from the wallet
|
306
305
|
const disconnect = useCallback(async () => {
|