@manahippo/aptos-wallet-adapter 0.1.17 → 0.1.18
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +16 -16
- package/dist/WalletAdapters/FewchaWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/FewchaWallet.js +6 -4
- package/dist/WalletAdapters/FewchaWallet.js.map +1 -1
- package/dist/WalletAdapters/MartianWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/MartianWallet.js +9 -4
- package/dist/WalletAdapters/MartianWallet.js.map +1 -1
- package/dist/WalletAdapters/NightlyWallet.d.ts +0 -41
- package/dist/WalletAdapters/NightlyWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/NightlyWallet.js +229 -199
- package/dist/WalletAdapters/NightlyWallet.js.map +1 -1
- package/dist/WalletAdapters/index.d.ts +0 -1
- package/dist/WalletAdapters/index.d.ts.map +1 -1
- package/dist/WalletAdapters/index.js +1 -1
- package/dist/WalletAdapters/index.js.map +1 -1
- package/dist/WalletProviders/WalletProvider.d.ts.map +1 -1
- package/dist/WalletProviders/WalletProvider.js.map +1 -1
- package/dist/WalletProviders/useWallet.d.ts.map +1 -1
- package/dist/WalletProviders/useWallet.js.map +1 -1
- package/package.json +3 -3
- package/src/WalletAdapters/FewchaWallet.ts +8 -6
- package/src/WalletAdapters/MartianWallet.ts +7 -4
- package/src/WalletAdapters/NightlyWallet.ts +229 -229
- package/src/WalletAdapters/index.ts +1 -1
- package/src/WalletProviders/WalletProvider.tsx +0 -1
- package/src/WalletProviders/useWallet.ts +0 -1
@@ -4,7 +4,7 @@ import {
|
|
4
4
|
SubmitTransactionRequest,
|
5
5
|
TransactionPayload
|
6
6
|
} from 'aptos/dist/api/data-contracts';
|
7
|
-
import { aptosClient } from '../config/aptosConstants';
|
7
|
+
// import { aptosClient } from '../config/aptosConstants';
|
8
8
|
import {
|
9
9
|
WalletDisconnectionError,
|
10
10
|
WalletNotConnectedError,
|
@@ -139,8 +139,9 @@ export class MartianWalletAdapter extends BaseWalletAdapter {
|
|
139
139
|
this._connecting = true;
|
140
140
|
|
141
141
|
const provider = window.martian;
|
142
|
-
await provider?.
|
143
|
-
|
142
|
+
const isConnected = await provider?.isConnected();
|
143
|
+
if (isConnected) await provider?.disconnect();
|
144
|
+
// console.log(4, isConnected);
|
144
145
|
const response = await provider?.connect();
|
145
146
|
// console.log(5, response);
|
146
147
|
|
@@ -149,6 +150,7 @@ export class MartianWalletAdapter extends BaseWalletAdapter {
|
|
149
150
|
}
|
150
151
|
|
151
152
|
const walletAccount = await provider?.account();
|
153
|
+
// console.log(6, walletAccount);
|
152
154
|
if (walletAccount) {
|
153
155
|
this._wallet = {
|
154
156
|
...walletAccount,
|
@@ -189,7 +191,8 @@ export class MartianWalletAdapter extends BaseWalletAdapter {
|
|
189
191
|
const wallet = this._wallet;
|
190
192
|
const provider = this._provider;
|
191
193
|
if (!wallet) throw new WalletNotConnectedError();
|
192
|
-
const tx = await
|
194
|
+
const tx = await provider?.generateTransaction(wallet.address || '', transactionPyld);
|
195
|
+
if (!tx) throw new WalletSignTransactionError('No transaction');
|
193
196
|
const response = await provider?.signAndSubmitTransaction(tx);
|
194
197
|
|
195
198
|
if (!response) {
|
@@ -1,260 +1,260 @@
|
|
1
|
-
import { TxnBuilderTypes, BCS } from 'aptos';
|
2
|
-
import {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
} from 'aptos/dist/api/data-contracts';
|
8
|
-
import {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
} from 'aptos/dist/transaction_builder/aptos_types';
|
14
|
-
import { bcsSerializeUint64, bcsToBytes, Seq } from 'aptos/dist/transaction_builder/bcs';
|
15
|
-
import { aptosClient } from '../config/aptosConstants';
|
16
|
-
import {
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
} from '../WalletProviders/errors';
|
22
|
-
import {
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
} from './BaseAdapter';
|
1
|
+
// import { TxnBuilderTypes, BCS } from 'aptos';
|
2
|
+
// import {
|
3
|
+
// PendingTransaction,
|
4
|
+
// ScriptFunctionPayload,
|
5
|
+
// SubmitTransactionRequest,
|
6
|
+
// TransactionPayload
|
7
|
+
// } from 'aptos/dist/api/data-contracts';
|
8
|
+
// import {
|
9
|
+
// ScriptFunction,
|
10
|
+
// StructTag,
|
11
|
+
// TransactionPayloadScriptFunction,
|
12
|
+
// TypeTagStruct
|
13
|
+
// } from 'aptos/dist/transaction_builder/aptos_types';
|
14
|
+
// import { bcsSerializeUint64, bcsToBytes, Seq } from 'aptos/dist/transaction_builder/bcs';
|
15
|
+
// import { aptosClient } from '../config/aptosConstants';
|
16
|
+
// import {
|
17
|
+
// WalletDisconnectionError,
|
18
|
+
// WalletNotConnectedError,
|
19
|
+
// WalletNotReadyError,
|
20
|
+
// WalletSignTransactionError
|
21
|
+
// } from '../WalletProviders/errors';
|
22
|
+
// import {
|
23
|
+
// AccountKeys,
|
24
|
+
// Address,
|
25
|
+
// AuthKey,
|
26
|
+
// BaseWalletAdapter,
|
27
|
+
// PublicKey,
|
28
|
+
// scopePollingDetectionStrategy,
|
29
|
+
// WalletName,
|
30
|
+
// WalletReadyState
|
31
|
+
// } from './BaseAdapter';
|
32
32
|
|
33
|
-
interface INightlyWallet {
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
}
|
33
|
+
// interface INightlyWallet {
|
34
|
+
// requestId: number;
|
35
|
+
// connect: (onDisconnect?: () => void, eager?: boolean) => Promise<any>;
|
36
|
+
// account: () => Promise<string>;
|
37
|
+
// isConnected: () => Promise<boolean>;
|
38
|
+
// signAndSubmitTransaction(transaction: any): Promise<void>;
|
39
|
+
// signTransaction(transaction: any): Promise<any>;
|
40
|
+
// disconnect(): Promise<void>;
|
41
|
+
// }
|
42
42
|
|
43
|
-
interface NightlyWindow extends Window {
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
}
|
43
|
+
// interface NightlyWindow extends Window {
|
44
|
+
// nightly?: {
|
45
|
+
// aptos: INightlyWallet;
|
46
|
+
// };
|
47
|
+
// }
|
48
48
|
|
49
|
-
declare const window: NightlyWindow;
|
49
|
+
// declare const window: NightlyWindow;
|
50
50
|
|
51
|
-
export const NightlyWalletName = 'Nightly Wallet' as WalletName<'Nightly Wallet'>;
|
51
|
+
// export const NightlyWalletName = 'Nightly Wallet' as WalletName<'Nightly Wallet'>;
|
52
52
|
|
53
|
-
export interface NightlyWalletAdapterConfig {
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
}
|
53
|
+
// export interface NightlyWalletAdapterConfig {
|
54
|
+
// provider?: INightlyWallet;
|
55
|
+
// // network?: WalletAdapterNetwork;
|
56
|
+
// timeout?: number;
|
57
|
+
// }
|
58
58
|
|
59
|
-
export class NightlyWalletAdapter extends BaseWalletAdapter {
|
60
|
-
|
59
|
+
// export class NightlyWalletAdapter extends BaseWalletAdapter {
|
60
|
+
// name = NightlyWalletName;
|
61
61
|
|
62
|
-
|
63
|
-
|
62
|
+
// url =
|
63
|
+
// 'https://chrome.google.com/webstore/detail/nightly/injggoambcadlfkkjcgdfbejanmgfgfm/related?hl=en&authuser=0';
|
64
64
|
|
65
|
-
|
66
|
-
|
65
|
+
// icon =
|
66
|
+
// 'https://lh3.googleusercontent.com/Ha38j09tA-70EiZ17pculpj1KUKDP07ytX4DJx_fumDfod_X2nRTiUg2Y9tDwRBs5jDj-gu52hwaPYVPgq1xAuFA1Q=w128-h128-e365-rj-sc0x00ffffff';
|
67
67
|
|
68
|
-
|
68
|
+
// protected _provider: INightlyWallet | undefined;
|
69
69
|
|
70
|
-
|
71
|
-
|
70
|
+
// // protected _network: WalletAdapterNetwork;
|
71
|
+
// protected _timeout: number;
|
72
72
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
73
|
+
// protected _readyState: WalletReadyState =
|
74
|
+
// typeof window === 'undefined' || typeof document === 'undefined'
|
75
|
+
// ? WalletReadyState.Unsupported
|
76
|
+
// : WalletReadyState.NotDetected;
|
77
77
|
|
78
|
-
|
78
|
+
// protected _connecting: boolean;
|
79
79
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
80
|
+
// protected _wallet: {
|
81
|
+
// publicKey?: string;
|
82
|
+
// address?: string;
|
83
|
+
// authKey?: string;
|
84
|
+
// isConnected: boolean;
|
85
|
+
// } | null;
|
86
86
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
87
|
+
// constructor({
|
88
|
+
// // provider,
|
89
|
+
// // network = WalletAdapterNetwork.Mainnet,
|
90
|
+
// timeout = 10000
|
91
|
+
// }: NightlyWalletAdapterConfig = {}) {
|
92
|
+
// super();
|
93
93
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
94
|
+
// this._provider = window.nightly?.aptos;
|
95
|
+
// // this._network = network;
|
96
|
+
// this._timeout = timeout;
|
97
|
+
// this._connecting = false;
|
98
|
+
// this._wallet = null;
|
99
99
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
100
|
+
// if (this._readyState !== WalletReadyState.Unsupported) {
|
101
|
+
// scopePollingDetectionStrategy(() => {
|
102
|
+
// if (window.nightly?.aptos) {
|
103
|
+
// this._readyState = WalletReadyState.Installed;
|
104
|
+
// this.emit('readyStateChange', this._readyState);
|
105
|
+
// return true;
|
106
|
+
// }
|
107
|
+
// return false;
|
108
|
+
// });
|
109
|
+
// }
|
110
|
+
// }
|
111
111
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
112
|
+
// get publicAccount(): AccountKeys {
|
113
|
+
// return {
|
114
|
+
// publicKey: this._wallet?.publicKey || null,
|
115
|
+
// address: this._wallet?.address || null,
|
116
|
+
// authKey: this._wallet?.authKey || null
|
117
|
+
// };
|
118
|
+
// }
|
119
119
|
|
120
|
-
|
121
|
-
|
122
|
-
|
120
|
+
// get connecting(): boolean {
|
121
|
+
// return this._connecting;
|
122
|
+
// }
|
123
123
|
|
124
|
-
|
125
|
-
|
126
|
-
|
124
|
+
// get connected(): boolean {
|
125
|
+
// return !!this._wallet?.isConnected;
|
126
|
+
// }
|
127
127
|
|
128
|
-
|
129
|
-
|
130
|
-
|
128
|
+
// get readyState(): WalletReadyState {
|
129
|
+
// return this._readyState;
|
130
|
+
// }
|
131
131
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
132
|
+
// async connect(): Promise<void> {
|
133
|
+
// try {
|
134
|
+
// if (this.connected || this.connecting) return;
|
135
|
+
// if (
|
136
|
+
// !(
|
137
|
+
// this._readyState === WalletReadyState.Loadable ||
|
138
|
+
// this._readyState === WalletReadyState.Installed
|
139
|
+
// )
|
140
|
+
// )
|
141
|
+
// throw new WalletNotReadyError();
|
142
|
+
// this._connecting = true;
|
143
143
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
144
|
+
// const provider = this._provider || window.nightly?.aptos;
|
145
|
+
// const publicKey = await provider?.connect(() => {
|
146
|
+
// console.log('Trigger disconnect Aptos');
|
147
|
+
// });
|
148
|
+
// this._wallet = {
|
149
|
+
// publicKey: publicKey?.asString(),
|
150
|
+
// address: publicKey?.address(),
|
151
|
+
// isConnected: true
|
152
|
+
// };
|
153
153
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
154
|
+
// this.emit('connect', this._wallet.publicKey || '');
|
155
|
+
// } catch (error: any) {
|
156
|
+
// this.emit('error', error);
|
157
|
+
// throw error;
|
158
|
+
// } finally {
|
159
|
+
// this._connecting = false;
|
160
|
+
// }
|
161
|
+
// }
|
162
162
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
163
|
+
// async disconnect(): Promise<void> {
|
164
|
+
// const wallet = this._wallet;
|
165
|
+
// if (wallet) {
|
166
|
+
// this._wallet = null;
|
167
167
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
168
|
+
// try {
|
169
|
+
// const provider = this._provider || window.nightly?.aptos;
|
170
|
+
// await provider?.disconnect();
|
171
|
+
// } catch (error: any) {
|
172
|
+
// this.emit('error', new WalletDisconnectionError(error?.message, error));
|
173
|
+
// }
|
174
|
+
// }
|
175
175
|
|
176
|
-
|
177
|
-
|
176
|
+
// this.emit('disconnect');
|
177
|
+
// }
|
178
178
|
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
179
|
+
// async signTransaction(transaction: TransactionPayload): Promise<SubmitTransactionRequest> {
|
180
|
+
// try {
|
181
|
+
// const wallet = this._wallet;
|
182
|
+
// if (!wallet) throw new WalletNotConnectedError();
|
183
183
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
184
|
+
// try {
|
185
|
+
// const provider = this._provider || window.nightly?.aptos;
|
186
|
+
// const response = await provider?.signTransaction(transaction);
|
187
|
+
// if (response) {
|
188
|
+
// return response;
|
189
|
+
// } else {
|
190
|
+
// throw new Error('Transaction failed');
|
191
|
+
// }
|
192
|
+
// } catch (error: any) {
|
193
|
+
// throw new WalletSignTransactionError(error?.message, error);
|
194
|
+
// }
|
195
|
+
// } catch (error: any) {
|
196
|
+
// this.emit('error', error);
|
197
|
+
// throw error;
|
198
|
+
// }
|
199
|
+
// }
|
200
200
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
201
|
+
// async signAndSubmitTransaction(tempTransaction: TransactionPayload): Promise<PendingTransaction> {
|
202
|
+
// try {
|
203
|
+
// const wallet = this._wallet;
|
204
|
+
// if (!wallet) throw new WalletNotConnectedError();
|
205
205
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
206
|
+
// try {
|
207
|
+
// const provider = this._provider || window.nightly?.aptos;
|
208
|
+
// const client = aptosClient;
|
209
|
+
// const [{ sequence_number: sequnceNumber }, chainId] = await Promise.all([
|
210
|
+
// client.getAccount(wallet.address || ''),
|
211
|
+
// client.getChainId()
|
212
|
+
// ]);
|
213
|
+
// const transaction = tempTransaction as ScriptFunctionPayload;
|
214
|
+
// const [txAddress, module, funcName] = transaction.function.split('::');
|
215
|
+
// const token = new TypeTagStruct(StructTag.fromString(transaction.type_arguments[0]));
|
216
|
+
// const argts = transaction.arguments.map((arg) => {
|
217
|
+
// if (typeof arg === 'string') {
|
218
|
+
// return bcsSerializeUint64(parseInt(arg));
|
219
|
+
// } else if (typeof arg === 'boolean') {
|
220
|
+
// const serializer = new BCS.Serializer();
|
221
|
+
// serializer.serializeBool(arg);
|
222
|
+
// return serializer.getBytes();
|
223
|
+
// } else if (typeof arg === 'number') {
|
224
|
+
// return bcsSerializeUint64(arg);
|
225
|
+
// } else {
|
226
|
+
// return arg;
|
227
|
+
// }
|
228
|
+
// });
|
229
|
+
// console.log('txnpayload>>', transaction.arguments, argts);
|
230
|
+
// const txnPayload = new TransactionPayloadScriptFunction(
|
231
|
+
// ScriptFunction.natural(`${txAddress}::${module}`, funcName, [token], [...argts])
|
232
|
+
// );
|
233
233
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
}
|
234
|
+
// const rawTxn = new TxnBuilderTypes.RawTransaction(
|
235
|
+
// TxnBuilderTypes.AccountAddress.fromHex(wallet.address || ''),
|
236
|
+
// BigInt(sequnceNumber),
|
237
|
+
// txnPayload,
|
238
|
+
// BigInt(1000),
|
239
|
+
// BigInt(1),
|
240
|
+
// BigInt(Math.floor(Date.now() / 1000) + 10),
|
241
|
+
// new TxnBuilderTypes.ChainId(chainId)
|
242
|
+
// );
|
243
|
+
// const bcsTxn = await provider?.signTransaction(rawTxn);
|
244
|
+
// const response = await aptosClient.submitSignedBCSTransaction(bcsTxn);
|
245
|
+
// if (response) {
|
246
|
+
// console.log('tx response>>>', response);
|
247
|
+
// return response;
|
248
|
+
// } else {
|
249
|
+
// throw new Error('Transaction failed');
|
250
|
+
// }
|
251
|
+
// } catch (error: any) {
|
252
|
+
// const errMsg = error instanceof Error ? error.message : error.response.data.message;
|
253
|
+
// throw new WalletSignTransactionError(errMsg);
|
254
|
+
// }
|
255
|
+
// } catch (error: any) {
|
256
|
+
// this.emit('error', error);
|
257
|
+
// throw error;
|
258
|
+
// }
|
259
|
+
// }
|
260
|
+
// }
|