@manahippo/aptos-wallet-adapter 0.1.17 → 0.1.20

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 (63) hide show
  1. package/README.md +16 -16
  2. package/dist/WalletAdapters/AptosWallet.d.ts +8 -5
  3. package/dist/WalletAdapters/AptosWallet.d.ts.map +1 -1
  4. package/dist/WalletAdapters/AptosWallet.js +24 -27
  5. package/dist/WalletAdapters/AptosWallet.js.map +1 -1
  6. package/dist/WalletAdapters/BaseAdapter.d.ts +7 -3
  7. package/dist/WalletAdapters/BaseAdapter.d.ts.map +1 -1
  8. package/dist/WalletAdapters/BaseAdapter.js.map +1 -1
  9. package/dist/WalletAdapters/FewchaWallet.d.ts +4 -2
  10. package/dist/WalletAdapters/FewchaWallet.d.ts.map +1 -1
  11. package/dist/WalletAdapters/FewchaWallet.js +56 -54
  12. package/dist/WalletAdapters/FewchaWallet.js.map +1 -1
  13. package/dist/WalletAdapters/HippoExtensionWallet.d.ts +4 -2
  14. package/dist/WalletAdapters/HippoExtensionWallet.d.ts.map +1 -1
  15. package/dist/WalletAdapters/HippoExtensionWallet.js +1 -1
  16. package/dist/WalletAdapters/HippoExtensionWallet.js.map +1 -1
  17. package/dist/WalletAdapters/HippoWallet.d.ts +4 -2
  18. package/dist/WalletAdapters/HippoWallet.d.ts.map +1 -1
  19. package/dist/WalletAdapters/HippoWallet.js +2 -1
  20. package/dist/WalletAdapters/HippoWallet.js.map +1 -1
  21. package/dist/WalletAdapters/MartianWallet.d.ts +7 -4
  22. package/dist/WalletAdapters/MartianWallet.d.ts.map +1 -1
  23. package/dist/WalletAdapters/MartianWallet.js +23 -28
  24. package/dist/WalletAdapters/MartianWallet.js.map +1 -1
  25. package/dist/WalletAdapters/MultiMaskWallet.d.ts +4 -2
  26. package/dist/WalletAdapters/MultiMaskWallet.d.ts.map +1 -1
  27. package/dist/WalletAdapters/MultiMaskWallet.js +1 -1
  28. package/dist/WalletAdapters/MultiMaskWallet.js.map +1 -1
  29. package/dist/WalletAdapters/NightlyWallet.d.ts +0 -41
  30. package/dist/WalletAdapters/NightlyWallet.d.ts.map +1 -1
  31. package/dist/WalletAdapters/NightlyWallet.js +229 -199
  32. package/dist/WalletAdapters/NightlyWallet.js.map +1 -1
  33. package/dist/WalletAdapters/index.d.ts +0 -1
  34. package/dist/WalletAdapters/index.d.ts.map +1 -1
  35. package/dist/WalletAdapters/index.js +1 -1
  36. package/dist/WalletAdapters/index.js.map +1 -1
  37. package/dist/WalletProviders/WalletProvider.d.ts.map +1 -1
  38. package/dist/WalletProviders/WalletProvider.js.map +1 -1
  39. package/dist/WalletProviders/useWallet.d.ts +4 -2
  40. package/dist/WalletProviders/useWallet.d.ts.map +1 -1
  41. package/dist/WalletProviders/useWallet.js.map +1 -1
  42. package/dist/config/aptosConstants.d.ts +2 -2
  43. package/dist/config/aptosConstants.d.ts.map +1 -1
  44. package/dist/config/aptosConstants.js +1 -1
  45. package/dist/config/aptosConstants.js.map +1 -1
  46. package/dist/utilities/util.d.ts +8 -0
  47. package/dist/utilities/util.d.ts.map +1 -0
  48. package/dist/utilities/util.js +14 -0
  49. package/dist/utilities/util.js.map +1 -0
  50. package/package.json +3 -3
  51. package/src/WalletAdapters/AptosWallet.ts +31 -32
  52. package/src/WalletAdapters/BaseAdapter.ts +7 -5
  53. package/src/WalletAdapters/FewchaWallet.ts +67 -69
  54. package/src/WalletAdapters/HippoExtensionWallet.ts +7 -5
  55. package/src/WalletAdapters/HippoWallet.ts +8 -6
  56. package/src/WalletAdapters/MartianWallet.ts +36 -35
  57. package/src/WalletAdapters/MultiMaskWallet.ts +9 -7
  58. package/src/WalletAdapters/NightlyWallet.ts +229 -229
  59. package/src/WalletAdapters/index.ts +1 -1
  60. package/src/WalletProviders/WalletProvider.tsx +1 -2
  61. package/src/WalletProviders/useWallet.ts +4 -5
  62. package/src/config/aptosConstants.ts +1 -1
  63. package/src/utilities/util.ts +11 -0
@@ -1 +1 @@
1
- {"version":3,"file":"aptosConstants.js","sourceRoot":"","sources":["../../src/config/aptosConstants.ts"],"names":[],"mappings":";;;AAAA,iCAAkD;AAErC,QAAA,aAAa,GAAG,mCAAmC,CAAC;AACjE,wDAAwD;AAE3C,QAAA,cAAc,GAAG,uBAAuB,CAAC;AACzC,QAAA,eAAe,GAAG,uCAAuC,CAAC;AAC1D,QAAA,gBAAgB,GAAG,uBAAuB,CAAC;AAC3C,QAAA,iBAAiB,GAAG,qCAAqC,CAAC;AAE1D,QAAA,QAAQ,GAAG,uBAAe,CAAC;AAC3B,QAAA,UAAU,GAAG,yBAAiB,CAAC;AAE/B,QAAA,WAAW,GAAG,IAAI,mBAAW,CAAC,gBAAQ,CAAC,CAAC;AACxC,QAAA,YAAY,GAAG,IAAI,oBAAY,CAAC,gBAAQ,EAAE,kBAAU,CAAC,CAAC"}
1
+ {"version":3,"file":"aptosConstants.js","sourceRoot":"","sources":["../../src/config/aptosConstants.ts"],"names":[],"mappings":";;;AAAA,iCAAkD;AAErC,QAAA,aAAa,GAAG,mCAAmC,CAAC;AACjE,wDAAwD;AAE3C,QAAA,cAAc,GAAG,uBAAuB,CAAC;AACzC,QAAA,eAAe,GAAG,0CAA0C,CAAC;AAC7D,QAAA,gBAAgB,GAAG,uBAAuB,CAAC;AAC3C,QAAA,iBAAiB,GAAG,qCAAqC,CAAC;AAE1D,QAAA,QAAQ,GAAG,uBAAe,CAAC;AAC3B,QAAA,UAAU,GAAG,yBAAiB,CAAC;AAE/B,QAAA,WAAW,GAAG,IAAI,mBAAW,CAAC,gBAAQ,CAAC,CAAC;AACxC,QAAA,YAAY,GAAG,IAAI,oBAAY,CAAC,gBAAQ,EAAE,kBAAU,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { TransactionPayload } from 'aptos/dist/generated';
2
+ export declare const payloadV1ToV0: (payload: TransactionPayload) => {
3
+ type: string;
4
+ function: string;
5
+ type_arguments: string[];
6
+ arguments: any[];
7
+ };
8
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/utilities/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAA4C,MAAM,sBAAsB,CAAC;AAEpG,eAAO,MAAM,aAAa,YAAa,kBAAkB;;;;;CAQxD,CAAC"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.payloadV1ToV0 = void 0;
4
+ const payloadV1ToV0 = (payload) => {
5
+ const v1 = payload;
6
+ return {
7
+ type: 'script_function_payload',
8
+ function: v1.function,
9
+ type_arguments: v1.type_arguments,
10
+ arguments: v1.arguments
11
+ };
12
+ };
13
+ exports.payloadV1ToV0 = payloadV1ToV0;
14
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/utilities/util.ts"],"names":[],"mappings":";;;AAEO,MAAM,aAAa,GAAG,CAAC,OAA2B,EAAE,EAAE;IAC3D,MAAM,EAAE,GAAG,OAAmD,CAAC;IAC/D,OAAO;QACL,IAAI,EAAE,yBAAyB;QAC/B,QAAQ,EAAE,EAAE,CAAC,QAAQ;QACrB,cAAc,EAAE,EAAE,CAAC,cAAc;QACjC,SAAS,EAAE,EAAE,CAAC,SAAS;KACxB,CAAC;AACJ,CAAC,CAAC;AARW,QAAA,aAAa,iBAQxB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manahippo/aptos-wallet-adapter",
3
- "version": "0.1.17",
3
+ "version": "0.1.20",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "files": [
@@ -23,11 +23,11 @@
23
23
  "prettier": "^2.7.1"
24
24
  },
25
25
  "dependencies": {
26
- "@fewcha/web3": "^0.1.6",
26
+ "@fewcha/web3": "^0.1.13",
27
27
  "@types/jest": "^27.0.1",
28
28
  "@types/node": "^16.7.13",
29
29
  "@types/react": "^18.0.0",
30
- "aptos": "1.2.0",
30
+ "aptos": "^1.3.6",
31
31
  "eventemitter3": "^4.0.7",
32
32
  "typescript": "^4.4.2"
33
33
  }
@@ -1,8 +1,9 @@
1
1
  import {
2
- PendingTransaction,
2
+ HexEncodedBytes,
3
3
  SubmitTransactionRequest,
4
4
  TransactionPayload
5
- } from 'aptos/dist/api/data-contracts';
5
+ } from 'aptos/dist/generated';
6
+ import { payloadV1ToV0 } from '../utilities/util';
6
7
  import {
7
8
  WalletDisconnectionError,
8
9
  WalletNotConnectedError,
@@ -18,12 +19,11 @@ import {
18
19
  } from './BaseAdapter';
19
20
 
20
21
  interface IAptosWallet {
21
- requestId: number;
22
22
  connect: () => Promise<{ address: string }>;
23
23
  account: () => Promise<string>;
24
24
  isConnected: () => Promise<boolean>;
25
- signAndSubmitTransaction(transaction: any): Promise<void>;
26
- signTransaction(transaction: any): Promise<void>;
25
+ signAndSubmitTransaction(transaction: any): Promise<{ hash: HexEncodedBytes }>;
26
+ signTransaction(transaction: any): Promise<SubmitTransactionRequest>;
27
27
  disconnect(): Promise<void>;
28
28
  }
29
29
 
@@ -120,8 +120,12 @@ export class AptosWalletAdapter extends BaseWalletAdapter {
120
120
  this._connecting = true;
121
121
 
122
122
  const provider = this._provider || window.aptos;
123
- const response = await provider?.connect();
123
+ const isConnected = await this._provider?.isConnected();
124
+ if (isConnected === true) {
125
+ await provider?.disconnect();
126
+ }
124
127
 
128
+ const response = await provider?.connect();
125
129
  this._wallet = {
126
130
  publicKey: response?.address,
127
131
  isConnected: true
@@ -155,44 +159,39 @@ export class AptosWalletAdapter extends BaseWalletAdapter {
155
159
  async signTransaction(transaction: TransactionPayload): Promise<SubmitTransactionRequest> {
156
160
  try {
157
161
  const wallet = this._wallet;
158
- if (!wallet) throw new WalletNotConnectedError();
162
+ const provider = this._provider || window.aptos;
163
+ if (!wallet || !provider) throw new WalletNotConnectedError();
159
164
 
160
- try {
161
- const provider = this._provider || window.aptos;
162
- const response = await provider?.signTransaction(transaction);
163
- if (response) {
164
- return response;
165
- } else {
166
- throw new Error('Transaction failed');
167
- }
168
- } catch (error: any) {
169
- 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');
170
170
  }
171
171
  } catch (error: any) {
172
- this.emit('error', error);
172
+ const errMsg = error.message;
173
+ this.emit('error', new WalletSignTransactionError(errMsg));
173
174
  throw error;
174
175
  }
175
176
  }
176
177
 
177
- async signAndSubmitTransaction(transaction: TransactionPayload): Promise<PendingTransaction> {
178
+ async signAndSubmitTransaction(
179
+ transaction: TransactionPayload
180
+ ): Promise<{ hash: HexEncodedBytes }> {
178
181
  try {
179
182
  const wallet = this._wallet;
180
- if (!wallet) throw new WalletNotConnectedError();
183
+ const provider = this._provider || window.aptos;
184
+ if (!wallet || !provider) throw new WalletNotConnectedError();
181
185
 
182
- try {
183
- const provider = this._provider || window.aptos;
184
- const response = await provider?.signAndSubmitTransaction(transaction);
185
- if (response) {
186
- return response;
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);
186
+ const response = await provider?.signAndSubmitTransaction(payloadV1ToV0(transaction));
187
+ if (response) {
188
+ return response;
189
+ } else {
190
+ throw new Error('Transaction failed');
193
191
  }
194
192
  } catch (error: any) {
195
- this.emit('error', error);
193
+ const errMsg = error.message;
194
+ this.emit('error', new WalletSignTransactionError(errMsg));
196
195
  throw error;
197
196
  }
198
197
  }
@@ -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 {
@@ -68,7 +68,7 @@ export interface WalletAdapterProps<Name extends string = string> {
68
68
  transaction: TransactionPayload
69
69
  // connection: Connection,
70
70
  // options?: SendTransactionOptions
71
- ): Promise<PendingTransaction>;
71
+ ): Promise<{ hash: HexEncodedBytes }>;
72
72
  signTransaction(
73
73
  transaction: TransactionPayload
74
74
  // connection: Connection,
@@ -106,7 +106,9 @@ export abstract class BaseWalletAdapter
106
106
 
107
107
  abstract connect(): Promise<void>;
108
108
  abstract disconnect(): Promise<void>;
109
- abstract signAndSubmitTransaction(transaction: TransactionPayload): Promise<PendingTransaction>;
109
+ abstract signAndSubmitTransaction(
110
+ transaction: TransactionPayload
111
+ ): Promise<{ hash: HexEncodedBytes }>;
110
112
 
111
113
  abstract signTransaction(transaction: TransactionPayload): Promise<SubmitTransactionRequest>;
112
114
  }
@@ -1,10 +1,5 @@
1
1
  import {
2
- PendingTransaction,
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,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
 
@@ -77,28 +78,6 @@ export class FewchaWalletAdapter extends BaseWalletAdapter {
77
78
  return false;
78
79
  });
79
80
  }
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
81
  }
103
82
 
104
83
  get publicAccount(): AccountKeys {
@@ -133,12 +112,31 @@ export class FewchaWalletAdapter extends BaseWalletAdapter {
133
112
  throw new WalletNotReadyError();
134
113
 
135
114
  this._connecting = true;
136
- const provider = this._provider;
115
+ const provider = this._provider || window.fewcha;
137
116
  const isConnected = await this._provider?.isConnected();
138
- if (isConnected) {
117
+ if (isConnected?.data === true) {
139
118
  await provider?.disconnect();
140
119
  }
141
- await provider?.connect();
120
+ const response = await provider?.connect();
121
+ if (response.status === 401) {
122
+ throw new WalletConnectionError('User has rejected the connection');
123
+ } else if (response.status !== 200) {
124
+ throw new WalletConnectionError('Wallet connect issue');
125
+ }
126
+ let accountDetail = { ...response.data };
127
+
128
+ if (!accountDetail.publicKey) {
129
+ const accountResp = await provider?.account();
130
+ if (!accountResp.data.publicKey) {
131
+ throw new WalletConnectionError('Wallet connect issue', response.data);
132
+ }
133
+ accountDetail = { ...accountResp.data };
134
+ }
135
+ this._wallet = {
136
+ connected: true,
137
+ ...accountDetail
138
+ };
139
+ this.emit('connect', this._wallet.publicKey);
142
140
  } catch (error: any) {
143
141
  this.emit('error', error);
144
142
  throw error;
@@ -153,8 +151,13 @@ export class FewchaWalletAdapter extends BaseWalletAdapter {
153
151
  this._wallet = null;
154
152
 
155
153
  try {
156
- const provider = this._provider;
157
- await provider?.disconnect();
154
+ const provider = this._provider || window.fewcha;
155
+ const isDisconnected = await provider?.disconnect();
156
+ if (isDisconnected.data === true) {
157
+ this.emit('disconnect');
158
+ } else {
159
+ throw new Error('Disconnect failed');
160
+ }
158
161
  } catch (error: any) {
159
162
  this.emit('error', new WalletDisconnectionError(error?.message, error));
160
163
  }
@@ -163,53 +166,48 @@ export class FewchaWalletAdapter extends BaseWalletAdapter {
163
166
 
164
167
  async signTransaction(transaction: TransactionPayload): Promise<SubmitTransactionRequest> {
165
168
  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;
169
+ const wallet = this._wallet;
170
+ if (!wallet) throw new WalletNotConnectedError();
171
+
172
+ const provider = this._provider || window.fewcha;
173
+ const tx = await provider.generateTransaction(payloadV1ToV0(transaction));
174
+ if (!tx) throw new WalletSignTransactionError('Cannot generate transaction');
175
+ const response = await provider?.signTransaction(tx);
176
+
177
+ if (!response) {
178
+ throw new WalletSignTransactionError('No response');
179
+ }
180
+ const result = { hash: response } as any;
181
+ return result as SubmitTransactionRequest;
184
182
  } catch (error: any) {
185
- this.emit('error', error);
183
+ const errMsg = error instanceof Error ? error.message : error.response.data.message;
184
+ this.emit('error', new WalletSignTransactionError(errMsg));
186
185
  throw error;
187
186
  }
188
187
  }
189
188
 
190
- async signAndSubmitTransaction(transaction: TransactionPayload): Promise<PendingTransaction> {
189
+ async signAndSubmitTransaction(
190
+ transaction: TransactionPayload
191
+ ): Promise<{ hash: HexEncodedBytes }> {
191
192
  try {
192
193
  const wallet = this._wallet;
193
194
  if (!wallet) throw new WalletNotConnectedError();
194
195
 
195
- try {
196
- const provider = this._provider;
197
- const tx = await aptosClient.generateTransaction(wallet.address, transaction);
198
- await provider?.signAndSubmitTransaction(tx);
199
-
200
- const promise = await new Promise((resolve, reject) => {
201
- this.once('success', resolve);
202
- this.once('error', reject);
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);
196
+ const provider = this._provider || window.fewcha;
197
+ const tx = await provider.generateTransaction(payloadV1ToV0(transaction));
198
+ if (!tx) throw new WalletSignTransactionError('Cannot generate transaction');
199
+ const response = await provider?.signAndSubmitTransaction(tx.data);
200
+ if (response.status === 401) {
201
+ throw new WalletSignTransactionError('User has rejected the transaction');
202
+ } else if (response.status !== 200) {
203
+ throw new WalletSignTransactionError('Transaction issue');
210
204
  }
205
+ return {
206
+ hash: response.data
207
+ };
211
208
  } catch (error: any) {
212
- this.emit('error', error);
209
+ const errMsg = error instanceof Error ? error.message : error.response.data.message;
210
+ this.emit('error', new WalletSignTransactionError(errMsg));
213
211
  throw error;
214
212
  }
215
213
  }
@@ -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,14 +133,14 @@ 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;
142
- await provider?.disconnect();
143
- // console.log(4);
138
+ const provider = this._provider || window.martian;
139
+ const isConnected = await provider?.isConnected();
140
+ if (isConnected) {
141
+ await provider?.disconnect();
142
+ }
144
143
  const response = await provider?.connect();
145
- // console.log(5, response);
146
144
 
147
145
  if (!response) {
148
146
  throw new WalletNotConnectedError('No connect response');
@@ -154,16 +152,12 @@ export class MartianWalletAdapter extends BaseWalletAdapter {
154
152
  ...walletAccount,
155
153
  isConnected: true
156
154
  };
157
- // console.log(6, this._wallet);
158
155
  }
159
- // console.log(9, this._wallet?.address);
160
156
  this.emit('connect', this._wallet?.address || '');
161
157
  } catch (error: any) {
162
- // console.log(10, error);
163
- this.emit('error', error);
158
+ this.emit('error', new Error(error));
164
159
  throw error;
165
160
  } finally {
166
- // console.log(11);
167
161
  this._connecting = false;
168
162
  }
169
163
  }
@@ -187,39 +181,46 @@ export class MartianWalletAdapter extends BaseWalletAdapter {
187
181
  async signTransaction(transactionPyld: TransactionPayload): Promise<SubmitTransactionRequest> {
188
182
  try {
189
183
  const wallet = this._wallet;
190
- const provider = this._provider;
191
- if (!wallet) throw new WalletNotConnectedError();
192
- const tx = await aptosClient.generateTransaction(wallet.address || '', transactionPyld);
193
- 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);
194
192
 
195
193
  if (!response) {
196
194
  throw new WalletSignTransactionError('No response');
197
195
  }
198
- return {
199
- hash: response
200
- } as PendingTransaction;
196
+ const result = { hash: response } as any;
197
+ return result as SubmitTransactionRequest;
201
198
  } catch (error: any) {
202
199
  this.emit('error', error);
203
200
  throw error;
204
201
  }
205
202
  }
206
203
 
207
- async signAndSubmitTransaction(transactionPyld: TransactionPayload): Promise<PendingTransaction> {
204
+ async signAndSubmitTransaction(
205
+ transactionPyld: TransactionPayload
206
+ ): Promise<{ hash: HexEncodedBytes }> {
208
207
  try {
209
208
  const wallet = this._wallet;
210
- const provider = this._provider;
211
- if (!wallet) throw new WalletNotConnectedError();
212
- 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');
213
216
  const response = await provider?.signAndSubmitTransaction(tx);
214
217
 
215
218
  if (!response) {
216
219
  throw new WalletSignTransactionError('No response');
217
220
  }
218
- return {
219
- hash: response
220
- } as PendingTransaction;
221
+ return { hash: response };
221
222
  } catch (error: any) {
222
- this.emit('error', error);
223
+ this.emit('error', new Error(error));
223
224
  throw error;
224
225
  }
225
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);