@manahippo/aptos-wallet-adapter 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -16
- package/dist/WalletAdapters/AptosWallet.d.ts +8 -5
- package/dist/WalletAdapters/AptosWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/AptosWallet.js +25 -29
- package/dist/WalletAdapters/AptosWallet.js.map +1 -1
- package/dist/WalletAdapters/BaseAdapter.d.ts +7 -5
- package/dist/WalletAdapters/BaseAdapter.d.ts.map +1 -1
- package/dist/WalletAdapters/BaseAdapter.js.map +1 -1
- package/dist/WalletAdapters/FewchaWallet.d.ts +4 -2
- package/dist/WalletAdapters/FewchaWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/FewchaWallet.js +58 -57
- package/dist/WalletAdapters/FewchaWallet.js.map +1 -1
- package/dist/WalletAdapters/HippoExtensionWallet.d.ts +4 -2
- package/dist/WalletAdapters/HippoExtensionWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/HippoExtensionWallet.js +3 -3
- package/dist/WalletAdapters/HippoExtensionWallet.js.map +1 -1
- package/dist/WalletAdapters/HippoWallet.d.ts +4 -2
- package/dist/WalletAdapters/HippoWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/HippoWallet.js +2 -1
- package/dist/WalletAdapters/HippoWallet.js.map +1 -1
- package/dist/WalletAdapters/MartianWallet.d.ts +7 -4
- package/dist/WalletAdapters/MartianWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/MartianWallet.js +24 -30
- package/dist/WalletAdapters/MartianWallet.js.map +1 -1
- package/dist/WalletAdapters/MultiMaskWallet.d.ts +4 -2
- package/dist/WalletAdapters/MultiMaskWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/MultiMaskWallet.js +4 -4
- package/dist/WalletAdapters/MultiMaskWallet.js.map +1 -1
- package/dist/WalletAdapters/NightlyWallet.d.ts +1 -41
- package/dist/WalletAdapters/NightlyWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/NightlyWallet.js +232 -198
- package/dist/WalletAdapters/NightlyWallet.js.map +1 -1
- package/dist/WalletAdapters/PontemWallet.d.ts +55 -0
- package/dist/WalletAdapters/PontemWallet.d.ts.map +1 -0
- package/dist/WalletAdapters/PontemWallet.js +160 -0
- package/dist/WalletAdapters/PontemWallet.js.map +1 -0
- package/dist/WalletAdapters/index.d.ts +1 -1
- package/dist/WalletAdapters/index.d.ts.map +1 -1
- package/dist/WalletAdapters/index.js +2 -1
- package/dist/WalletAdapters/index.js.map +1 -1
- package/dist/WalletProviders/WalletProvider.d.ts +0 -1
- package/dist/WalletProviders/WalletProvider.d.ts.map +1 -1
- package/dist/WalletProviders/WalletProvider.js +1 -6
- package/dist/WalletProviders/WalletProvider.js.map +1 -1
- package/dist/WalletProviders/useWallet.d.ts +4 -3
- package/dist/WalletProviders/useWallet.d.ts.map +1 -1
- package/dist/WalletProviders/useWallet.js +1 -1
- package/dist/WalletProviders/useWallet.js.map +1 -1
- package/dist/config/aptosConstants.d.ts +2 -2
- package/dist/config/aptosConstants.d.ts.map +1 -1
- package/dist/config/aptosConstants.js +1 -1
- package/dist/config/aptosConstants.js.map +1 -1
- package/dist/hooks/useLocalStorage.d.ts.map +1 -1
- package/dist/hooks/useLocalStorage.js +9 -4
- package/dist/hooks/useLocalStorage.js.map +1 -1
- package/dist/hooks/useSSR.d.ts +4 -0
- package/dist/hooks/useSSR.d.ts.map +1 -0
- package/dist/hooks/useSSR.js +17 -0
- package/dist/hooks/useSSR.js.map +1 -0
- package/dist/utilities/util.d.ts +8 -0
- package/dist/utilities/util.d.ts.map +1 -0
- package/dist/utilities/util.js +14 -0
- package/dist/utilities/util.js.map +1 -0
- package/package.json +10 -10
- package/src/WalletAdapters/AptosWallet.ts +32 -34
- package/src/WalletAdapters/BaseAdapter.ts +8 -19
- package/src/WalletAdapters/FewchaWallet.ts +69 -73
- package/src/WalletAdapters/HippoExtensionWallet.ts +9 -7
- package/src/WalletAdapters/HippoWallet.ts +8 -6
- package/src/WalletAdapters/MartianWallet.ts +31 -37
- package/src/WalletAdapters/MultiMaskWallet.ts +13 -10
- package/src/WalletAdapters/NightlyWallet.ts +230 -229
- package/src/WalletAdapters/PontemWallet.ts +225 -0
- package/src/WalletAdapters/index.ts +2 -1
- package/src/WalletProviders/WalletProvider.tsx +1 -9
- package/src/WalletProviders/useWallet.ts +6 -14
- package/src/config/aptosConstants.ts +1 -1
- package/src/hooks/useLocalStorage.ts +9 -4
- package/src/hooks/useSSR.ts +15 -0
- package/src/utilities/util.ts +11 -0
@@ -0,0 +1,225 @@
|
|
1
|
+
import { MaybeHexString } from 'aptos';
|
2
|
+
import {
|
3
|
+
TransactionPayload,
|
4
|
+
SubmitTransactionRequest,
|
5
|
+
HexEncodedBytes
|
6
|
+
} from 'aptos/dist/generated';
|
7
|
+
import {
|
8
|
+
WalletDisconnectionError,
|
9
|
+
WalletNotConnectedError,
|
10
|
+
WalletNotReadyError,
|
11
|
+
WalletSignTransactionError
|
12
|
+
} from '../WalletProviders/errors';
|
13
|
+
import {
|
14
|
+
AccountKeys,
|
15
|
+
BaseWalletAdapter,
|
16
|
+
scopePollingDetectionStrategy,
|
17
|
+
WalletName,
|
18
|
+
WalletReadyState
|
19
|
+
} from './BaseAdapter';
|
20
|
+
|
21
|
+
interface ConnectPontemAccount {
|
22
|
+
address: MaybeHexString;
|
23
|
+
method: string;
|
24
|
+
publicKey: MaybeHexString;
|
25
|
+
status: number;
|
26
|
+
}
|
27
|
+
|
28
|
+
interface PontemAccount {
|
29
|
+
address: MaybeHexString;
|
30
|
+
publicKey?: MaybeHexString;
|
31
|
+
authKey?: MaybeHexString;
|
32
|
+
isConnected: boolean;
|
33
|
+
}
|
34
|
+
interface IPontemWallet {
|
35
|
+
connect: () => Promise<ConnectPontemAccount>;
|
36
|
+
account(): Promise<MaybeHexString>;
|
37
|
+
generateTransaction(sender: MaybeHexString, payload: any): Promise<any>;
|
38
|
+
signAndSubmit(transaction: TransactionPayload): Promise<{
|
39
|
+
success: boolean;
|
40
|
+
result: {
|
41
|
+
hash: HexEncodedBytes;
|
42
|
+
};
|
43
|
+
}>;
|
44
|
+
// signTransaction(transaction: TransactionPayload): Promise<HexEncodedBytes>;
|
45
|
+
disconnect(): Promise<void>;
|
46
|
+
}
|
47
|
+
|
48
|
+
interface PontemWindow extends Window {
|
49
|
+
pontem?: IPontemWallet;
|
50
|
+
}
|
51
|
+
|
52
|
+
declare const window: PontemWindow;
|
53
|
+
|
54
|
+
export const PontemWalletName = 'PontemWallet' as WalletName<'PontemWallet'>;
|
55
|
+
|
56
|
+
export interface PontemWalletAdapterConfig {
|
57
|
+
provider?: IPontemWallet;
|
58
|
+
// network?: WalletAdapterNetwork;
|
59
|
+
timeout?: number;
|
60
|
+
}
|
61
|
+
|
62
|
+
export class PontemWalletAdapter extends BaseWalletAdapter {
|
63
|
+
name = PontemWalletName;
|
64
|
+
|
65
|
+
url = 'https://chrome.google.com/webstore/detail/pontem-wallet/phkbamefinggmakgklpkljjmgibohnba';
|
66
|
+
|
67
|
+
icon =
|
68
|
+
'https://www.gitbook.com/cdn-cgi/image/width=20,height=20,fit=contain,dpr=2,format=auto/https%3A%2F%2F736486047-files.gitbook.io%2F~%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fspaces%252F-MVVJKmKQGx983dZy_jr%252Favatar-1619180126965.png%3Fgeneration%3D1619180127194239%26alt%3Dmedia';
|
69
|
+
|
70
|
+
protected _provider: IPontemWallet | undefined;
|
71
|
+
|
72
|
+
// protected _network: WalletAdapterNetwork;
|
73
|
+
protected _timeout: number;
|
74
|
+
|
75
|
+
protected _readyState: WalletReadyState =
|
76
|
+
typeof window === 'undefined' || typeof document === 'undefined'
|
77
|
+
? WalletReadyState.Unsupported
|
78
|
+
: WalletReadyState.NotDetected;
|
79
|
+
|
80
|
+
protected _connecting: boolean;
|
81
|
+
|
82
|
+
protected _wallet: PontemAccount | null;
|
83
|
+
|
84
|
+
constructor({
|
85
|
+
// provider,
|
86
|
+
// network = WalletAdapterNetwork.Mainnet,
|
87
|
+
timeout = 10000
|
88
|
+
}: PontemWalletAdapterConfig = {}) {
|
89
|
+
super();
|
90
|
+
|
91
|
+
this._provider = typeof window !== 'undefined' ? window.pontem : undefined;
|
92
|
+
// this._network = network;
|
93
|
+
this._timeout = timeout;
|
94
|
+
this._connecting = false;
|
95
|
+
this._wallet = null;
|
96
|
+
|
97
|
+
if (typeof window !== 'undefined' && this._readyState !== WalletReadyState.Unsupported) {
|
98
|
+
scopePollingDetectionStrategy(() => {
|
99
|
+
if (this._provider) {
|
100
|
+
this._readyState = WalletReadyState.Installed;
|
101
|
+
this.emit('readyStateChange', this._readyState);
|
102
|
+
return true;
|
103
|
+
}
|
104
|
+
return false;
|
105
|
+
});
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
get publicAccount(): AccountKeys {
|
110
|
+
return {
|
111
|
+
publicKey: this._wallet?.publicKey || null,
|
112
|
+
address: this._wallet?.address || null,
|
113
|
+
authKey: this._wallet?.authKey || null
|
114
|
+
};
|
115
|
+
}
|
116
|
+
|
117
|
+
get connecting(): boolean {
|
118
|
+
return this._connecting;
|
119
|
+
}
|
120
|
+
|
121
|
+
get connected(): boolean {
|
122
|
+
return !!this._wallet?.isConnected;
|
123
|
+
}
|
124
|
+
|
125
|
+
get readyState(): WalletReadyState {
|
126
|
+
return this._readyState;
|
127
|
+
}
|
128
|
+
|
129
|
+
async connect(): Promise<void> {
|
130
|
+
try {
|
131
|
+
if (this.connected || this.connecting) return;
|
132
|
+
if (
|
133
|
+
!(
|
134
|
+
this._readyState === WalletReadyState.Loadable ||
|
135
|
+
this._readyState === WalletReadyState.Installed
|
136
|
+
)
|
137
|
+
)
|
138
|
+
throw new WalletNotReadyError();
|
139
|
+
this._connecting = true;
|
140
|
+
|
141
|
+
const provider = this._provider || window.pontem;
|
142
|
+
// const isConnected = await provider?.isConnected();
|
143
|
+
// if (isConnected) {
|
144
|
+
// await provider?.disconnect();
|
145
|
+
// }
|
146
|
+
const response = await provider?.connect();
|
147
|
+
|
148
|
+
if (!response) {
|
149
|
+
throw new WalletNotConnectedError('No connect response');
|
150
|
+
}
|
151
|
+
|
152
|
+
const walletAccount = await provider?.account();
|
153
|
+
if (walletAccount) {
|
154
|
+
this._wallet = {
|
155
|
+
address: walletAccount,
|
156
|
+
isConnected: true
|
157
|
+
};
|
158
|
+
}
|
159
|
+
this.emit('connect', this._wallet?.address || '');
|
160
|
+
} catch (error: any) {
|
161
|
+
this.emit('error', new Error('User has rejected the connection'));
|
162
|
+
throw error;
|
163
|
+
} finally {
|
164
|
+
this._connecting = false;
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
async disconnect(): Promise<void> {
|
169
|
+
const wallet = this._wallet;
|
170
|
+
const provider = this._provider;
|
171
|
+
if (wallet) {
|
172
|
+
this._wallet = null;
|
173
|
+
|
174
|
+
try {
|
175
|
+
await provider?.disconnect();
|
176
|
+
} catch (error: any) {
|
177
|
+
this.emit('error', new WalletDisconnectionError(error?.message, error));
|
178
|
+
}
|
179
|
+
}
|
180
|
+
|
181
|
+
this.emit('disconnect');
|
182
|
+
}
|
183
|
+
|
184
|
+
async signTransaction(): Promise<SubmitTransactionRequest> {
|
185
|
+
try {
|
186
|
+
// const wallet = this._wallet;
|
187
|
+
// const provider = this._provider || window.pontem;
|
188
|
+
// if (!wallet || !provider) throw new WalletNotConnectedError();
|
189
|
+
// const tx = await provider.generateTransaction(
|
190
|
+
// wallet.address || '',
|
191
|
+
// payloadV1ToV0(transactionPyld)
|
192
|
+
// );
|
193
|
+
// if (!tx) throw new WalletSignTransactionError('Cannot generate transaction');
|
194
|
+
// const response = await provider?.signTransaction(tx);
|
195
|
+
|
196
|
+
// if (!response) {
|
197
|
+
// throw new WalletSignTransactionError('No response');
|
198
|
+
// }
|
199
|
+
// const result = { hash: response } as any;
|
200
|
+
return {} as SubmitTransactionRequest;
|
201
|
+
} catch (error: any) {
|
202
|
+
this.emit('error', error);
|
203
|
+
throw error;
|
204
|
+
}
|
205
|
+
}
|
206
|
+
|
207
|
+
async signAndSubmitTransaction(
|
208
|
+
transactionPyld: TransactionPayload
|
209
|
+
): Promise<{ hash: HexEncodedBytes }> {
|
210
|
+
try {
|
211
|
+
const wallet = this._wallet;
|
212
|
+
const provider = this._provider || window.pontem;
|
213
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
214
|
+
const response = await provider?.signAndSubmit(transactionPyld);
|
215
|
+
|
216
|
+
if (!response || !response.success) {
|
217
|
+
throw new WalletSignTransactionError('No response');
|
218
|
+
}
|
219
|
+
return { hash: response.result.hash };
|
220
|
+
} catch (error: any) {
|
221
|
+
this.emit('error', new Error(error.error.message));
|
222
|
+
throw error;
|
223
|
+
}
|
224
|
+
}
|
225
|
+
}
|
@@ -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,
|
@@ -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
|
@@ -19,7 +18,6 @@ import { Wallet, WalletContext } from './useWallet';
|
|
19
18
|
export interface WalletProviderProps {
|
20
19
|
children: ReactNode;
|
21
20
|
wallets: WalletAdapter[];
|
22
|
-
autoConnect?: boolean;
|
23
21
|
onError?: (error: WalletError) => void;
|
24
22
|
localStorageKey?: string;
|
25
23
|
}
|
@@ -39,7 +37,6 @@ const initialState: {
|
|
39
37
|
export const WalletProvider: FC<WalletProviderProps> = ({
|
40
38
|
children,
|
41
39
|
wallets: adapters,
|
42
|
-
autoConnect = false,
|
43
40
|
onError,
|
44
41
|
localStorageKey = 'walletName'
|
45
42
|
}) => {
|
@@ -141,7 +138,6 @@ export const WalletProvider: FC<WalletProviderProps> = ({
|
|
141
138
|
adapter.off('error', handleError);
|
142
139
|
};
|
143
140
|
}
|
144
|
-
return () => null;
|
145
141
|
}, [adapter, handleConnect, handleDisconnect, handleError]);
|
146
142
|
|
147
143
|
// When the adapter changes, disconnect the old one
|
@@ -244,7 +240,6 @@ export const WalletProvider: FC<WalletProviderProps> = ({
|
|
244
240
|
return (
|
245
241
|
<WalletContext.Provider
|
246
242
|
value={{
|
247
|
-
autoConnect,
|
248
243
|
wallets,
|
249
244
|
wallet,
|
250
245
|
account,
|
@@ -255,10 +250,7 @@ export const WalletProvider: FC<WalletProviderProps> = ({
|
|
255
250
|
connect,
|
256
251
|
disconnect,
|
257
252
|
signAndSubmitTransaction,
|
258
|
-
// sendTransaction,
|
259
253
|
signTransaction
|
260
|
-
// signAllTransactions,
|
261
|
-
// signMessage
|
262
254
|
}}>
|
263
255
|
{children}
|
264
256
|
</WalletContext.Provider>
|
@@ -1,12 +1,11 @@
|
|
1
1
|
import {
|
2
|
-
|
2
|
+
TransactionPayload,
|
3
3
|
SubmitTransactionRequest,
|
4
|
-
|
5
|
-
} from 'aptos/dist/
|
4
|
+
HexEncodedBytes
|
5
|
+
} from 'aptos/dist/generated';
|
6
6
|
import { createContext, useContext } from 'react';
|
7
7
|
import {
|
8
8
|
AccountKeys,
|
9
|
-
PublicKey,
|
10
9
|
WalletAdapter,
|
11
10
|
WalletName,
|
12
11
|
WalletReadyState
|
@@ -18,7 +17,7 @@ export interface Wallet {
|
|
18
17
|
}
|
19
18
|
|
20
19
|
export interface WalletContextState {
|
21
|
-
autoConnect: boolean;
|
20
|
+
// autoConnect: boolean;
|
22
21
|
wallets: Wallet[];
|
23
22
|
wallet: Wallet | null;
|
24
23
|
account: AccountKeys | null;
|
@@ -28,19 +27,12 @@ export interface WalletContextState {
|
|
28
27
|
select(walletName: WalletName): void;
|
29
28
|
connect(walletName: string): Promise<void>;
|
30
29
|
disconnect(): Promise<void>;
|
31
|
-
signAndSubmitTransaction(
|
32
|
-
transaction: TransactionPayload
|
33
|
-
// connection: Connection,
|
34
|
-
// options?: SendTransactionOptions
|
35
|
-
): Promise<PendingTransaction>;
|
36
|
-
|
30
|
+
signAndSubmitTransaction(transaction: TransactionPayload): Promise<{ hash: HexEncodedBytes }>;
|
37
31
|
signTransaction(transaction: TransactionPayload): Promise<SubmitTransactionRequest>;
|
38
|
-
// signAllTransactions: SignerWalletAdapterProps['signAllTransactions'] | undefined;
|
39
|
-
// signMessage: MessageSignerWalletAdapterProps['signMessage'] | undefined;
|
40
32
|
}
|
41
33
|
|
42
34
|
const DEFAULT_CONTEXT = {
|
43
|
-
autoConnect: false,
|
35
|
+
// autoConnect: false,
|
44
36
|
connecting: false,
|
45
37
|
connected: false,
|
46
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
|
|
@@ -1,15 +1,20 @@
|
|
1
1
|
import { useCallback, useState } from 'react';
|
2
|
+
import { useSSR } from './useSSR';
|
2
3
|
|
3
4
|
export const useLocalStorage = () => {
|
5
|
+
const { isClient } = useSSR();
|
4
6
|
const useLocalStorageState = <T>(
|
5
7
|
key: string,
|
6
8
|
defaultState: T,
|
7
9
|
session?: boolean
|
8
10
|
): [T, (T: any) => void] => {
|
9
|
-
|
11
|
+
let storage: undefined | Storage;
|
12
|
+
if (isClient) {
|
13
|
+
storage = session ? sessionStorage : localStorage;
|
14
|
+
}
|
10
15
|
const [state, setState] = useState(() => {
|
11
16
|
try {
|
12
|
-
let storedState = storage
|
17
|
+
let storedState = storage?.getItem(key);
|
13
18
|
if (storedState) {
|
14
19
|
return JSON.parse(storedState || '');
|
15
20
|
}
|
@@ -25,9 +30,9 @@ export const useLocalStorage = () => {
|
|
25
30
|
(newState: any) => {
|
26
31
|
setState(newState);
|
27
32
|
if (newState === null) {
|
28
|
-
storage
|
33
|
+
storage?.removeItem(key);
|
29
34
|
} else {
|
30
|
-
storage
|
35
|
+
storage?.setItem(key, JSON.stringify(newState));
|
31
36
|
}
|
32
37
|
},
|
33
38
|
[key, storage]
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { useEffect, useState } from 'react';
|
2
|
+
|
3
|
+
export const useSSR = () => {
|
4
|
+
const [isClient, setIsClient] = useState(false);
|
5
|
+
|
6
|
+
useEffect(() => {
|
7
|
+
if (typeof window !== 'undefined') {
|
8
|
+
setIsClient(true);
|
9
|
+
}
|
10
|
+
}, []);
|
11
|
+
|
12
|
+
return {
|
13
|
+
isClient
|
14
|
+
};
|
15
|
+
};
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { TransactionPayload, TransactionPayload_EntryFunctionPayload } from 'aptos/dist/generated';
|
2
|
+
|
3
|
+
export const payloadV1ToV0 = (payload: TransactionPayload) => {
|
4
|
+
const v1 = payload as TransactionPayload_EntryFunctionPayload;
|
5
|
+
return {
|
6
|
+
type: 'script_function_payload',
|
7
|
+
function: v1.function,
|
8
|
+
type_arguments: v1.type_arguments,
|
9
|
+
arguments: v1.arguments
|
10
|
+
};
|
11
|
+
};
|