@manahippo/aptos-wallet-adapter 0.1.19 → 0.1.22
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/dist/WalletAdapters/AptosWallet.d.ts +8 -5
- package/dist/WalletAdapters/AptosWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/AptosWallet.js +23 -27
- package/dist/WalletAdapters/AptosWallet.js.map +1 -1
- package/dist/WalletAdapters/BaseAdapter.d.ts +7 -5
- package/dist/WalletAdapters/BaseAdapter.d.ts.map +1 -1
- package/dist/WalletAdapters/BaseAdapter.js.map +1 -1
- package/dist/WalletAdapters/FewchaWallet.d.ts +4 -2
- package/dist/WalletAdapters/FewchaWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/FewchaWallet.js +59 -59
- package/dist/WalletAdapters/FewchaWallet.js.map +1 -1
- package/dist/WalletAdapters/HippoExtensionWallet.d.ts +4 -2
- package/dist/WalletAdapters/HippoExtensionWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/HippoExtensionWallet.js +3 -3
- package/dist/WalletAdapters/HippoExtensionWallet.js.map +1 -1
- package/dist/WalletAdapters/HippoWallet.d.ts +4 -2
- package/dist/WalletAdapters/HippoWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/HippoWallet.js +2 -1
- package/dist/WalletAdapters/HippoWallet.js.map +1 -1
- package/dist/WalletAdapters/MartianWallet.d.ts +7 -4
- package/dist/WalletAdapters/MartianWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/MartianWallet.js +15 -26
- package/dist/WalletAdapters/MartianWallet.js.map +1 -1
- package/dist/WalletAdapters/MultiMaskWallet.d.ts +4 -2
- package/dist/WalletAdapters/MultiMaskWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/MultiMaskWallet.js +3 -3
- package/dist/WalletAdapters/MultiMaskWallet.js.map +1 -1
- package/dist/WalletAdapters/NightlyWallet.d.ts +1 -0
- package/dist/WalletAdapters/NightlyWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/NightlyWallet.js +4 -0
- package/dist/WalletAdapters/NightlyWallet.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 +1 -6
- package/dist/WalletProviders/WalletProvider.js.map +1 -1
- package/dist/WalletProviders/useWallet.d.ts +4 -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/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.js +1 -1
- package/dist/utilities/util.js.map +1 -1
- package/package.json +9 -9
- package/src/WalletAdapters/AptosWallet.ts +29 -31
- package/src/WalletAdapters/BaseAdapter.ts +7 -18
- package/src/WalletAdapters/FewchaWallet.ts +66 -71
- package/src/WalletAdapters/HippoExtensionWallet.ts +7 -5
- package/src/WalletAdapters/HippoWallet.ts +6 -4
- package/src/WalletAdapters/MartianWallet.ts +26 -31
- package/src/WalletAdapters/MultiMaskWallet.ts +11 -7
- package/src/WalletAdapters/NightlyWallet.ts +1 -0
- package/src/WalletProviders/WalletProvider.tsx +1 -8
- package/src/WalletProviders/useWallet.ts +5 -12
- package/src/hooks/useLocalStorage.ts +9 -4
- package/src/hooks/useSSR.ts +15 -0
- package/src/utilities/util.ts +1 -1
@@ -1,5 +1,5 @@
|
|
1
1
|
import {
|
2
|
-
|
2
|
+
HexEncodedBytes,
|
3
3
|
SubmitTransactionRequest,
|
4
4
|
TransactionPayload
|
5
5
|
} from 'aptos/dist/generated';
|
@@ -19,12 +19,11 @@ import {
|
|
19
19
|
} from './BaseAdapter';
|
20
20
|
|
21
21
|
interface IAptosWallet {
|
22
|
-
requestId: number;
|
23
22
|
connect: () => Promise<{ address: string }>;
|
24
23
|
account: () => Promise<string>;
|
25
24
|
isConnected: () => Promise<boolean>;
|
26
|
-
signAndSubmitTransaction(transaction: any): Promise<
|
27
|
-
signTransaction(transaction: any): Promise<
|
25
|
+
signAndSubmitTransaction(transaction: any): Promise<{ hash: HexEncodedBytes }>;
|
26
|
+
signTransaction(transaction: any): Promise<SubmitTransactionRequest>;
|
28
27
|
disconnect(): Promise<void>;
|
29
28
|
}
|
30
29
|
|
@@ -70,13 +69,13 @@ export class AptosWalletAdapter extends BaseWalletAdapter {
|
|
70
69
|
}: AptosWalletAdapterConfig = {}) {
|
71
70
|
super();
|
72
71
|
|
73
|
-
this._provider = window.aptos;
|
72
|
+
this._provider = typeof window !== 'undefined' ? window.aptos : undefined;
|
74
73
|
// this._network = network;
|
75
74
|
this._timeout = timeout;
|
76
75
|
this._connecting = false;
|
77
76
|
this._wallet = null;
|
78
77
|
|
79
|
-
if (this._readyState !== WalletReadyState.Unsupported) {
|
78
|
+
if (typeof window !== 'undefined' && this._readyState !== WalletReadyState.Unsupported) {
|
80
79
|
scopePollingDetectionStrategy(() => {
|
81
80
|
if (window.aptos) {
|
82
81
|
this._readyState = WalletReadyState.Installed;
|
@@ -121,8 +120,12 @@ export class AptosWalletAdapter extends BaseWalletAdapter {
|
|
121
120
|
this._connecting = true;
|
122
121
|
|
123
122
|
const provider = this._provider || window.aptos;
|
124
|
-
const
|
123
|
+
const isConnected = await this._provider?.isConnected();
|
124
|
+
if (isConnected === true) {
|
125
|
+
await provider?.disconnect();
|
126
|
+
}
|
125
127
|
|
128
|
+
const response = await provider?.connect();
|
126
129
|
this._wallet = {
|
127
130
|
publicKey: response?.address,
|
128
131
|
isConnected: true
|
@@ -156,44 +159,39 @@ export class AptosWalletAdapter extends BaseWalletAdapter {
|
|
156
159
|
async signTransaction(transaction: TransactionPayload): Promise<SubmitTransactionRequest> {
|
157
160
|
try {
|
158
161
|
const wallet = this._wallet;
|
159
|
-
|
162
|
+
const provider = this._provider || window.aptos;
|
163
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
160
164
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
} else {
|
167
|
-
throw new Error('Sign Transaction failed');
|
168
|
-
}
|
169
|
-
} catch (error: any) {
|
170
|
-
throw new WalletSignTransactionError(error?.message, error);
|
165
|
+
const response = await provider?.signTransaction(payloadV1ToV0(transaction));
|
166
|
+
if (response) {
|
167
|
+
return response;
|
168
|
+
} else {
|
169
|
+
throw new Error('Sign Transaction failed');
|
171
170
|
}
|
172
171
|
} catch (error: any) {
|
173
|
-
|
172
|
+
const errMsg = error.message;
|
173
|
+
this.emit('error', new WalletSignTransactionError(errMsg));
|
174
174
|
throw error;
|
175
175
|
}
|
176
176
|
}
|
177
177
|
|
178
|
-
async signAndSubmitTransaction(
|
178
|
+
async signAndSubmitTransaction(
|
179
|
+
transaction: TransactionPayload
|
180
|
+
): Promise<{ hash: HexEncodedBytes }> {
|
179
181
|
try {
|
180
182
|
const wallet = this._wallet;
|
181
183
|
const provider = this._provider || window.aptos;
|
182
184
|
if (!wallet || !provider) throw new WalletNotConnectedError();
|
183
185
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
throw new Error('Transaction failed');
|
190
|
-
}
|
191
|
-
} catch (error: any) {
|
192
|
-
const errMsg = error.message;
|
193
|
-
throw new WalletSignTransactionError(errMsg);
|
186
|
+
const response = await provider?.signAndSubmitTransaction(payloadV1ToV0(transaction));
|
187
|
+
if (response) {
|
188
|
+
return response;
|
189
|
+
} else {
|
190
|
+
throw new Error('Transaction failed');
|
194
191
|
}
|
195
192
|
} catch (error: any) {
|
196
|
-
|
193
|
+
const errMsg = error.message;
|
194
|
+
this.emit('error', new WalletSignTransactionError(errMsg));
|
197
195
|
throw error;
|
198
196
|
}
|
199
197
|
}
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { MaybeHexString } from 'aptos';
|
2
2
|
import {
|
3
3
|
TransactionPayload,
|
4
|
-
|
5
|
-
|
4
|
+
SubmitTransactionRequest,
|
5
|
+
HexEncodedBytes
|
6
6
|
} from 'aptos/dist/generated';
|
7
7
|
import EventEmitter from 'eventemitter3';
|
8
8
|
|
@@ -64,26 +64,13 @@ export interface WalletAdapterProps<Name extends string = string> {
|
|
64
64
|
publicAccount: AccountKeys;
|
65
65
|
connect(): Promise<void>;
|
66
66
|
disconnect(): Promise<void>;
|
67
|
-
signAndSubmitTransaction(
|
68
|
-
|
69
|
-
// connection: Connection,
|
70
|
-
// options?: SendTransactionOptions
|
71
|
-
): Promise<PendingTransaction>;
|
72
|
-
signTransaction(
|
73
|
-
transaction: TransactionPayload
|
74
|
-
// connection: Connection,
|
75
|
-
// options?: SendTransactionOptions
|
76
|
-
): Promise<SubmitTransactionRequest>;
|
67
|
+
signAndSubmitTransaction(transaction: TransactionPayload): Promise<{ hash: HexEncodedBytes }>;
|
68
|
+
signTransaction(transaction: TransactionPayload): Promise<SubmitTransactionRequest>;
|
77
69
|
}
|
78
70
|
|
79
71
|
export type WalletAdapter<Name extends string = string> = WalletAdapterProps<Name> &
|
80
72
|
EventEmitter<WalletAdapterEvents>;
|
81
73
|
|
82
|
-
export interface SignerWalletAdapterProps {
|
83
|
-
// signTransaction(transaction: Transaction): Promise<Transaction>;
|
84
|
-
// signAllTransactions(transaction: Transaction[]): Promise<Transaction[]>;
|
85
|
-
}
|
86
|
-
|
87
74
|
export abstract class BaseWalletAdapter
|
88
75
|
extends EventEmitter<WalletAdapterEvents>
|
89
76
|
implements WalletAdapter
|
@@ -106,7 +93,9 @@ export abstract class BaseWalletAdapter
|
|
106
93
|
|
107
94
|
abstract connect(): Promise<void>;
|
108
95
|
abstract disconnect(): Promise<void>;
|
109
|
-
abstract signAndSubmitTransaction(
|
96
|
+
abstract signAndSubmitTransaction(
|
97
|
+
transaction: TransactionPayload
|
98
|
+
): Promise<{ hash: HexEncodedBytes }>;
|
110
99
|
|
111
100
|
abstract signTransaction(transaction: TransactionPayload): Promise<SubmitTransactionRequest>;
|
112
101
|
}
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { WEBWALLET_URL } from '../config/aptosConstants';
|
2
1
|
import {
|
2
|
+
WalletConnectionError,
|
3
3
|
WalletDisconnectionError,
|
4
4
|
WalletNotConnectedError,
|
5
5
|
WalletNotReadyError,
|
@@ -16,8 +16,9 @@ import {
|
|
16
16
|
import {
|
17
17
|
TransactionPayload,
|
18
18
|
SubmitTransactionRequest,
|
19
|
-
|
19
|
+
HexEncodedBytes
|
20
20
|
} from 'aptos/dist/generated';
|
21
|
+
import { payloadV1ToV0 } from '../utilities/util';
|
21
22
|
|
22
23
|
export const FewchaWalletName = 'Fewcha Wallet' as WalletName<'Fewcha Wallet'>;
|
23
24
|
|
@@ -27,8 +28,6 @@ interface FewchaWindow extends Window {
|
|
27
28
|
|
28
29
|
declare const window: FewchaWindow;
|
29
30
|
|
30
|
-
const defaultWeb3 = new Web3(new Web3Provider(window.fewcha));
|
31
|
-
|
32
31
|
export interface FewchaAdapterConfig {
|
33
32
|
provider?: string;
|
34
33
|
// network?: WalletAdapterNetwork;
|
@@ -60,14 +59,15 @@ export class FewchaWalletAdapter extends BaseWalletAdapter {
|
|
60
59
|
}: FewchaAdapterConfig = {}) {
|
61
60
|
super();
|
62
61
|
|
63
|
-
this._provider =
|
62
|
+
this._provider =
|
63
|
+
typeof window !== 'undefined' ? new Web3(new Web3Provider(window.fewcha)).action : undefined;
|
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: any = await this._provider?.account();
|
83
|
-
const isConnected = await this._provider?.isConnected();
|
84
|
-
if (publicAccount?.publicKey && isConnected) {
|
85
|
-
this._wallet = {
|
86
|
-
connected: isConnected,
|
87
|
-
...publicAccount
|
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,31 @@ export class FewchaWalletAdapter extends BaseWalletAdapter {
|
|
133
111
|
throw new WalletNotReadyError();
|
134
112
|
|
135
113
|
this._connecting = true;
|
136
|
-
const provider = this._provider;
|
114
|
+
const provider = this._provider || window.fewcha;
|
137
115
|
const isConnected = await this._provider?.isConnected();
|
138
|
-
if (isConnected) {
|
116
|
+
if (isConnected?.data === true) {
|
139
117
|
await provider?.disconnect();
|
140
118
|
}
|
141
|
-
await provider?.connect();
|
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 };
|
133
|
+
}
|
134
|
+
this._wallet = {
|
135
|
+
connected: true,
|
136
|
+
...accountDetail
|
137
|
+
};
|
138
|
+
this.emit('connect', this._wallet.publicKey);
|
142
139
|
} catch (error: any) {
|
143
140
|
this.emit('error', error);
|
144
141
|
throw error;
|
@@ -153,8 +150,13 @@ export class FewchaWalletAdapter extends BaseWalletAdapter {
|
|
153
150
|
this._wallet = null;
|
154
151
|
|
155
152
|
try {
|
156
|
-
const provider = this._provider;
|
157
|
-
await provider?.disconnect();
|
153
|
+
const provider = this._provider || window.fewcha;
|
154
|
+
const isDisconnected = await provider?.disconnect();
|
155
|
+
if (isDisconnected.data === true) {
|
156
|
+
this.emit('disconnect');
|
157
|
+
} else {
|
158
|
+
throw new Error('Disconnect failed');
|
159
|
+
}
|
158
160
|
} catch (error: any) {
|
159
161
|
this.emit('error', new WalletDisconnectionError(error?.message, error));
|
160
162
|
}
|
@@ -163,55 +165,48 @@ export class FewchaWalletAdapter extends BaseWalletAdapter {
|
|
163
165
|
|
164
166
|
async signTransaction(transaction: TransactionPayload): Promise<SubmitTransactionRequest> {
|
165
167
|
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;
|
168
|
+
const wallet = this._wallet;
|
169
|
+
if (!wallet) throw new WalletNotConnectedError();
|
170
|
+
|
171
|
+
const provider = this._provider || window.fewcha;
|
172
|
+
const tx = await provider.generateTransaction(payloadV1ToV0(transaction));
|
173
|
+
if (!tx) throw new WalletSignTransactionError('Cannot generate transaction');
|
174
|
+
const response = await provider?.signTransaction(tx);
|
175
|
+
|
176
|
+
if (!response) {
|
177
|
+
throw new WalletSignTransactionError('No response');
|
178
|
+
}
|
179
|
+
const result = { hash: response } as any;
|
180
|
+
return result as SubmitTransactionRequest;
|
184
181
|
} catch (error: any) {
|
185
|
-
|
182
|
+
const errMsg = error instanceof Error ? error.message : error.response.data.message;
|
183
|
+
this.emit('error', new WalletSignTransactionError(errMsg));
|
186
184
|
throw error;
|
187
185
|
}
|
188
186
|
}
|
189
187
|
|
190
|
-
async signAndSubmitTransaction(
|
188
|
+
async signAndSubmitTransaction(
|
189
|
+
transaction: TransactionPayload
|
190
|
+
): Promise<{ hash: HexEncodedBytes }> {
|
191
191
|
try {
|
192
192
|
const wallet = this._wallet;
|
193
193
|
if (!wallet) throw new WalletNotConnectedError();
|
194
194
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
this.once('success', resolve);
|
204
|
-
this.once('error', reject);
|
205
|
-
});
|
206
|
-
return {
|
207
|
-
hash: promise
|
208
|
-
} as PendingTransaction;
|
209
|
-
} catch (error: any) {
|
210
|
-
const errMsg = error instanceof Error ? error.message : error.response.data.message;
|
211
|
-
throw new WalletSignTransactionError(errMsg);
|
195
|
+
const provider = this._provider || window.fewcha;
|
196
|
+
const tx = await provider.generateTransaction(payloadV1ToV0(transaction));
|
197
|
+
if (!tx) throw new WalletSignTransactionError('Cannot generate transaction');
|
198
|
+
const response = await provider?.signAndSubmitTransaction(tx.data);
|
199
|
+
if (response.status === 401) {
|
200
|
+
throw new WalletSignTransactionError('User has rejected the transaction');
|
201
|
+
} else if (response.status !== 200) {
|
202
|
+
throw new WalletSignTransactionError('Transaction issue');
|
212
203
|
}
|
204
|
+
return {
|
205
|
+
hash: response.data
|
206
|
+
};
|
213
207
|
} catch (error: any) {
|
214
|
-
|
208
|
+
const errMsg = error instanceof Error ? error.message : error.response.data.message;
|
209
|
+
this.emit('error', new WalletSignTransactionError(errMsg));
|
215
210
|
throw error;
|
216
211
|
}
|
217
212
|
}
|
@@ -2,7 +2,7 @@ import { MaybeHexString } from 'aptos';
|
|
2
2
|
import {
|
3
3
|
TransactionPayload,
|
4
4
|
SubmitTransactionRequest,
|
5
|
-
|
5
|
+
HexEncodedBytes
|
6
6
|
} from 'aptos/dist/generated';
|
7
7
|
import {
|
8
8
|
WalletDisconnectionError,
|
@@ -73,13 +73,13 @@ export class HippoExtensionWalletAdapter extends BaseWalletAdapter {
|
|
73
73
|
}: HippoExtensionWalletAdapterConfig = {}) {
|
74
74
|
super();
|
75
75
|
|
76
|
-
this._provider = window.hippoWallet;
|
76
|
+
this._provider = typeof window !== 'undefined' ? window.hippoWallet : undefined;
|
77
77
|
// this._network = network;
|
78
78
|
this._timeout = timeout;
|
79
79
|
this._connecting = false;
|
80
80
|
this._wallet = null;
|
81
81
|
|
82
|
-
if (this._readyState !== WalletReadyState.Unsupported) {
|
82
|
+
if (typeof window !== 'undefined' && this._readyState !== WalletReadyState.Unsupported) {
|
83
83
|
scopePollingDetectionStrategy(() => {
|
84
84
|
if (window.hippoWallet) {
|
85
85
|
this._readyState = WalletReadyState.Installed;
|
@@ -178,7 +178,9 @@ export class HippoExtensionWalletAdapter extends BaseWalletAdapter {
|
|
178
178
|
}
|
179
179
|
}
|
180
180
|
|
181
|
-
async signAndSubmitTransaction(
|
181
|
+
async signAndSubmitTransaction(
|
182
|
+
transaction: TransactionPayload
|
183
|
+
): Promise<{ hash: HexEncodedBytes }> {
|
182
184
|
try {
|
183
185
|
const wallet = this._wallet;
|
184
186
|
if (!wallet) throw new WalletNotConnectedError();
|
@@ -187,7 +189,7 @@ export class HippoExtensionWalletAdapter extends BaseWalletAdapter {
|
|
187
189
|
const provider = this._provider || window.hippoWallet;
|
188
190
|
const response = await provider?.signAndSubmitTransaction(transaction);
|
189
191
|
if (response) {
|
190
|
-
return response.detail;
|
192
|
+
return response.detail.hash;
|
191
193
|
} else {
|
192
194
|
throw new Error('Transaction failed');
|
193
195
|
}
|
@@ -2,7 +2,7 @@ import { MaybeHexString } from 'aptos';
|
|
2
2
|
import {
|
3
3
|
TransactionPayload,
|
4
4
|
SubmitTransactionRequest,
|
5
|
-
|
5
|
+
HexEncodedBytes
|
6
6
|
} from 'aptos/dist/generated';
|
7
7
|
import { WEBWALLET_URL } from '../config/aptosConstants';
|
8
8
|
import {
|
@@ -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,7 @@ 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 };
|
191
193
|
} catch (error: any) {
|
192
194
|
this.emit('error', error);
|
193
195
|
throw error;
|
@@ -2,7 +2,7 @@ import { MaybeHexString } from 'aptos';
|
|
2
2
|
import {
|
3
3
|
TransactionPayload,
|
4
4
|
SubmitTransactionRequest,
|
5
|
-
|
5
|
+
HexEncodedBytes
|
6
6
|
} from 'aptos/dist/generated';
|
7
7
|
import { payloadV1ToV0 } from '../utilities/util';
|
8
8
|
import {
|
@@ -33,12 +33,12 @@ interface MartianAccount {
|
|
33
33
|
isConnected: boolean;
|
34
34
|
}
|
35
35
|
interface IMartianWallet {
|
36
|
-
connect: (
|
36
|
+
connect: () => Promise<ConnectMartianAccount>;
|
37
37
|
account(): Promise<MartianAccount>;
|
38
38
|
isConnected(): Promise<boolean>;
|
39
39
|
generateTransaction(sender: MaybeHexString, payload: any): Promise<any>;
|
40
|
-
signAndSubmitTransaction(transaction:
|
41
|
-
|
40
|
+
signAndSubmitTransaction(transaction: TransactionPayload): Promise<HexEncodedBytes>;
|
41
|
+
signTransaction(transaction: TransactionPayload): Promise<HexEncodedBytes>;
|
42
42
|
disconnect(): Promise<void>;
|
43
43
|
}
|
44
44
|
|
@@ -85,15 +85,15 @@ export class MartianWalletAdapter extends BaseWalletAdapter {
|
|
85
85
|
}: MartianWalletAdapterConfig = {}) {
|
86
86
|
super();
|
87
87
|
|
88
|
-
this._provider = window.martian;
|
88
|
+
this._provider = typeof window !== 'undefined' ? window.martian : undefined;
|
89
89
|
// this._network = network;
|
90
90
|
this._timeout = timeout;
|
91
91
|
this._connecting = false;
|
92
92
|
this._wallet = null;
|
93
93
|
|
94
|
-
if (this._readyState !== WalletReadyState.Unsupported) {
|
94
|
+
if (typeof window !== 'undefined' && this._readyState !== WalletReadyState.Unsupported) {
|
95
95
|
scopePollingDetectionStrategy(() => {
|
96
|
-
if (
|
96
|
+
if (this._provider) {
|
97
97
|
this._readyState = WalletReadyState.Installed;
|
98
98
|
this.emit('readyStateChange', this._readyState);
|
99
99
|
return true;
|
@@ -125,9 +125,7 @@ export class MartianWalletAdapter extends BaseWalletAdapter {
|
|
125
125
|
|
126
126
|
async connect(): Promise<void> {
|
127
127
|
try {
|
128
|
-
// console.log(1, window.martian);
|
129
128
|
if (this.connected || this.connecting) return;
|
130
|
-
// console.log(2);
|
131
129
|
if (
|
132
130
|
!(
|
133
131
|
this._readyState === WalletReadyState.Loadable ||
|
@@ -135,37 +133,31 @@ export class MartianWalletAdapter extends BaseWalletAdapter {
|
|
135
133
|
)
|
136
134
|
)
|
137
135
|
throw new WalletNotReadyError();
|
138
|
-
// console.log(3);
|
139
136
|
this._connecting = true;
|
140
137
|
|
141
|
-
const provider = window.martian;
|
138
|
+
const provider = this._provider || window.martian;
|
142
139
|
const isConnected = await provider?.isConnected();
|
143
|
-
if (isConnected)
|
144
|
-
|
140
|
+
if (isConnected) {
|
141
|
+
await provider?.disconnect();
|
142
|
+
}
|
145
143
|
const response = await provider?.connect();
|
146
|
-
// console.log(5, response);
|
147
144
|
|
148
145
|
if (!response) {
|
149
146
|
throw new WalletNotConnectedError('No connect response');
|
150
147
|
}
|
151
148
|
|
152
149
|
const walletAccount = await provider?.account();
|
153
|
-
// console.log(6, walletAccount);
|
154
150
|
if (walletAccount) {
|
155
151
|
this._wallet = {
|
156
152
|
...walletAccount,
|
157
153
|
isConnected: true
|
158
154
|
};
|
159
|
-
// console.log(6, this._wallet);
|
160
155
|
}
|
161
|
-
// console.log(9, this._wallet?.address);
|
162
156
|
this.emit('connect', this._wallet?.address || '');
|
163
157
|
} catch (error: any) {
|
164
|
-
|
165
|
-
this.emit('error', error);
|
158
|
+
this.emit('error', new Error(error));
|
166
159
|
throw error;
|
167
160
|
} finally {
|
168
|
-
// console.log(11);
|
169
161
|
this._connecting = false;
|
170
162
|
}
|
171
163
|
}
|
@@ -189,11 +181,14 @@ export class MartianWalletAdapter extends BaseWalletAdapter {
|
|
189
181
|
async signTransaction(transactionPyld: TransactionPayload): Promise<SubmitTransactionRequest> {
|
190
182
|
try {
|
191
183
|
const wallet = this._wallet;
|
192
|
-
const provider = this._provider;
|
193
|
-
if (!wallet) throw new WalletNotConnectedError();
|
194
|
-
const tx = await provider
|
195
|
-
|
196
|
-
|
184
|
+
const provider = this._provider || window.martian;
|
185
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
186
|
+
const tx = await provider.generateTransaction(
|
187
|
+
wallet.address || '',
|
188
|
+
payloadV1ToV0(transactionPyld)
|
189
|
+
);
|
190
|
+
if (!tx) throw new WalletSignTransactionError('Cannot generate transaction');
|
191
|
+
const response = await provider?.signTransaction(tx);
|
197
192
|
|
198
193
|
if (!response) {
|
199
194
|
throw new WalletSignTransactionError('No response');
|
@@ -206,13 +201,15 @@ export class MartianWalletAdapter extends BaseWalletAdapter {
|
|
206
201
|
}
|
207
202
|
}
|
208
203
|
|
209
|
-
async signAndSubmitTransaction(
|
204
|
+
async signAndSubmitTransaction(
|
205
|
+
transactionPyld: TransactionPayload
|
206
|
+
): Promise<{ hash: HexEncodedBytes }> {
|
210
207
|
try {
|
211
208
|
const wallet = this._wallet;
|
212
209
|
const provider = this._provider || window.martian;
|
213
210
|
if (!wallet || !provider) throw new WalletNotConnectedError();
|
214
211
|
const tx = await provider.generateTransaction(
|
215
|
-
wallet.address
|
212
|
+
wallet.address || '',
|
216
213
|
payloadV1ToV0(transactionPyld)
|
217
214
|
);
|
218
215
|
if (!tx) throw new WalletSignTransactionError('Cannot generate transaction');
|
@@ -221,11 +218,9 @@ export class MartianWalletAdapter extends BaseWalletAdapter {
|
|
221
218
|
if (!response) {
|
222
219
|
throw new WalletSignTransactionError('No response');
|
223
220
|
}
|
224
|
-
return {
|
225
|
-
hash: response
|
226
|
-
} as PendingTransaction;
|
221
|
+
return { hash: response };
|
227
222
|
} catch (error: any) {
|
228
|
-
this.emit('error', error);
|
223
|
+
this.emit('error', new Error(error));
|
229
224
|
throw error;
|
230
225
|
}
|
231
226
|
}
|
@@ -1,8 +1,10 @@
|
|
1
|
+
/* eslint-disable no-unused-vars */
|
2
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
1
3
|
import {
|
2
4
|
TransactionPayload,
|
3
5
|
SubmitTransactionRequest,
|
4
|
-
|
5
|
-
|
6
|
+
ScriptFunctionPayload,
|
7
|
+
HexEncodedBytes
|
6
8
|
} from 'aptos/dist/generated';
|
7
9
|
import {
|
8
10
|
WalletDisconnectionError,
|
@@ -74,13 +76,13 @@ export class MultiMaskWalletAdapter extends BaseWalletAdapter {
|
|
74
76
|
}: MultiMaskWalletAdapterConfig = {}) {
|
75
77
|
super();
|
76
78
|
|
77
|
-
this._provider = window.aptosWeb3;
|
79
|
+
this._provider = typeof window !== 'undefined' ? window.aptosWeb3 : undefined;
|
78
80
|
// this._network = network;
|
79
81
|
this._timeout = timeout;
|
80
82
|
this._connecting = false;
|
81
83
|
this._wallet = null;
|
82
84
|
|
83
|
-
if (this._readyState !== WalletReadyState.Unsupported) {
|
85
|
+
if (typeof window !== 'undefined' && this._readyState !== WalletReadyState.Unsupported) {
|
84
86
|
scopePollingDetectionStrategy(() => {
|
85
87
|
if (this._provider) {
|
86
88
|
this._readyState = WalletReadyState.Installed;
|
@@ -202,7 +204,9 @@ export class MultiMaskWalletAdapter extends BaseWalletAdapter {
|
|
202
204
|
}
|
203
205
|
}
|
204
206
|
|
205
|
-
async signAndSubmitTransaction(
|
207
|
+
async signAndSubmitTransaction(
|
208
|
+
tempTransaction: TransactionPayload
|
209
|
+
): Promise<{ hash: HexEncodedBytes }> {
|
206
210
|
try {
|
207
211
|
const wallet = this._provider;
|
208
212
|
if (!wallet) throw new WalletNotConnectedError();
|
@@ -210,13 +214,13 @@ export class MultiMaskWalletAdapter extends BaseWalletAdapter {
|
|
210
214
|
|
211
215
|
try {
|
212
216
|
// console.log('trans', 1);
|
213
|
-
const response = await new Promise<
|
217
|
+
const response = await new Promise<{ hash: HexEncodedBytes }>((resolve, reject) => {
|
214
218
|
// const args = [...transaction.type_arguments, transaction.arguments[0] / 1000];
|
215
219
|
// console.log('trans 2', transaction, transaction.function.split(':')[0]);
|
216
220
|
wallet.currentProvider.sendAsync(
|
217
221
|
{
|
218
222
|
method: 'eth_sendTransaction',
|
219
|
-
params: [{ from: transaction.function.name.split(':')[0] }]
|
223
|
+
params: [] //[{ from: transaction.function.name.split(':')[0] }]
|
220
224
|
},
|
221
225
|
(error, resp: any) => {
|
222
226
|
console.log('signTransaction', error, resp);
|