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