@manahippo/aptos-wallet-adapter 0.1.18 → 0.1.21

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.
Files changed (55) hide show
  1. package/dist/WalletAdapters/AptosWallet.d.ts +8 -5
  2. package/dist/WalletAdapters/AptosWallet.d.ts.map +1 -1
  3. package/dist/WalletAdapters/AptosWallet.js +24 -27
  4. package/dist/WalletAdapters/AptosWallet.js.map +1 -1
  5. package/dist/WalletAdapters/BaseAdapter.d.ts +7 -5
  6. package/dist/WalletAdapters/BaseAdapter.d.ts.map +1 -1
  7. package/dist/WalletAdapters/BaseAdapter.js.map +1 -1
  8. package/dist/WalletAdapters/FewchaWallet.d.ts +4 -2
  9. package/dist/WalletAdapters/FewchaWallet.d.ts.map +1 -1
  10. package/dist/WalletAdapters/FewchaWallet.js +57 -57
  11. package/dist/WalletAdapters/FewchaWallet.js.map +1 -1
  12. package/dist/WalletAdapters/HippoExtensionWallet.d.ts +4 -2
  13. package/dist/WalletAdapters/HippoExtensionWallet.d.ts.map +1 -1
  14. package/dist/WalletAdapters/HippoExtensionWallet.js +1 -1
  15. package/dist/WalletAdapters/HippoExtensionWallet.js.map +1 -1
  16. package/dist/WalletAdapters/HippoWallet.d.ts +4 -2
  17. package/dist/WalletAdapters/HippoWallet.d.ts.map +1 -1
  18. package/dist/WalletAdapters/HippoWallet.js +2 -1
  19. package/dist/WalletAdapters/HippoWallet.js.map +1 -1
  20. package/dist/WalletAdapters/MartianWallet.d.ts +7 -4
  21. package/dist/WalletAdapters/MartianWallet.d.ts.map +1 -1
  22. package/dist/WalletAdapters/MartianWallet.js +20 -30
  23. package/dist/WalletAdapters/MartianWallet.js.map +1 -1
  24. package/dist/WalletAdapters/MultiMaskWallet.d.ts +4 -2
  25. package/dist/WalletAdapters/MultiMaskWallet.d.ts.map +1 -1
  26. package/dist/WalletAdapters/MultiMaskWallet.js +1 -1
  27. package/dist/WalletAdapters/MultiMaskWallet.js.map +1 -1
  28. package/dist/WalletProviders/WalletProvider.d.ts +0 -1
  29. package/dist/WalletProviders/WalletProvider.d.ts.map +1 -1
  30. package/dist/WalletProviders/WalletProvider.js +1 -6
  31. package/dist/WalletProviders/WalletProvider.js.map +1 -1
  32. package/dist/WalletProviders/useWallet.d.ts +4 -3
  33. package/dist/WalletProviders/useWallet.d.ts.map +1 -1
  34. package/dist/WalletProviders/useWallet.js +1 -1
  35. package/dist/WalletProviders/useWallet.js.map +1 -1
  36. package/dist/config/aptosConstants.d.ts +2 -2
  37. package/dist/config/aptosConstants.d.ts.map +1 -1
  38. package/dist/config/aptosConstants.js +1 -1
  39. package/dist/config/aptosConstants.js.map +1 -1
  40. package/dist/utilities/util.d.ts +8 -0
  41. package/dist/utilities/util.d.ts.map +1 -0
  42. package/dist/utilities/util.js +14 -0
  43. package/dist/utilities/util.js.map +1 -0
  44. package/package.json +2 -2
  45. package/src/WalletAdapters/AptosWallet.ts +31 -32
  46. package/src/WalletAdapters/BaseAdapter.ts +8 -19
  47. package/src/WalletAdapters/FewchaWallet.ts +68 -73
  48. package/src/WalletAdapters/HippoExtensionWallet.ts +7 -5
  49. package/src/WalletAdapters/HippoWallet.ts +8 -6
  50. package/src/WalletAdapters/MartianWallet.ts +35 -37
  51. package/src/WalletAdapters/MultiMaskWallet.ts +9 -7
  52. package/src/WalletProviders/WalletProvider.tsx +1 -8
  53. package/src/WalletProviders/useWallet.ts +6 -13
  54. package/src/config/aptosConstants.ts +1 -1
  55. package/src/utilities/util.ts +11 -0
@@ -1,9 +1,9 @@
1
1
  import { MaybeHexString } from 'aptos';
2
2
  import {
3
- PendingTransaction,
3
+ TransactionPayload,
4
4
  SubmitTransactionRequest,
5
- TransactionPayload
6
- } from 'aptos/dist/api/data-contracts';
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
- transaction: TransactionPayload
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(transaction: TransactionPayload): Promise<PendingTransaction>;
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
- PendingTransaction,
3
- SubmitTransactionRequest,
4
- TransactionPayload
5
- } from 'aptos/dist/api/data-contracts';
6
- import { WEBWALLET_URL } from '../config/aptosConstants';
7
- import {
2
+ WalletConnectionError,
8
3
  WalletDisconnectionError,
9
4
  WalletNotConnectedError,
10
5
  WalletNotReadyError,
@@ -18,6 +13,12 @@ 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
+ 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,6 +59,7 @@ export class FewchaWalletAdapter extends BaseWalletAdapter {
60
59
  }: FewchaAdapterConfig = {}) {
61
60
  super();
62
61
 
62
+ const defaultWeb3 = new Web3(new Web3Provider(window.fewcha));
63
63
  this._provider = defaultWeb3.action;
64
64
  // this._network = network;
65
65
  this._timeout = timeout;
@@ -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 request = new URLSearchParams({
167
- request: JSON.stringify({
168
- method: 'signTransaction',
169
- payload: transaction
170
- }),
171
- origin: window.location.origin
172
- }).toString();
173
- const popup = window.open(
174
- `${WEBWALLET_URL}?${request}`,
175
- 'Transaction Confirmation',
176
- 'scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,width=440,height=700'
177
- );
178
- if (!popup) throw new WalletNotConnectedError();
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
- this.emit('error', error);
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(transaction: TransactionPayload): Promise<PendingTransaction> {
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
- try {
196
- const provider = this._provider;
197
- const tx = await provider?.generateTransaction(transaction);
198
- if (tx) {
199
- await provider?.signAndSubmitTransaction(tx.data);
200
- }
201
-
202
- const promise = await new Promise((resolve, reject) => {
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
- this.emit('error', error);
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
  }
@@ -1,9 +1,9 @@
1
1
  import { MaybeHexString } from 'aptos';
2
2
  import {
3
- PendingTransaction,
3
+ TransactionPayload,
4
4
  SubmitTransactionRequest,
5
- TransactionPayload
6
- } from 'aptos/dist/api/data-contracts';
5
+ HexEncodedBytes
6
+ } from 'aptos/dist/generated';
7
7
  import {
8
8
  WalletDisconnectionError,
9
9
  WalletNotConnectedError,
@@ -178,7 +178,9 @@ export class HippoExtensionWalletAdapter extends BaseWalletAdapter {
178
178
  }
179
179
  }
180
180
 
181
- async signAndSubmitTransaction(transaction: TransactionPayload): Promise<PendingTransaction> {
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
- PendingTransaction,
3
+ TransactionPayload,
4
4
  SubmitTransactionRequest,
5
- TransactionPayload
6
- } from 'aptos/dist/api/data-contracts';
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(transaction: TransactionPayload): Promise<PendingTransaction> {
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 PendingTransaction;
192
+ return promise as { hash: HexEncodedBytes };
191
193
  } catch (error: any) {
192
194
  this.emit('error', error);
193
195
  throw error;
@@ -1,10 +1,10 @@
1
1
  import { MaybeHexString } from 'aptos';
2
2
  import {
3
- PendingTransaction,
3
+ TransactionPayload,
4
4
  SubmitTransactionRequest,
5
- TransactionPayload
6
- } from 'aptos/dist/api/data-contracts';
7
- // import { aptosClient } from '../config/aptosConstants';
5
+ HexEncodedBytes
6
+ } from 'aptos/dist/generated';
7
+ import { payloadV1ToV0 } from '../utilities/util';
8
8
  import {
9
9
  WalletDisconnectionError,
10
10
  WalletNotConnectedError,
@@ -33,12 +33,12 @@ interface MartianAccount {
33
33
  isConnected: boolean;
34
34
  }
35
35
  interface IMartianWallet {
36
- connect: (params?: any) => Promise<ConnectMartianAccount>;
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: any): Promise<string>;
41
- // signTransaction(transaction: any): Promise<void>;
40
+ signAndSubmitTransaction(transaction: TransactionPayload): Promise<HexEncodedBytes>;
41
+ signTransaction(transaction: TransactionPayload): Promise<HexEncodedBytes>;
42
42
  disconnect(): Promise<void>;
43
43
  }
44
44
 
@@ -93,7 +93,7 @@ export class MartianWalletAdapter extends BaseWalletAdapter {
93
93
 
94
94
  if (this._readyState !== WalletReadyState.Unsupported) {
95
95
  scopePollingDetectionStrategy(() => {
96
- if (window.martian) {
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) await provider?.disconnect();
144
- // console.log(4, isConnected);
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
- // console.log(10, error);
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,40 +181,46 @@ 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?.generateTransaction(wallet.address || '', transactionPyld);
195
- if (!tx) throw new WalletSignTransactionError('No transaction');
196
- const response = await provider?.signAndSubmitTransaction(tx);
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');
200
195
  }
201
- return {
202
- hash: response
203
- } as PendingTransaction;
196
+ const result = { hash: response } as any;
197
+ return result as SubmitTransactionRequest;
204
198
  } catch (error: any) {
205
199
  this.emit('error', error);
206
200
  throw error;
207
201
  }
208
202
  }
209
203
 
210
- async signAndSubmitTransaction(transactionPyld: TransactionPayload): Promise<PendingTransaction> {
204
+ async signAndSubmitTransaction(
205
+ transactionPyld: TransactionPayload
206
+ ): Promise<{ hash: HexEncodedBytes }> {
211
207
  try {
212
208
  const wallet = this._wallet;
213
- const provider = this._provider;
214
- if (!wallet) throw new WalletNotConnectedError();
215
- const tx = await provider?.generateTransaction(wallet.address || '', transactionPyld);
209
+ const provider = this._provider || window.martian;
210
+ if (!wallet || !provider) throw new WalletNotConnectedError();
211
+ const tx = await provider.generateTransaction(
212
+ wallet.address || '',
213
+ payloadV1ToV0(transactionPyld)
214
+ );
215
+ if (!tx) throw new WalletSignTransactionError('Cannot generate transaction');
216
216
  const response = await provider?.signAndSubmitTransaction(tx);
217
217
 
218
218
  if (!response) {
219
219
  throw new WalletSignTransactionError('No response');
220
220
  }
221
- return {
222
- hash: response
223
- } as PendingTransaction;
221
+ return { hash: response };
224
222
  } catch (error: any) {
225
- this.emit('error', error);
223
+ this.emit('error', new Error(error));
226
224
  throw error;
227
225
  }
228
226
  }
@@ -1,9 +1,9 @@
1
1
  import {
2
- PendingTransaction,
3
- ScriptFunctionPayload,
2
+ TransactionPayload,
4
3
  SubmitTransactionRequest,
5
- TransactionPayload
6
- } from 'aptos/dist/api/data-contracts';
4
+ ScriptFunctionPayload,
5
+ HexEncodedBytes
6
+ } from 'aptos/dist/generated';
7
7
  import {
8
8
  WalletDisconnectionError,
9
9
  WalletNotConnectedError,
@@ -202,7 +202,9 @@ export class MultiMaskWalletAdapter extends BaseWalletAdapter {
202
202
  }
203
203
  }
204
204
 
205
- async signAndSubmitTransaction(tempTransaction: TransactionPayload): Promise<PendingTransaction> {
205
+ async signAndSubmitTransaction(
206
+ tempTransaction: TransactionPayload
207
+ ): Promise<{ hash: HexEncodedBytes }> {
206
208
  try {
207
209
  const wallet = this._provider;
208
210
  if (!wallet) throw new WalletNotConnectedError();
@@ -210,13 +212,13 @@ export class MultiMaskWalletAdapter extends BaseWalletAdapter {
210
212
 
211
213
  try {
212
214
  // console.log('trans', 1);
213
- const response = await new Promise<PendingTransaction>((resolve, reject) => {
215
+ const response = await new Promise<{ hash: HexEncodedBytes }>((resolve, reject) => {
214
216
  // const args = [...transaction.type_arguments, transaction.arguments[0] / 1000];
215
217
  // console.log('trans 2', transaction, transaction.function.split(':')[0]);
216
218
  wallet.currentProvider.sendAsync(
217
219
  {
218
220
  method: 'eth_sendTransaction',
219
- params: [{ from: transaction.function.split(':')[0] }]
221
+ params: []//[{ from: transaction.function.name.split(':')[0] }]
220
222
  },
221
223
  (error, resp: any) => {
222
224
  console.log('signTransaction', error, resp);
@@ -1,6 +1,6 @@
1
- import { TransactionPayload } from 'aptos/dist/api/data-contracts';
2
1
  import { useLocalStorage } from '../hooks/useLocalStorage';
3
2
  import { FC, ReactNode, useCallback, useEffect, useRef, useState } from 'react';
3
+ import { TransactionPayload } from 'aptos/dist/generated';
4
4
  import {
5
5
  WalletError,
6
6
  WalletNotConnectedError,
@@ -18,7 +18,6 @@ import { Wallet, WalletContext } from './useWallet';
18
18
  export interface WalletProviderProps {
19
19
  children: ReactNode;
20
20
  wallets: WalletAdapter[];
21
- autoConnect?: boolean;
22
21
  onError?: (error: WalletError) => void;
23
22
  localStorageKey?: string;
24
23
  }
@@ -38,7 +37,6 @@ const initialState: {
38
37
  export const WalletProvider: FC<WalletProviderProps> = ({
39
38
  children,
40
39
  wallets: adapters,
41
- autoConnect = false,
42
40
  onError,
43
41
  localStorageKey = 'walletName'
44
42
  }) => {
@@ -140,7 +138,6 @@ export const WalletProvider: FC<WalletProviderProps> = ({
140
138
  adapter.off('error', handleError);
141
139
  };
142
140
  }
143
- return () => null;
144
141
  }, [adapter, handleConnect, handleDisconnect, handleError]);
145
142
 
146
143
  // When the adapter changes, disconnect the old one
@@ -243,7 +240,6 @@ export const WalletProvider: FC<WalletProviderProps> = ({
243
240
  return (
244
241
  <WalletContext.Provider
245
242
  value={{
246
- autoConnect,
247
243
  wallets,
248
244
  wallet,
249
245
  account,
@@ -254,10 +250,7 @@ export const WalletProvider: FC<WalletProviderProps> = ({
254
250
  connect,
255
251
  disconnect,
256
252
  signAndSubmitTransaction,
257
- // sendTransaction,
258
253
  signTransaction
259
- // signAllTransactions,
260
- // signMessage
261
254
  }}>
262
255
  {children}
263
256
  </WalletContext.Provider>
@@ -1,8 +1,8 @@
1
1
  import {
2
- PendingTransaction,
2
+ TransactionPayload,
3
3
  SubmitTransactionRequest,
4
- TransactionPayload
5
- } from 'aptos/dist/api/data-contracts';
4
+ HexEncodedBytes
5
+ } from 'aptos/dist/generated';
6
6
  import { createContext, useContext } from 'react';
7
7
  import {
8
8
  AccountKeys,
@@ -17,7 +17,7 @@ export interface Wallet {
17
17
  }
18
18
 
19
19
  export interface WalletContextState {
20
- autoConnect: boolean;
20
+ // autoConnect: boolean;
21
21
  wallets: Wallet[];
22
22
  wallet: Wallet | null;
23
23
  account: AccountKeys | null;
@@ -27,19 +27,12 @@ export interface WalletContextState {
27
27
  select(walletName: WalletName): void;
28
28
  connect(walletName: string): Promise<void>;
29
29
  disconnect(): Promise<void>;
30
- signAndSubmitTransaction(
31
- transaction: TransactionPayload
32
- // connection: Connection,
33
- // options?: SendTransactionOptions
34
- ): Promise<PendingTransaction>;
35
-
30
+ signAndSubmitTransaction(transaction: TransactionPayload): Promise<{ hash: HexEncodedBytes }>;
36
31
  signTransaction(transaction: TransactionPayload): Promise<SubmitTransactionRequest>;
37
- // signAllTransactions: SignerWalletAdapterProps['signAllTransactions'] | undefined;
38
- // signMessage: MessageSignerWalletAdapterProps['signMessage'] | undefined;
39
32
  }
40
33
 
41
34
  const DEFAULT_CONTEXT = {
42
- autoConnect: false,
35
+ // autoConnect: false,
43
36
  connecting: false,
44
37
  connected: false,
45
38
  disconnecting: false
@@ -4,7 +4,7 @@ export const WEBWALLET_URL = 'https://hippo-wallet-test.web.app';
4
4
  // export const WEBWALLET_URL = 'http://localhost:3030';
5
5
 
6
6
  export const LOCAL_NODE_URL = 'http://127.0.0.1:8080';
7
- export const DEVNET_NODE_URL = 'https://fullnode.devnet.aptoslabs.com';
7
+ export const DEVNET_NODE_URL = 'https://fullnode.devnet.aptoslabs.com/v1';
8
8
  export const LOCAL_FAUCET_URL = 'http://127.0.0.1:8000';
9
9
  export const DEVNET_FAUCET_URL = 'https://faucet.devnet.aptoslabs.com';
10
10
 
@@ -0,0 +1,11 @@
1
+ import { TransactionPayload, TransactionPayload_ScriptFunctionPayload } from 'aptos/dist/generated';
2
+
3
+ export const payloadV1ToV0 = (payload: TransactionPayload) => {
4
+ const v1 = payload as TransactionPayload_ScriptFunctionPayload;
5
+ return {
6
+ type: 'script_function_payload',
7
+ function: v1.function,
8
+ type_arguments: v1.type_arguments,
9
+ arguments: v1.arguments
10
+ };
11
+ };