@manahippo/aptos-wallet-adapter 0.2.0 → 0.3.1
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 +21 -19
- package/dist/WalletAdapters/AptosWallet.d.ts +18 -7
- package/dist/WalletAdapters/AptosWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/AptosWallet.js +47 -32
- package/dist/WalletAdapters/AptosWallet.js.map +1 -1
- package/dist/WalletAdapters/BaseAdapter.d.ts +10 -6
- package/dist/WalletAdapters/BaseAdapter.d.ts.map +1 -1
- package/dist/WalletAdapters/BaseAdapter.js.map +1 -1
- package/dist/WalletAdapters/FewchaWallet.d.ts +7 -4
- package/dist/WalletAdapters/FewchaWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/FewchaWallet.js +90 -88
- package/dist/WalletAdapters/FewchaWallet.js.map +1 -1
- package/dist/WalletAdapters/HippoExtensionWallet.d.ts +8 -4
- package/dist/WalletAdapters/HippoExtensionWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/HippoExtensionWallet.js +27 -5
- package/dist/WalletAdapters/HippoExtensionWallet.js.map +1 -1
- package/dist/WalletAdapters/HippoWallet.d.ts +7 -4
- package/dist/WalletAdapters/HippoWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/HippoWallet.js +28 -2
- package/dist/WalletAdapters/HippoWallet.js.map +1 -1
- package/dist/WalletAdapters/MartianWallet.d.ts +11 -6
- package/dist/WalletAdapters/MartianWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/MartianWallet.js +51 -35
- package/dist/WalletAdapters/MartianWallet.js.map +1 -1
- package/dist/WalletAdapters/NightlyWallet.d.ts +1 -41
- package/dist/WalletAdapters/NightlyWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/NightlyWallet.js +232 -198
- package/dist/WalletAdapters/NightlyWallet.js.map +1 -1
- package/dist/WalletAdapters/PontemWallet.d.ts +57 -0
- package/dist/WalletAdapters/PontemWallet.d.ts.map +1 -0
- package/dist/WalletAdapters/PontemWallet.js +182 -0
- package/dist/WalletAdapters/PontemWallet.js.map +1 -0
- package/dist/WalletAdapters/SpikaWallet.d.ts +46 -0
- package/dist/WalletAdapters/SpikaWallet.d.ts.map +1 -0
- package/dist/WalletAdapters/{MultiMaskWallet.js → SpikaWallet.js} +72 -83
- package/dist/WalletAdapters/SpikaWallet.js.map +1 -0
- package/dist/WalletAdapters/index.d.ts +2 -2
- package/dist/WalletAdapters/index.d.ts.map +1 -1
- package/dist/WalletAdapters/index.js +3 -2
- package/dist/WalletAdapters/index.js.map +1 -1
- package/dist/WalletProviders/WalletProvider.d.ts +0 -1
- package/dist/WalletProviders/WalletProvider.d.ts.map +1 -1
- package/dist/WalletProviders/WalletProvider.js +10 -7
- package/dist/WalletProviders/WalletProvider.js.map +1 -1
- package/dist/WalletProviders/useWallet.d.ts +5 -3
- package/dist/WalletProviders/useWallet.d.ts.map +1 -1
- package/dist/WalletProviders/useWallet.js +1 -1
- package/dist/WalletProviders/useWallet.js.map +1 -1
- package/dist/config/aptosConstants.d.ts +2 -2
- package/dist/config/aptosConstants.d.ts.map +1 -1
- package/dist/config/aptosConstants.js +1 -1
- package/dist/config/aptosConstants.js.map +1 -1
- package/dist/hooks/useLocalStorage.d.ts.map +1 -1
- package/dist/hooks/useLocalStorage.js +9 -4
- package/dist/hooks/useLocalStorage.js.map +1 -1
- package/dist/hooks/useSSR.d.ts +4 -0
- package/dist/hooks/useSSR.d.ts.map +1 -0
- package/dist/hooks/useSSR.js +17 -0
- package/dist/hooks/useSSR.js.map +1 -0
- package/dist/utilities/util.d.ts +8 -0
- package/dist/utilities/util.d.ts.map +1 -0
- package/dist/utilities/util.js +14 -0
- package/dist/utilities/util.js.map +1 -0
- package/package.json +10 -10
- package/src/WalletAdapters/AptosWallet.ts +63 -37
- package/src/WalletAdapters/BaseAdapter.ts +14 -16
- package/src/WalletAdapters/FewchaWallet.ts +97 -81
- package/src/WalletAdapters/HippoExtensionWallet.ts +32 -9
- package/src/WalletAdapters/HippoWallet.ts +35 -7
- package/src/WalletAdapters/MartianWallet.ts +57 -42
- package/src/WalletAdapters/NightlyWallet.ts +230 -229
- package/src/WalletAdapters/PontemWallet.ts +250 -0
- package/src/WalletAdapters/SpikaWallet.ts +229 -0
- package/src/WalletAdapters/index.ts +3 -2
- package/src/WalletProviders/WalletProvider.tsx +12 -10
- package/src/WalletProviders/useWallet.ts +7 -14
- package/src/config/aptosConstants.ts +1 -1
- package/src/hooks/useLocalStorage.ts +9 -4
- package/src/hooks/useSSR.ts +15 -0
- package/src/utilities/util.ts +11 -0
- package/dist/WalletAdapters/MultiMaskWallet.d.ts +0 -39
- package/dist/WalletAdapters/MultiMaskWallet.d.ts.map +0 -1
- package/dist/WalletAdapters/MultiMaskWallet.js.map +0 -1
- package/src/WalletAdapters/MultiMaskWallet.ts +0 -245
@@ -1,16 +1,13 @@
|
|
1
1
|
import {
|
2
|
-
|
3
|
-
SubmitTransactionRequest,
|
4
|
-
TransactionPayload
|
5
|
-
} from 'aptos/dist/api/data-contracts';
|
6
|
-
import { aptosClient, WEBWALLET_URL } from '../config/aptosConstants';
|
7
|
-
import {
|
2
|
+
WalletConnectionError,
|
8
3
|
WalletDisconnectionError,
|
9
4
|
WalletNotConnectedError,
|
10
5
|
WalletNotReadyError,
|
6
|
+
WalletSignAndSubmitMessageError,
|
7
|
+
WalletSignMessageError,
|
11
8
|
WalletSignTransactionError
|
12
9
|
} from '../WalletProviders/errors';
|
13
|
-
import Web3, {
|
10
|
+
import Web3, { Web3ProviderType } from '@fewcha/web3';
|
14
11
|
import {
|
15
12
|
AccountKeys,
|
16
13
|
BaseWalletAdapter,
|
@@ -18,8 +15,14 @@ import {
|
|
18
15
|
WalletName,
|
19
16
|
WalletReadyState
|
20
17
|
} from './BaseAdapter';
|
18
|
+
import {
|
19
|
+
TransactionPayload,
|
20
|
+
SubmitTransactionRequest,
|
21
|
+
HexEncodedBytes,
|
22
|
+
EntryFunctionPayload
|
23
|
+
} from 'aptos/dist/generated';
|
21
24
|
|
22
|
-
export const FewchaWalletName = 'Fewcha
|
25
|
+
export const FewchaWalletName = 'Fewcha' as WalletName<'Fewcha'>;
|
23
26
|
|
24
27
|
interface FewchaWindow extends Window {
|
25
28
|
fewcha: Web3ProviderType;
|
@@ -27,8 +30,6 @@ interface FewchaWindow extends Window {
|
|
27
30
|
|
28
31
|
declare const window: FewchaWindow;
|
29
32
|
|
30
|
-
const defaultWeb3 = new Web3(new Web3Provider(window.fewcha));
|
31
|
-
|
32
33
|
export interface FewchaAdapterConfig {
|
33
34
|
provider?: string;
|
34
35
|
// network?: WalletAdapterNetwork;
|
@@ -60,14 +61,13 @@ export class FewchaWalletAdapter extends BaseWalletAdapter {
|
|
60
61
|
}: FewchaAdapterConfig = {}) {
|
61
62
|
super();
|
62
63
|
|
63
|
-
this._provider = defaultWeb3.action;
|
64
64
|
// this._network = network;
|
65
65
|
this._timeout = timeout;
|
66
66
|
this._connecting = false;
|
67
67
|
this._wallet = null;
|
68
68
|
// this._readyState = WalletReadyState.Installed;
|
69
69
|
|
70
|
-
if (this._readyState !== WalletReadyState.Unsupported) {
|
70
|
+
if (typeof window !== 'undefined' && this._readyState !== WalletReadyState.Unsupported) {
|
71
71
|
scopePollingDetectionStrategy(() => {
|
72
72
|
if (window.fewcha) {
|
73
73
|
this._readyState = WalletReadyState.Installed;
|
@@ -77,28 +77,6 @@ export class FewchaWalletAdapter extends BaseWalletAdapter {
|
|
77
77
|
return false;
|
78
78
|
});
|
79
79
|
}
|
80
|
-
|
81
|
-
window.addEventListener('aptos#connected', async () => {
|
82
|
-
const publicAccount = await this._provider?.account();
|
83
|
-
const isConnected = await this._provider?.isConnected();
|
84
|
-
if (publicAccount?.data.publicKey && isConnected) {
|
85
|
-
this._wallet = {
|
86
|
-
connected: isConnected,
|
87
|
-
...publicAccount.data
|
88
|
-
};
|
89
|
-
this.emit('connect', this._wallet.publicKey);
|
90
|
-
}
|
91
|
-
});
|
92
|
-
|
93
|
-
window.addEventListener('aptos#transaction', (e: any) => {
|
94
|
-
if (e?.detail?.tx) {
|
95
|
-
this.emit('success', e?.detail?.tx);
|
96
|
-
}
|
97
|
-
});
|
98
|
-
|
99
|
-
window.addEventListener('aptos#disconnected', () => {
|
100
|
-
this.emit('disconnect');
|
101
|
-
});
|
102
80
|
}
|
103
81
|
|
104
82
|
get publicAccount(): AccountKeys {
|
@@ -133,12 +111,32 @@ export class FewchaWalletAdapter extends BaseWalletAdapter {
|
|
133
111
|
throw new WalletNotReadyError();
|
134
112
|
|
135
113
|
this._connecting = true;
|
136
|
-
const provider =
|
137
|
-
const isConnected = await
|
138
|
-
if (isConnected) {
|
139
|
-
await provider
|
114
|
+
const provider = new Web3().action;
|
115
|
+
const isConnected = await provider.isConnected();
|
116
|
+
if (isConnected?.data === true) {
|
117
|
+
await provider.disconnect();
|
118
|
+
}
|
119
|
+
const response = await provider.connect();
|
120
|
+
if (response.status === 401) {
|
121
|
+
throw new WalletConnectionError('User has rejected the connection');
|
122
|
+
} else if (response.status !== 200) {
|
123
|
+
throw new WalletConnectionError('Wallet connect issue');
|
124
|
+
}
|
125
|
+
let accountDetail = { ...response.data };
|
126
|
+
|
127
|
+
if (!accountDetail.publicKey) {
|
128
|
+
const accountResp = await provider.account();
|
129
|
+
if (!accountResp.data.publicKey) {
|
130
|
+
throw new WalletConnectionError('Wallet connect issue', response.data);
|
131
|
+
}
|
132
|
+
accountDetail = { ...accountResp.data };
|
140
133
|
}
|
141
|
-
|
134
|
+
this._wallet = {
|
135
|
+
connected: true,
|
136
|
+
...accountDetail
|
137
|
+
};
|
138
|
+
this._provider = provider;
|
139
|
+
this.emit('connect', this._wallet.publicKey);
|
142
140
|
} catch (error: any) {
|
143
141
|
this.emit('error', error);
|
144
142
|
throw error;
|
@@ -148,68 +146,86 @@ export class FewchaWalletAdapter extends BaseWalletAdapter {
|
|
148
146
|
}
|
149
147
|
|
150
148
|
async disconnect(): Promise<void> {
|
151
|
-
const
|
152
|
-
if (
|
153
|
-
this._wallet = null;
|
154
|
-
|
149
|
+
const provider = this._provider;
|
150
|
+
if (provider) {
|
155
151
|
try {
|
156
|
-
const
|
157
|
-
|
152
|
+
const isDisconnected = await provider.disconnect();
|
153
|
+
if (isDisconnected.data === true) {
|
154
|
+
this._provider = undefined;
|
155
|
+
this._wallet = null;
|
156
|
+
} else {
|
157
|
+
throw new Error('Disconnect failed');
|
158
|
+
}
|
158
159
|
} catch (error: any) {
|
159
160
|
this.emit('error', new WalletDisconnectionError(error?.message, error));
|
161
|
+
throw error;
|
160
162
|
}
|
161
163
|
}
|
164
|
+
this.emit('disconnect');
|
162
165
|
}
|
163
166
|
|
164
167
|
async signTransaction(transaction: TransactionPayload): Promise<SubmitTransactionRequest> {
|
165
168
|
try {
|
166
|
-
const
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
'
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
const promise = await new Promise((resolve, reject) => {
|
180
|
-
this.once('success', resolve);
|
181
|
-
this.once('error', reject);
|
182
|
-
});
|
183
|
-
return promise as SubmitTransactionRequest;
|
169
|
+
const wallet = this._wallet;
|
170
|
+
if (!wallet) throw new WalletNotConnectedError();
|
171
|
+
|
172
|
+
const provider = this._provider || window.fewcha;
|
173
|
+
const tx = await provider.generateTransaction(transaction as EntryFunctionPayload);
|
174
|
+
if (!tx) throw new Error('Cannot generate transaction');
|
175
|
+
const response = await provider?.signTransaction(tx.data);
|
176
|
+
|
177
|
+
if (!response) {
|
178
|
+
throw new Error('No response');
|
179
|
+
}
|
180
|
+
const result = { hash: response } as any;
|
181
|
+
return result as SubmitTransactionRequest;
|
184
182
|
} catch (error: any) {
|
185
|
-
|
183
|
+
const errMsg = error instanceof Error ? error.message : error.response.data.message;
|
184
|
+
this.emit('error', new WalletSignTransactionError(errMsg));
|
186
185
|
throw error;
|
187
186
|
}
|
188
187
|
}
|
189
188
|
|
190
|
-
async signAndSubmitTransaction(
|
189
|
+
async signAndSubmitTransaction(
|
190
|
+
transaction: TransactionPayload
|
191
|
+
): Promise<{ hash: HexEncodedBytes }> {
|
191
192
|
try {
|
192
193
|
const wallet = this._wallet;
|
193
194
|
if (!wallet) throw new WalletNotConnectedError();
|
194
195
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
});
|
204
|
-
return {
|
205
|
-
hash: promise
|
206
|
-
} as PendingTransaction;
|
207
|
-
} catch (error: any) {
|
208
|
-
const errMsg = error instanceof Error ? error.message : error.response.data.message;
|
209
|
-
throw new WalletSignTransactionError(errMsg);
|
196
|
+
const provider = this._provider || window.fewcha;
|
197
|
+
const tx = await provider.generateTransaction(transaction as EntryFunctionPayload);
|
198
|
+
if (!tx) throw new Error('Cannot generate transaction');
|
199
|
+
const response = await provider?.signAndSubmitTransaction(tx.data);
|
200
|
+
if (response.status === 401) {
|
201
|
+
throw new Error('User has rejected the transaction');
|
202
|
+
} else if (response.status !== 200) {
|
203
|
+
throw new Error('Transaction issue');
|
210
204
|
}
|
205
|
+
return {
|
206
|
+
hash: response.data
|
207
|
+
};
|
211
208
|
} catch (error: any) {
|
212
|
-
|
209
|
+
const errMsg = error instanceof Error ? error.message : error.response.data.message;
|
210
|
+
this.emit('error', new WalletSignAndSubmitMessageError(errMsg));
|
211
|
+
throw error;
|
212
|
+
}
|
213
|
+
}
|
214
|
+
|
215
|
+
async signMessage(message: string): Promise<string> {
|
216
|
+
try {
|
217
|
+
const wallet = this._wallet;
|
218
|
+
const provider = this._provider || window.fewcha;
|
219
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
220
|
+
const response = await provider?.signMessage(message);
|
221
|
+
if (response) {
|
222
|
+
return response.data;
|
223
|
+
} else {
|
224
|
+
throw new Error('Sign Message failed');
|
225
|
+
}
|
226
|
+
} catch (error: any) {
|
227
|
+
const errMsg = error.message;
|
228
|
+
this.emit('error', new WalletSignMessageError(errMsg));
|
213
229
|
throw error;
|
214
230
|
}
|
215
231
|
}
|
@@ -1,13 +1,15 @@
|
|
1
1
|
import { MaybeHexString } from 'aptos';
|
2
2
|
import {
|
3
|
-
|
3
|
+
TransactionPayload,
|
4
4
|
SubmitTransactionRequest,
|
5
|
-
|
6
|
-
} from 'aptos/dist/
|
5
|
+
HexEncodedBytes
|
6
|
+
} from 'aptos/dist/generated';
|
7
7
|
import {
|
8
8
|
WalletDisconnectionError,
|
9
9
|
WalletNotConnectedError,
|
10
10
|
WalletNotReadyError,
|
11
|
+
WalletSignAndSubmitMessageError,
|
12
|
+
WalletSignMessageError,
|
11
13
|
WalletSignTransactionError
|
12
14
|
} from '../WalletProviders/errors';
|
13
15
|
import {
|
@@ -28,6 +30,7 @@ interface IHippoWallet {
|
|
28
30
|
isConnected: () => Promise<boolean>;
|
29
31
|
signAndSubmitTransaction(transaction: any): Promise<any>;
|
30
32
|
signTransaction(transaction: any): Promise<void>;
|
33
|
+
signMessage(message: string): Promise<string>;
|
31
34
|
disconnect(): Promise<void>;
|
32
35
|
}
|
33
36
|
|
@@ -37,7 +40,7 @@ interface HippoWindow extends Window {
|
|
37
40
|
|
38
41
|
declare const window: HippoWindow;
|
39
42
|
|
40
|
-
export const HippoExtensionWalletName = 'Hippo
|
43
|
+
export const HippoExtensionWalletName = 'Hippo' as WalletName<'Hippo'>;
|
41
44
|
|
42
45
|
export interface HippoExtensionWalletAdapterConfig {
|
43
46
|
provider?: IHippoWallet;
|
@@ -73,13 +76,13 @@ export class HippoExtensionWalletAdapter extends BaseWalletAdapter {
|
|
73
76
|
}: HippoExtensionWalletAdapterConfig = {}) {
|
74
77
|
super();
|
75
78
|
|
76
|
-
this._provider = window.hippoWallet;
|
79
|
+
this._provider = typeof window !== 'undefined' ? window.hippoWallet : undefined;
|
77
80
|
// this._network = network;
|
78
81
|
this._timeout = timeout;
|
79
82
|
this._connecting = false;
|
80
83
|
this._wallet = null;
|
81
84
|
|
82
|
-
if (this._readyState !== WalletReadyState.Unsupported) {
|
85
|
+
if (typeof window !== 'undefined' && this._readyState !== WalletReadyState.Unsupported) {
|
83
86
|
scopePollingDetectionStrategy(() => {
|
84
87
|
if (window.hippoWallet) {
|
85
88
|
this._readyState = WalletReadyState.Installed;
|
@@ -178,7 +181,9 @@ export class HippoExtensionWalletAdapter extends BaseWalletAdapter {
|
|
178
181
|
}
|
179
182
|
}
|
180
183
|
|
181
|
-
async signAndSubmitTransaction(
|
184
|
+
async signAndSubmitTransaction(
|
185
|
+
transaction: TransactionPayload
|
186
|
+
): Promise<{ hash: HexEncodedBytes }> {
|
182
187
|
try {
|
183
188
|
const wallet = this._wallet;
|
184
189
|
if (!wallet) throw new WalletNotConnectedError();
|
@@ -187,17 +192,35 @@ export class HippoExtensionWalletAdapter extends BaseWalletAdapter {
|
|
187
192
|
const provider = this._provider || window.hippoWallet;
|
188
193
|
const response = await provider?.signAndSubmitTransaction(transaction);
|
189
194
|
if (response) {
|
190
|
-
return response.detail;
|
195
|
+
return response.detail.hash;
|
191
196
|
} else {
|
192
197
|
throw new Error('Transaction failed');
|
193
198
|
}
|
194
199
|
} catch (error: any) {
|
195
200
|
// console.log('transact err', error, error.message);
|
196
|
-
throw new
|
201
|
+
throw new WalletSignAndSubmitMessageError(error.message || error);
|
197
202
|
}
|
198
203
|
} catch (error: any) {
|
199
204
|
this.emit('error', error);
|
200
205
|
throw error;
|
201
206
|
}
|
202
207
|
}
|
208
|
+
|
209
|
+
async signMessage(message: string): Promise<string> {
|
210
|
+
try {
|
211
|
+
const wallet = this._wallet;
|
212
|
+
const provider = this._provider || window.hippoWallet;
|
213
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
214
|
+
const response = await provider?.signMessage(message);
|
215
|
+
if (response) {
|
216
|
+
return response;
|
217
|
+
} else {
|
218
|
+
throw new Error('Sign Message failed');
|
219
|
+
}
|
220
|
+
} catch (error: any) {
|
221
|
+
const errMsg = error.message;
|
222
|
+
this.emit('error', new WalletSignMessageError(errMsg));
|
223
|
+
throw error;
|
224
|
+
}
|
225
|
+
}
|
203
226
|
}
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { MaybeHexString } from 'aptos';
|
2
2
|
import {
|
3
|
-
|
3
|
+
TransactionPayload,
|
4
4
|
SubmitTransactionRequest,
|
5
|
-
|
6
|
-
} from 'aptos/dist/
|
5
|
+
HexEncodedBytes
|
6
|
+
} from 'aptos/dist/generated';
|
7
7
|
import { WEBWALLET_URL } from '../config/aptosConstants';
|
8
8
|
import {
|
9
9
|
WalletNotConnectedError,
|
@@ -12,7 +12,7 @@ import {
|
|
12
12
|
} from '../WalletProviders/errors';
|
13
13
|
import { AccountKeys, BaseWalletAdapter, WalletName, WalletReadyState } from './BaseAdapter';
|
14
14
|
|
15
|
-
export const HippoWalletName = 'Hippo Web
|
15
|
+
export const HippoWalletName = 'Hippo Web' as WalletName<'Hippo Web'>;
|
16
16
|
|
17
17
|
export interface HippoWalletAdapterConfig {
|
18
18
|
provider?: string;
|
@@ -102,7 +102,7 @@ export class HippoWalletAdapter extends BaseWalletAdapter {
|
|
102
102
|
};
|
103
103
|
this.emit('connect', this._wallet);
|
104
104
|
} else if (e.data.method === 'success') {
|
105
|
-
this.emit('success', e.data.detail);
|
105
|
+
this.emit('success', e.data.detail?.hash);
|
106
106
|
} else if (e.data.method === 'fail') {
|
107
107
|
this.emit('error', new WalletSignAndSubmitMessageError(e.data.error));
|
108
108
|
} else if (e.data.method === 'disconnected') {
|
@@ -168,7 +168,9 @@ export class HippoWalletAdapter extends BaseWalletAdapter {
|
|
168
168
|
}
|
169
169
|
}
|
170
170
|
|
171
|
-
async signAndSubmitTransaction(
|
171
|
+
async signAndSubmitTransaction(
|
172
|
+
transaction: TransactionPayload
|
173
|
+
): Promise<{ hash: HexEncodedBytes }> {
|
172
174
|
try {
|
173
175
|
const request = new URLSearchParams({
|
174
176
|
request: JSON.stringify({
|
@@ -187,7 +189,33 @@ export class HippoWalletAdapter extends BaseWalletAdapter {
|
|
187
189
|
this.once('success', resolve);
|
188
190
|
this.once('error', reject);
|
189
191
|
});
|
190
|
-
return promise as
|
192
|
+
return promise as { hash: HexEncodedBytes };
|
193
|
+
} catch (error: any) {
|
194
|
+
this.emit('error', error);
|
195
|
+
throw error;
|
196
|
+
}
|
197
|
+
}
|
198
|
+
|
199
|
+
async signMessage(message: string): Promise<string> {
|
200
|
+
try {
|
201
|
+
const request = new URLSearchParams({
|
202
|
+
request: JSON.stringify({
|
203
|
+
method: 'signMessage',
|
204
|
+
payload: message
|
205
|
+
}),
|
206
|
+
origin: window.location.origin
|
207
|
+
}).toString();
|
208
|
+
const popup = window.open(
|
209
|
+
`${WEBWALLET_URL}?${request}`,
|
210
|
+
'Transaction Confirmation',
|
211
|
+
'scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,width=440,height=700'
|
212
|
+
);
|
213
|
+
if (!popup) throw new WalletNotConnectedError();
|
214
|
+
const promise = await new Promise((resolve, reject) => {
|
215
|
+
this.once('success', resolve);
|
216
|
+
this.once('error', reject);
|
217
|
+
});
|
218
|
+
return promise as string;
|
191
219
|
} catch (error: any) {
|
192
220
|
this.emit('error', error);
|
193
221
|
throw error;
|
@@ -1,14 +1,15 @@
|
|
1
1
|
import { MaybeHexString } from 'aptos';
|
2
2
|
import {
|
3
|
-
|
3
|
+
TransactionPayload,
|
4
4
|
SubmitTransactionRequest,
|
5
|
-
|
6
|
-
} from 'aptos/dist/
|
7
|
-
import { aptosClient } from '../config/aptosConstants';
|
5
|
+
HexEncodedBytes
|
6
|
+
} from 'aptos/dist/generated';
|
8
7
|
import {
|
9
8
|
WalletDisconnectionError,
|
10
9
|
WalletNotConnectedError,
|
11
10
|
WalletNotReadyError,
|
11
|
+
WalletSignAndSubmitMessageError,
|
12
|
+
WalletSignMessageError,
|
12
13
|
WalletSignTransactionError
|
13
14
|
} from '../WalletProviders/errors';
|
14
15
|
import {
|
@@ -33,12 +34,13 @@ interface MartianAccount {
|
|
33
34
|
isConnected: boolean;
|
34
35
|
}
|
35
36
|
interface IMartianWallet {
|
36
|
-
connect: (
|
37
|
+
connect: () => Promise<ConnectMartianAccount>;
|
37
38
|
account(): Promise<MartianAccount>;
|
38
39
|
isConnected(): Promise<boolean>;
|
39
40
|
generateTransaction(sender: MaybeHexString, payload: any): Promise<any>;
|
40
|
-
signAndSubmitTransaction(transaction:
|
41
|
-
|
41
|
+
signAndSubmitTransaction(transaction: TransactionPayload): Promise<HexEncodedBytes>;
|
42
|
+
signTransaction(transaction: TransactionPayload): Promise<HexEncodedBytes>;
|
43
|
+
signMessage(message: string): Promise<string>;
|
42
44
|
disconnect(): Promise<void>;
|
43
45
|
}
|
44
46
|
|
@@ -48,7 +50,7 @@ interface MartianWindow extends Window {
|
|
48
50
|
|
49
51
|
declare const window: MartianWindow;
|
50
52
|
|
51
|
-
export const MartianWalletName = '
|
53
|
+
export const MartianWalletName = 'Martian' as WalletName<'Martian'>;
|
52
54
|
|
53
55
|
export interface MartianWalletAdapterConfig {
|
54
56
|
provider?: IMartianWallet;
|
@@ -62,7 +64,7 @@ export class MartianWalletAdapter extends BaseWalletAdapter {
|
|
62
64
|
url = 'https://chrome.google.com/webstore/detail/martian-wallet/efbglgofoippbgcjepnhiblaibcnclgk';
|
63
65
|
|
64
66
|
icon =
|
65
|
-
'
|
67
|
+
'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzUyIiBoZWlnaHQ9IjM1MiIgdmlld0JveD0iMCAwIDM1MiAzNTIiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIzNTIiIGhlaWdodD0iMzUyIiByeD0iODciIGZpbGw9IiMxRjFGMUYiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0xNjkuNzAxIDg5LjA4NDFDMTU5LjUwOCA4OS44MzA5IDE1MC41NDcg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yNDcuNjk4IDE2OC4xMDQgMjQ3LjM0NkMxNjAuNTU1IDI0Ni40NTggMTUzLjk3MiAyNDQuNzYzIDE0Ny40NDcgMjQyLjAyOEMxNDUuOTEzIDI0MS4zODUgMTQxLjgxNCAyMzkuMzc5IDE0MC41MDMgMjM4LjYyOUMxMzcuODA3IDIzNy4wODkgMTM0Ljg3MyAyMzUuMjExIDEzNC44NzggMjM1LjAzMUMxMzQuODg4IDIzNC42ODQgMTM5LjY4MSAyMzEuNjU0IDE0Mi4xOTUgMjMwLjQwN0MxNDYuMDU3IDIyOC40OSAxNDkuNDU3IDIyNy4zOTcgMTU0LjM5IDIyNi40ODdDMTU2LjMxMiAyMjYuMTMyIDE1Ni45MTEgMjI2LjExOSAxNzYuNDExIDIyNi4wMDFDMTg3LjQzNiAyMjUuOTM0IDE5Ni44MDEgMjI1LjgzNSAxOTcuMjIxIDIyNS43OEMxOTcuNjQyIDIyNS43MjUgMTk5LjAxOCAyMjUuNTk3IDIwMC4yNzkgMjI1LjQ5NEMyMDUuMTI2IDIyNS4xIDIxMS44NDMgMjIzLjk3NiAyMTYuOTU5IDIyMi43MDRDMjE5LjYzOSAyMjIuMDM4IDIyNC4xNTggMjIwLjc5NCAyMjQuNjU3IDIyMC41ODZDMjI0Ljg0NCAyMjAuNTA4IDIyNi4wMjkgMjIwLjA5MiAyMjcuMjkgMjE5LjY2MkMyMjguNTUxIDIxOS4yMzEgMjMwLjYxNSAyMTguNDY2IDIzMS44NzcgMjE3Ljk2MUMyMzQuMzIzIDIxNi45ODIgMjM0LjQyNSAyMTYuOTQ5IDIzNC40MjUgMjE3LjEyOVoiIGZpbGw9IndoaXRlIi8+Cjwvc3ZnPgo=';
|
66
68
|
|
67
69
|
protected _provider: IMartianWallet | undefined;
|
68
70
|
|
@@ -85,15 +87,15 @@ export class MartianWalletAdapter extends BaseWalletAdapter {
|
|
85
87
|
}: MartianWalletAdapterConfig = {}) {
|
86
88
|
super();
|
87
89
|
|
88
|
-
this._provider = window.martian;
|
90
|
+
this._provider = typeof window !== 'undefined' ? window.martian : undefined;
|
89
91
|
// this._network = network;
|
90
92
|
this._timeout = timeout;
|
91
93
|
this._connecting = false;
|
92
94
|
this._wallet = null;
|
93
95
|
|
94
|
-
if (this._readyState !== WalletReadyState.Unsupported) {
|
96
|
+
if (typeof window !== 'undefined' && this._readyState !== WalletReadyState.Unsupported) {
|
95
97
|
scopePollingDetectionStrategy(() => {
|
96
|
-
if (
|
98
|
+
if (this._provider) {
|
97
99
|
this._readyState = WalletReadyState.Installed;
|
98
100
|
this.emit('readyStateChange', this._readyState);
|
99
101
|
return true;
|
@@ -125,9 +127,7 @@ export class MartianWalletAdapter extends BaseWalletAdapter {
|
|
125
127
|
|
126
128
|
async connect(): Promise<void> {
|
127
129
|
try {
|
128
|
-
// console.log(1, window.martian);
|
129
130
|
if (this.connected || this.connecting) return;
|
130
|
-
// console.log(2);
|
131
131
|
if (
|
132
132
|
!(
|
133
133
|
this._readyState === WalletReadyState.Loadable ||
|
@@ -135,14 +135,14 @@ export class MartianWalletAdapter extends BaseWalletAdapter {
|
|
135
135
|
)
|
136
136
|
)
|
137
137
|
throw new WalletNotReadyError();
|
138
|
-
// console.log(3);
|
139
138
|
this._connecting = true;
|
140
139
|
|
141
|
-
const provider = window.martian;
|
142
|
-
await provider?.
|
143
|
-
|
140
|
+
const provider = this._provider || window.martian;
|
141
|
+
const isConnected = await provider?.isConnected();
|
142
|
+
if (isConnected) {
|
143
|
+
await provider?.disconnect();
|
144
|
+
}
|
144
145
|
const response = await provider?.connect();
|
145
|
-
// console.log(5, response);
|
146
146
|
|
147
147
|
if (!response) {
|
148
148
|
throw new WalletNotConnectedError('No connect response');
|
@@ -154,16 +154,12 @@ export class MartianWalletAdapter extends BaseWalletAdapter {
|
|
154
154
|
...walletAccount,
|
155
155
|
isConnected: true
|
156
156
|
};
|
157
|
-
// console.log(6, this._wallet);
|
158
157
|
}
|
159
|
-
// console.log(9, this._wallet?.address);
|
160
158
|
this.emit('connect', this._wallet?.address || '');
|
161
159
|
} catch (error: any) {
|
162
|
-
|
163
|
-
this.emit('error', error);
|
160
|
+
this.emit('error', new Error(error));
|
164
161
|
throw error;
|
165
162
|
} finally {
|
166
|
-
// console.log(11);
|
167
163
|
this._connecting = false;
|
168
164
|
}
|
169
165
|
}
|
@@ -187,39 +183,58 @@ export class MartianWalletAdapter extends BaseWalletAdapter {
|
|
187
183
|
async signTransaction(transactionPyld: TransactionPayload): Promise<SubmitTransactionRequest> {
|
188
184
|
try {
|
189
185
|
const wallet = this._wallet;
|
190
|
-
const provider = this._provider;
|
191
|
-
if (!wallet) throw new WalletNotConnectedError();
|
192
|
-
const tx = await
|
193
|
-
|
186
|
+
const provider = this._provider || window.martian;
|
187
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
188
|
+
const tx = await provider.generateTransaction(wallet.address || '', transactionPyld);
|
189
|
+
if (!tx) throw new Error('Cannot generate transaction');
|
190
|
+
const response = await provider?.signTransaction(tx);
|
194
191
|
|
195
192
|
if (!response) {
|
196
|
-
throw new
|
193
|
+
throw new Error('No response');
|
197
194
|
}
|
198
|
-
|
199
|
-
|
200
|
-
} as PendingTransaction;
|
195
|
+
const result = { hash: response } as any;
|
196
|
+
return result as SubmitTransactionRequest;
|
201
197
|
} catch (error: any) {
|
202
|
-
this.emit('error', error);
|
198
|
+
this.emit('error', new WalletSignTransactionError(error));
|
203
199
|
throw error;
|
204
200
|
}
|
205
201
|
}
|
206
202
|
|
207
|
-
async signAndSubmitTransaction(
|
203
|
+
async signAndSubmitTransaction(
|
204
|
+
transactionPyld: TransactionPayload
|
205
|
+
): Promise<{ hash: HexEncodedBytes }> {
|
208
206
|
try {
|
209
207
|
const wallet = this._wallet;
|
210
|
-
const provider = this._provider;
|
211
|
-
if (!wallet) throw new WalletNotConnectedError();
|
212
|
-
const tx = await provider
|
208
|
+
const provider = this._provider || window.martian;
|
209
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
210
|
+
const tx = await provider.generateTransaction(wallet.address || '', transactionPyld);
|
211
|
+
if (!tx) throw new Error('Cannot generate transaction');
|
213
212
|
const response = await provider?.signAndSubmitTransaction(tx);
|
214
213
|
|
215
214
|
if (!response) {
|
216
|
-
throw new
|
215
|
+
throw new Error('No response');
|
216
|
+
}
|
217
|
+
return { hash: response };
|
218
|
+
} catch (error: any) {
|
219
|
+
this.emit('error', new WalletSignAndSubmitMessageError(error));
|
220
|
+
throw error;
|
221
|
+
}
|
222
|
+
}
|
223
|
+
|
224
|
+
async signMessage(message: string): Promise<string> {
|
225
|
+
try {
|
226
|
+
const wallet = this._wallet;
|
227
|
+
const provider = this._provider || window.martian;
|
228
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
229
|
+
const response = await provider?.signMessage(message);
|
230
|
+
if (response) {
|
231
|
+
return response;
|
232
|
+
} else {
|
233
|
+
throw new Error('Sign Message failed');
|
217
234
|
}
|
218
|
-
return {
|
219
|
-
hash: response
|
220
|
-
} as PendingTransaction;
|
221
235
|
} catch (error: any) {
|
222
|
-
|
236
|
+
const errMsg = error.message;
|
237
|
+
this.emit('error', new WalletSignMessageError(errMsg));
|
223
238
|
throw error;
|
224
239
|
}
|
225
240
|
}
|