@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.
@@ -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?.disconnect();
143
- // console.log(4);
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 aptosClient.generateTransaction(wallet.address || '', transactionPyld);
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
- 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';
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
- 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
- }
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
- nightly?: {
45
- aptos: INightlyWallet;
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
- provider?: INightlyWallet;
55
- // network?: WalletAdapterNetwork;
56
- timeout?: number;
57
- }
53
+ // export interface NightlyWalletAdapterConfig {
54
+ // provider?: INightlyWallet;
55
+ // // network?: WalletAdapterNetwork;
56
+ // timeout?: number;
57
+ // }
58
58
 
59
- export class NightlyWalletAdapter extends BaseWalletAdapter {
60
- name = NightlyWalletName;
59
+ // export class NightlyWalletAdapter extends BaseWalletAdapter {
60
+ // name = NightlyWalletName;
61
61
 
62
- url =
63
- 'https://chrome.google.com/webstore/detail/nightly/injggoambcadlfkkjcgdfbejanmgfgfm/related?hl=en&authuser=0';
62
+ // url =
63
+ // 'https://chrome.google.com/webstore/detail/nightly/injggoambcadlfkkjcgdfbejanmgfgfm/related?hl=en&authuser=0';
64
64
 
65
- icon =
66
- 'https://lh3.googleusercontent.com/Ha38j09tA-70EiZ17pculpj1KUKDP07ytX4DJx_fumDfod_X2nRTiUg2Y9tDwRBs5jDj-gu52hwaPYVPgq1xAuFA1Q=w128-h128-e365-rj-sc0x00ffffff';
65
+ // icon =
66
+ // 'https://lh3.googleusercontent.com/Ha38j09tA-70EiZ17pculpj1KUKDP07ytX4DJx_fumDfod_X2nRTiUg2Y9tDwRBs5jDj-gu52hwaPYVPgq1xAuFA1Q=w128-h128-e365-rj-sc0x00ffffff';
67
67
 
68
- protected _provider: INightlyWallet | undefined;
68
+ // protected _provider: INightlyWallet | undefined;
69
69
 
70
- // protected _network: WalletAdapterNetwork;
71
- protected _timeout: number;
70
+ // // protected _network: WalletAdapterNetwork;
71
+ // protected _timeout: number;
72
72
 
73
- protected _readyState: WalletReadyState =
74
- typeof window === 'undefined' || typeof document === 'undefined'
75
- ? WalletReadyState.Unsupported
76
- : WalletReadyState.NotDetected;
73
+ // protected _readyState: WalletReadyState =
74
+ // typeof window === 'undefined' || typeof document === 'undefined'
75
+ // ? WalletReadyState.Unsupported
76
+ // : WalletReadyState.NotDetected;
77
77
 
78
- protected _connecting: boolean;
78
+ // protected _connecting: boolean;
79
79
 
80
- protected _wallet: {
81
- publicKey?: string;
82
- address?: string;
83
- authKey?: string;
84
- isConnected: boolean;
85
- } | null;
80
+ // protected _wallet: {
81
+ // publicKey?: string;
82
+ // address?: string;
83
+ // authKey?: string;
84
+ // isConnected: boolean;
85
+ // } | null;
86
86
 
87
- constructor({
88
- // provider,
89
- // network = WalletAdapterNetwork.Mainnet,
90
- timeout = 10000
91
- }: NightlyWalletAdapterConfig = {}) {
92
- super();
87
+ // constructor({
88
+ // // provider,
89
+ // // network = WalletAdapterNetwork.Mainnet,
90
+ // timeout = 10000
91
+ // }: NightlyWalletAdapterConfig = {}) {
92
+ // super();
93
93
 
94
- this._provider = window.nightly?.aptos;
95
- // this._network = network;
96
- this._timeout = timeout;
97
- this._connecting = false;
98
- this._wallet = null;
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
- 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
- }
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
- 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
- }
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
- get connecting(): boolean {
121
- return this._connecting;
122
- }
120
+ // get connecting(): boolean {
121
+ // return this._connecting;
122
+ // }
123
123
 
124
- get connected(): boolean {
125
- return !!this._wallet?.isConnected;
126
- }
124
+ // get connected(): boolean {
125
+ // return !!this._wallet?.isConnected;
126
+ // }
127
127
 
128
- get readyState(): WalletReadyState {
129
- return this._readyState;
130
- }
128
+ // get readyState(): WalletReadyState {
129
+ // return this._readyState;
130
+ // }
131
131
 
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;
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
- 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
- };
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
- 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
- }
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
- async disconnect(): Promise<void> {
164
- const wallet = this._wallet;
165
- if (wallet) {
166
- this._wallet = null;
163
+ // async disconnect(): Promise<void> {
164
+ // const wallet = this._wallet;
165
+ // if (wallet) {
166
+ // this._wallet = null;
167
167
 
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
- }
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
- this.emit('disconnect');
177
- }
176
+ // this.emit('disconnect');
177
+ // }
178
178
 
179
- async signTransaction(transaction: TransactionPayload): Promise<SubmitTransactionRequest> {
180
- try {
181
- const wallet = this._wallet;
182
- if (!wallet) throw new WalletNotConnectedError();
179
+ // async signTransaction(transaction: TransactionPayload): Promise<SubmitTransactionRequest> {
180
+ // try {
181
+ // const wallet = this._wallet;
182
+ // if (!wallet) throw new WalletNotConnectedError();
183
183
 
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
- }
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
- async signAndSubmitTransaction(tempTransaction: TransactionPayload): Promise<PendingTransaction> {
202
- try {
203
- const wallet = this._wallet;
204
- if (!wallet) throw new WalletNotConnectedError();
201
+ // async signAndSubmitTransaction(tempTransaction: TransactionPayload): Promise<PendingTransaction> {
202
+ // try {
203
+ // const wallet = this._wallet;
204
+ // if (!wallet) throw new WalletNotConnectedError();
205
205
 
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
- );
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
- 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
- }
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
+ // }
@@ -5,4 +5,4 @@ export * from './HippoWallet';
5
5
  export * from './MartianWallet';
6
6
  export * from './MultiMaskWallet';
7
7
  export * from './FewchaWallet';
8
- export * from './NightlyWallet';
8
+ // export * from './NightlyWallet';
@@ -9,7 +9,6 @@ import {
9
9
  } from './errors';
10
10
  import {
11
11
  AccountKeys,
12
- PublicKey,
13
12
  WalletAdapter,
14
13
  WalletName,
15
14
  WalletReadyState
@@ -6,7 +6,6 @@ import {
6
6
  import { createContext, useContext } from 'react';
7
7
  import {
8
8
  AccountKeys,
9
- PublicKey,
10
9
  WalletAdapter,
11
10
  WalletName,
12
11
  WalletReadyState