@manahippo/aptos-wallet-adapter 0.4.2 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +8 -2
- package/dist/WalletAdapters/AptosSnap.d.ts +42 -0
- package/dist/WalletAdapters/AptosSnap.d.ts.map +1 -0
- package/dist/WalletAdapters/AptosSnap.js +185 -0
- package/dist/WalletAdapters/AptosSnap.js.map +1 -0
- package/dist/WalletAdapters/FletchWallet.d.ts +57 -0
- package/dist/WalletAdapters/FletchWallet.d.ts.map +1 -0
- package/dist/WalletAdapters/FletchWallet.js +178 -0
- package/dist/WalletAdapters/FletchWallet.js.map +1 -0
- package/dist/WalletAdapters/HyperPayWallet.d.ts +56 -0
- package/dist/WalletAdapters/HyperPayWallet.d.ts.map +1 -0
- package/dist/WalletAdapters/HyperPayWallet.js +180 -0
- package/dist/WalletAdapters/HyperPayWallet.js.map +1 -0
- package/dist/WalletAdapters/PetraWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/PetraWallet.js +1 -1
- package/dist/WalletAdapters/PetraWallet.js.map +1 -1
- package/dist/WalletAdapters/PontemWallet.d.ts +4 -6
- package/dist/WalletAdapters/PontemWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/PontemWallet.js +4 -5
- package/dist/WalletAdapters/PontemWallet.js.map +1 -1
- package/dist/WalletAdapters/RiseWallet.d.ts +51 -0
- package/dist/WalletAdapters/RiseWallet.d.ts.map +1 -0
- package/dist/WalletAdapters/RiseWallet.js +189 -0
- package/dist/WalletAdapters/RiseWallet.js.map +1 -0
- package/dist/WalletAdapters/index.d.ts +4 -0
- package/dist/WalletAdapters/index.d.ts.map +1 -1
- package/dist/WalletAdapters/index.js +4 -0
- package/dist/WalletAdapters/index.js.map +1 -1
- package/dist/WalletProviders/WalletProvider.d.ts.map +1 -1
- package/dist/WalletProviders/WalletProvider.js +12 -5
- package/dist/WalletProviders/WalletProvider.js.map +1 -1
- package/package.json +3 -2
- package/src/WalletAdapters/AptosSnap.ts +235 -0
- package/src/WalletAdapters/FletchWallet.ts +223 -0
- package/src/WalletAdapters/HyperPayWallet.ts +237 -0
- package/src/WalletAdapters/PetraWallet.ts +2 -1
- package/src/WalletAdapters/PontemWallet.ts +8 -9
- package/src/WalletAdapters/RiseWallet.ts +238 -0
- package/src/WalletAdapters/index.ts +4 -0
- package/src/WalletProviders/WalletProvider.tsx +14 -7
@@ -0,0 +1,237 @@
|
|
1
|
+
import { MaybeHexString } from 'aptos';
|
2
|
+
import { TransactionPayload, HexEncodedBytes } from 'aptos/src/generated';
|
3
|
+
import {
|
4
|
+
WalletDisconnectionError,
|
5
|
+
WalletNotConnectedError,
|
6
|
+
WalletNotReadyError,
|
7
|
+
WalletSignAndSubmitMessageError,
|
8
|
+
WalletSignMessageError,
|
9
|
+
WalletSignTransactionError
|
10
|
+
} from '../WalletProviders/errors';
|
11
|
+
import {
|
12
|
+
AccountKeys,
|
13
|
+
BaseWalletAdapter,
|
14
|
+
scopePollingDetectionStrategy,
|
15
|
+
WalletName,
|
16
|
+
WalletReadyState
|
17
|
+
} from './BaseAdapter';
|
18
|
+
|
19
|
+
interface ConnectHyperPayAccount {
|
20
|
+
address: MaybeHexString;
|
21
|
+
method: string;
|
22
|
+
publicKey: MaybeHexString;
|
23
|
+
status: number;
|
24
|
+
}
|
25
|
+
|
26
|
+
interface HyperPayAccount {
|
27
|
+
address: MaybeHexString;
|
28
|
+
publicKey: MaybeHexString;
|
29
|
+
authKey: MaybeHexString;
|
30
|
+
isConnected: boolean;
|
31
|
+
}
|
32
|
+
interface IHyperPayWallet {
|
33
|
+
connect: () => Promise<ConnectHyperPayAccount>;
|
34
|
+
account(): Promise<HyperPayAccount>;
|
35
|
+
isConnected(): Promise<boolean>;
|
36
|
+
generateTransaction(sender: MaybeHexString, payload: any, options?: any): Promise<any>;
|
37
|
+
signAndSubmitTransaction(transaction: TransactionPayload): Promise<HexEncodedBytes>;
|
38
|
+
signTransaction(transaction: TransactionPayload): Promise<Uint8Array>;
|
39
|
+
signMessage(message: string): Promise<{ signature: string }>;
|
40
|
+
disconnect(): Promise<void>;
|
41
|
+
}
|
42
|
+
|
43
|
+
interface HyperPayWindow extends Window {
|
44
|
+
hyperpay?: IHyperPayWallet;
|
45
|
+
}
|
46
|
+
|
47
|
+
declare const window: HyperPayWindow;
|
48
|
+
|
49
|
+
export const HyperPayWalletName = 'HyperPay' as WalletName<'HyperPay'>;
|
50
|
+
|
51
|
+
export interface HyperPayWalletAdapterConfig {
|
52
|
+
provider?: IHyperPayWallet;
|
53
|
+
// network?: WalletAdapterNetwork;
|
54
|
+
timeout?: number;
|
55
|
+
}
|
56
|
+
|
57
|
+
export class HyperPayWalletAdapter extends BaseWalletAdapter {
|
58
|
+
name = HyperPayWalletName;
|
59
|
+
|
60
|
+
url = 'https://www.hyperpay.tech/';
|
61
|
+
|
62
|
+
icon =
|
63
|
+
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMjE1IDEyMTUiPjxwYXRoIGQ9Ik02MDcuNSAwQzk0My4wMTMgMCAxMjE1IDI3MS45ODcgMTIxNSA2MDcuNVM5NDMuMDEzIDEyMTUgNjA3LjUgMTIxNSAwIDk0My4wMTMgMCA2MDcuNSAyNzEuOTg3IDAgNjA3LjUgMHpNMzUxLjY4IDM3MS4zMTVzMy43MDgtNzIuOSA3Ny43Ni03Mi45aDIwNC4xMnMxMTkuNDM3LS4xIDIwNC4xMiA3NS4zM2MwIDAgMTExLjg0MyA5My42MTIgMTE2LjY0IDIzNS43MSAwIDAgMS45NjIgMTE5LjA0NS03Mi45IDIxMS40MSAwIDAtNzcuOTMxIDEyMS41LTI2Mi40NCAxMjEuNUg0NDEuNTlzLTg5LjkxIDExLjA0OS04OS45MS04NS4wNXYtNDg2ek0xMTkuMzQ0IDU1My42NTlzLjkwNi0xNy44MiAxOS4wMDgtMTcuODJoNDkuOXMyOS4yLS4wMjMgNDkuOSAxOC40MTRjMCAwIDI3LjMzOSAyMi44ODMgMjguNTEyIDU3LjYxOCAwIDAgLjQ4IDI5LjEtMTcuODIgNTEuNjc4IDAgMC0xOS4wNSAyOS43LTY0LjE1MiAyOS43aC00My4zN3MtMjEuOTc4IDIuNy0yMS45NzgtMjAuNzl2LTExOC44eiIgZmlsbD0iIzE1N0VGQiIgZmlsbC1ydWxlPSJldmVub2RkIi8+PC9zdmc+';
|
64
|
+
|
65
|
+
protected _provider: IHyperPayWallet | undefined;
|
66
|
+
|
67
|
+
// protected _network: WalletAdapterNetwork;
|
68
|
+
protected _timeout: number;
|
69
|
+
|
70
|
+
protected _readyState: WalletReadyState =
|
71
|
+
typeof window === 'undefined' || typeof document === 'undefined'
|
72
|
+
? WalletReadyState.Unsupported
|
73
|
+
: WalletReadyState.NotDetected;
|
74
|
+
|
75
|
+
protected _connecting: boolean;
|
76
|
+
|
77
|
+
protected _wallet: HyperPayAccount | null;
|
78
|
+
|
79
|
+
constructor({
|
80
|
+
// provider,
|
81
|
+
// network = WalletAdapterNetwork.Mainnet,
|
82
|
+
timeout = 10000
|
83
|
+
}: HyperPayWalletAdapterConfig = {}) {
|
84
|
+
super();
|
85
|
+
|
86
|
+
this._provider = typeof window !== 'undefined' ? window.hyperpay : undefined;
|
87
|
+
// this._network = network;
|
88
|
+
this._timeout = timeout;
|
89
|
+
this._connecting = false;
|
90
|
+
this._wallet = null;
|
91
|
+
|
92
|
+
if (typeof window !== 'undefined' && this._readyState !== WalletReadyState.Unsupported) {
|
93
|
+
scopePollingDetectionStrategy(() => {
|
94
|
+
if (window.hyperpay) {
|
95
|
+
this._readyState = WalletReadyState.Installed;
|
96
|
+
this.emit('readyStateChange', this._readyState);
|
97
|
+
return true;
|
98
|
+
}
|
99
|
+
return false;
|
100
|
+
});
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
get publicAccount(): AccountKeys {
|
105
|
+
return {
|
106
|
+
publicKey: this._wallet?.publicKey || null,
|
107
|
+
address: this._wallet?.address || null,
|
108
|
+
authKey: this._wallet?.authKey || null
|
109
|
+
};
|
110
|
+
}
|
111
|
+
|
112
|
+
get connecting(): boolean {
|
113
|
+
return this._connecting;
|
114
|
+
}
|
115
|
+
|
116
|
+
get connected(): boolean {
|
117
|
+
return !!this._wallet?.isConnected;
|
118
|
+
}
|
119
|
+
|
120
|
+
get readyState(): WalletReadyState {
|
121
|
+
return this._readyState;
|
122
|
+
}
|
123
|
+
|
124
|
+
async connect(): Promise<void> {
|
125
|
+
try {
|
126
|
+
if (this.connected || this.connecting) return;
|
127
|
+
if (
|
128
|
+
!(
|
129
|
+
this._readyState === WalletReadyState.Loadable ||
|
130
|
+
this._readyState === WalletReadyState.Installed
|
131
|
+
)
|
132
|
+
)
|
133
|
+
throw new WalletNotReadyError();
|
134
|
+
this._connecting = true;
|
135
|
+
|
136
|
+
const provider = this._provider || window.hyperpay;
|
137
|
+
const isConnected = await provider?.isConnected();
|
138
|
+
if (isConnected) {
|
139
|
+
await provider?.disconnect();
|
140
|
+
}
|
141
|
+
const response = await provider?.connect();
|
142
|
+
|
143
|
+
if (!response) {
|
144
|
+
throw new WalletNotConnectedError('No connect response');
|
145
|
+
}
|
146
|
+
|
147
|
+
const walletAccount = await provider?.account();
|
148
|
+
if (walletAccount) {
|
149
|
+
this._wallet = {
|
150
|
+
...walletAccount,
|
151
|
+
isConnected: true
|
152
|
+
};
|
153
|
+
}
|
154
|
+
this.emit('connect', this._wallet?.address || '');
|
155
|
+
} catch (error: any) {
|
156
|
+
this.emit('error', new Error(error));
|
157
|
+
throw error;
|
158
|
+
} finally {
|
159
|
+
this._connecting = false;
|
160
|
+
}
|
161
|
+
}
|
162
|
+
|
163
|
+
async disconnect(): Promise<void> {
|
164
|
+
const wallet = this._wallet;
|
165
|
+
const provider = this._provider || window.hyperpay;
|
166
|
+
if (wallet) {
|
167
|
+
this._wallet = null;
|
168
|
+
|
169
|
+
try {
|
170
|
+
await provider?.disconnect();
|
171
|
+
} catch (error: any) {
|
172
|
+
this.emit('error', new WalletDisconnectionError(error?.message, error));
|
173
|
+
}
|
174
|
+
}
|
175
|
+
|
176
|
+
this.emit('disconnect');
|
177
|
+
}
|
178
|
+
|
179
|
+
async signTransaction(transactionPyld: TransactionPayload, options?: any): Promise<Uint8Array> {
|
180
|
+
try {
|
181
|
+
const wallet = this._wallet;
|
182
|
+
const provider = this._provider || window.hyperpay;
|
183
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
184
|
+
const tx = await provider.generateTransaction(wallet.address || '', transactionPyld, options);
|
185
|
+
if (!tx) throw new Error('Cannot generate transaction');
|
186
|
+
const response = await provider?.signTransaction(tx);
|
187
|
+
|
188
|
+
if (!response) {
|
189
|
+
throw new Error('No response');
|
190
|
+
}
|
191
|
+
return response;
|
192
|
+
} catch (error: any) {
|
193
|
+
this.emit('error', new WalletSignTransactionError(error));
|
194
|
+
throw error;
|
195
|
+
}
|
196
|
+
}
|
197
|
+
|
198
|
+
async signAndSubmitTransaction(
|
199
|
+
transactionPyld: TransactionPayload,
|
200
|
+
options?: any
|
201
|
+
): Promise<{ hash: HexEncodedBytes }> {
|
202
|
+
try {
|
203
|
+
const wallet = this._wallet;
|
204
|
+
const provider = this._provider || window.hyperpay;
|
205
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
206
|
+
const tx = await provider.generateTransaction(wallet.address || '', transactionPyld, options);
|
207
|
+
if (!tx) throw new Error('Cannot generate transaction');
|
208
|
+
const response = await provider?.signAndSubmitTransaction(tx);
|
209
|
+
|
210
|
+
if (!response) {
|
211
|
+
throw new Error('No response');
|
212
|
+
}
|
213
|
+
return { hash: response };
|
214
|
+
} catch (error: any) {
|
215
|
+
this.emit('error', new WalletSignAndSubmitMessageError(error));
|
216
|
+
throw error;
|
217
|
+
}
|
218
|
+
}
|
219
|
+
|
220
|
+
async signMessage(message: string): Promise<string> {
|
221
|
+
try {
|
222
|
+
const wallet = this._wallet;
|
223
|
+
const provider = this._provider || window.hyperpay;
|
224
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
225
|
+
const response = await provider?.signMessage(message);
|
226
|
+
if (response?.signature) {
|
227
|
+
return response?.signature;
|
228
|
+
} else {
|
229
|
+
throw new Error('Sign Message failed');
|
230
|
+
}
|
231
|
+
} catch (error: any) {
|
232
|
+
const errMsg = error.message;
|
233
|
+
this.emit('error', new WalletSignMessageError(errMsg));
|
234
|
+
throw error;
|
235
|
+
}
|
236
|
+
}
|
237
|
+
}
|
@@ -53,7 +53,8 @@ export interface AptosWalletAdapterConfig {
|
|
53
53
|
export class AptosWalletAdapter extends BaseWalletAdapter {
|
54
54
|
name = AptosWalletName;
|
55
55
|
|
56
|
-
url =
|
56
|
+
url =
|
57
|
+
'https://chrome.google.com/webstore/detail/petra-aptos-wallet/ejjladinnckdgjemekebdpeokbikhfci';
|
57
58
|
|
58
59
|
icon = 'https://miro.medium.com/fit/c/176/176/1*Gf747eyRywU8Img0tK5wvw.png';
|
59
60
|
|
@@ -12,6 +12,8 @@ import {
|
|
12
12
|
AccountKeys,
|
13
13
|
BaseWalletAdapter,
|
14
14
|
scopePollingDetectionStrategy,
|
15
|
+
SignMessagePayload,
|
16
|
+
SignMessageResponse,
|
15
17
|
WalletName,
|
16
18
|
WalletReadyState
|
17
19
|
} from './BaseAdapter';
|
@@ -45,11 +47,9 @@ interface IPontemWallet {
|
|
45
47
|
}>;
|
46
48
|
isConnected(): Promise<boolean>;
|
47
49
|
signTransaction(transaction: TransactionPayload, options?: any): Promise<Uint8Array>;
|
48
|
-
signMessage(message:
|
50
|
+
signMessage(message: SignMessagePayload): Promise<{
|
49
51
|
success: boolean;
|
50
|
-
result:
|
51
|
-
hexString: HexEncodedBytes;
|
52
|
-
};
|
52
|
+
result: SignMessageResponse;
|
53
53
|
}>;
|
54
54
|
disconnect(): Promise<void>;
|
55
55
|
}
|
@@ -221,20 +221,19 @@ export class PontemWalletAdapter extends BaseWalletAdapter {
|
|
221
221
|
}
|
222
222
|
return { hash: response.result.hash };
|
223
223
|
} catch (error: any) {
|
224
|
-
this.emit('error', new WalletSignAndSubmitMessageError(error.
|
224
|
+
this.emit('error', new WalletSignAndSubmitMessageError(error.message));
|
225
225
|
throw error;
|
226
226
|
}
|
227
227
|
}
|
228
228
|
|
229
|
-
async signMessage(
|
229
|
+
async signMessage(messagePayload: SignMessagePayload): Promise<SignMessageResponse> {
|
230
230
|
try {
|
231
231
|
const wallet = this._wallet;
|
232
232
|
const provider = this._provider || window.pontem;
|
233
233
|
if (!wallet || !provider) throw new WalletNotConnectedError();
|
234
|
-
const response = await provider?.signMessage(
|
235
|
-
console.log('MEMEM>>>', response);
|
234
|
+
const response = await provider?.signMessage(messagePayload);
|
236
235
|
if (response.success) {
|
237
|
-
return response.result
|
236
|
+
return response.result;
|
238
237
|
} else {
|
239
238
|
throw new Error('Sign Message failed');
|
240
239
|
}
|
@@ -0,0 +1,238 @@
|
|
1
|
+
import { HexEncodedBytes, TransactionPayload } from 'aptos/src/generated';
|
2
|
+
import {
|
3
|
+
WalletDisconnectionError,
|
4
|
+
WalletNotConnectedError,
|
5
|
+
WalletNotReadyError,
|
6
|
+
WalletSignMessageError,
|
7
|
+
WalletSignTransactionError
|
8
|
+
} from '../WalletProviders';
|
9
|
+
import {
|
10
|
+
AccountKeys,
|
11
|
+
BaseWalletAdapter,
|
12
|
+
scopePollingDetectionStrategy,
|
13
|
+
SignMessagePayload,
|
14
|
+
SignMessageResponse,
|
15
|
+
WalletName,
|
16
|
+
WalletReadyState
|
17
|
+
} from './BaseAdapter';
|
18
|
+
import { MaybeHexString } from 'aptos';
|
19
|
+
|
20
|
+
interface RiseAccount {
|
21
|
+
address: MaybeHexString;
|
22
|
+
publicKey: MaybeHexString;
|
23
|
+
authKey: MaybeHexString;
|
24
|
+
isConnected: boolean;
|
25
|
+
}
|
26
|
+
|
27
|
+
interface IRiseWallet {
|
28
|
+
connect: () => Promise<{ address: string }>;
|
29
|
+
account(): Promise<RiseAccount>;
|
30
|
+
isConnected: () => Promise<boolean>;
|
31
|
+
signAndSubmitTransaction(transaction: any): Promise<{ hash: HexEncodedBytes }>;
|
32
|
+
signTransaction(transaction: any, options?: any): Promise<Uint8Array>;
|
33
|
+
signMessage(message: SignMessagePayload): Promise<SignMessageResponse>;
|
34
|
+
disconnect(): Promise<void>;
|
35
|
+
}
|
36
|
+
|
37
|
+
interface RiseWindow extends Window {
|
38
|
+
rise?: IRiseWallet;
|
39
|
+
}
|
40
|
+
|
41
|
+
declare const window: RiseWindow;
|
42
|
+
|
43
|
+
export const RiseWalletName = 'Rise Wallet' as WalletName<'Rise Wallet'>;
|
44
|
+
|
45
|
+
export interface RiseWalletAdapterConfig {
|
46
|
+
provider?: IRiseWallet;
|
47
|
+
// network?: WalletAdapterNetwork;
|
48
|
+
timeout?: number;
|
49
|
+
}
|
50
|
+
|
51
|
+
export class RiseWalletAdapter extends BaseWalletAdapter {
|
52
|
+
name = RiseWalletName;
|
53
|
+
|
54
|
+
url = 'https://chrome.google.com/webstore/detail/hbbgbephgojikajhfbomhlmmollphcad';
|
55
|
+
|
56
|
+
icon = 'https://static.risewallet.io/logo.png';
|
57
|
+
|
58
|
+
protected _provider: IRiseWallet | undefined;
|
59
|
+
|
60
|
+
// protected _network: WalletAdapterNetwork;
|
61
|
+
protected _timeout: number;
|
62
|
+
|
63
|
+
protected _readyState: WalletReadyState =
|
64
|
+
typeof window === 'undefined' || typeof document === 'undefined'
|
65
|
+
? WalletReadyState.Unsupported
|
66
|
+
: WalletReadyState.NotDetected;
|
67
|
+
|
68
|
+
protected _connecting: boolean;
|
69
|
+
|
70
|
+
protected _wallet: any | null;
|
71
|
+
|
72
|
+
constructor({
|
73
|
+
// provider,
|
74
|
+
// network = WalletAdapterNetwork.Mainnet,
|
75
|
+
timeout = 10000
|
76
|
+
}: RiseWalletAdapterConfig = {}) {
|
77
|
+
super();
|
78
|
+
|
79
|
+
this._provider = typeof window !== 'undefined' ? window.rise : undefined;
|
80
|
+
// this._network = network;
|
81
|
+
this._timeout = timeout;
|
82
|
+
this._connecting = false;
|
83
|
+
this._wallet = null;
|
84
|
+
|
85
|
+
if (typeof window !== 'undefined' && this._readyState !== WalletReadyState.Unsupported) {
|
86
|
+
scopePollingDetectionStrategy(() => {
|
87
|
+
if (window.rise) {
|
88
|
+
this._readyState = WalletReadyState.Installed;
|
89
|
+
this.emit('readyStateChange', this._readyState);
|
90
|
+
return true;
|
91
|
+
}
|
92
|
+
return false;
|
93
|
+
});
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
get publicAccount(): AccountKeys {
|
98
|
+
return {
|
99
|
+
publicKey: this._wallet?.publicKey || null,
|
100
|
+
address: this._wallet?.address || null,
|
101
|
+
authKey: this._wallet?.authKey || null
|
102
|
+
};
|
103
|
+
}
|
104
|
+
|
105
|
+
get connecting(): boolean {
|
106
|
+
return this._connecting;
|
107
|
+
}
|
108
|
+
|
109
|
+
get connected(): boolean {
|
110
|
+
return !!this._wallet?.isConnected;
|
111
|
+
}
|
112
|
+
|
113
|
+
get readyState(): WalletReadyState {
|
114
|
+
return this._readyState;
|
115
|
+
}
|
116
|
+
|
117
|
+
async connect(): Promise<void> {
|
118
|
+
try {
|
119
|
+
if (this.connected || this.connecting) return;
|
120
|
+
if (
|
121
|
+
!(
|
122
|
+
this._readyState === WalletReadyState.Loadable ||
|
123
|
+
this._readyState === WalletReadyState.Installed
|
124
|
+
)
|
125
|
+
)
|
126
|
+
throw new WalletNotReadyError();
|
127
|
+
this._connecting = true;
|
128
|
+
|
129
|
+
const provider = this._provider || window.rise;
|
130
|
+
const isConnected = await this._provider?.isConnected();
|
131
|
+
if (isConnected === true) {
|
132
|
+
await provider?.disconnect();
|
133
|
+
}
|
134
|
+
|
135
|
+
const response = await provider?.connect();
|
136
|
+
|
137
|
+
if (!response) {
|
138
|
+
throw new WalletNotConnectedError('User has rejected the request');
|
139
|
+
}
|
140
|
+
|
141
|
+
const account = await provider?.account();
|
142
|
+
if (account) {
|
143
|
+
const { publicKey, address, authKey } = account;
|
144
|
+
|
145
|
+
this._wallet = {
|
146
|
+
publicKey,
|
147
|
+
address,
|
148
|
+
authKey,
|
149
|
+
isConnected: true
|
150
|
+
};
|
151
|
+
|
152
|
+
this.emit('connect', this._wallet.publicKey);
|
153
|
+
}
|
154
|
+
} catch (error: any) {
|
155
|
+
this.emit('error', error);
|
156
|
+
throw error;
|
157
|
+
} finally {
|
158
|
+
this._connecting = false;
|
159
|
+
}
|
160
|
+
}
|
161
|
+
|
162
|
+
async disconnect(): Promise<void> {
|
163
|
+
const wallet = this._wallet;
|
164
|
+
if (wallet) {
|
165
|
+
this._wallet = null;
|
166
|
+
|
167
|
+
try {
|
168
|
+
const provider = this._provider || window.rise;
|
169
|
+
await provider?.disconnect();
|
170
|
+
} catch (error: any) {
|
171
|
+
this.emit('error', new WalletDisconnectionError(error?.message, error));
|
172
|
+
}
|
173
|
+
}
|
174
|
+
|
175
|
+
this.emit('disconnect');
|
176
|
+
}
|
177
|
+
|
178
|
+
async signTransaction(transaction: TransactionPayload): Promise<Uint8Array> {
|
179
|
+
try {
|
180
|
+
const wallet = this._wallet;
|
181
|
+
const provider = this._provider || window.rise;
|
182
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
183
|
+
|
184
|
+
const response = await provider?.signTransaction(transaction);
|
185
|
+
if (response) {
|
186
|
+
return response;
|
187
|
+
} else {
|
188
|
+
throw new Error('Sign Transaction failed');
|
189
|
+
}
|
190
|
+
} catch (error: any) {
|
191
|
+
const errMsg = error.message;
|
192
|
+
this.emit('error', new WalletSignTransactionError(errMsg));
|
193
|
+
throw error;
|
194
|
+
}
|
195
|
+
}
|
196
|
+
|
197
|
+
async signAndSubmitTransaction(
|
198
|
+
transaction: TransactionPayload
|
199
|
+
): Promise<{ hash: HexEncodedBytes }> {
|
200
|
+
try {
|
201
|
+
const wallet = this._wallet;
|
202
|
+
const provider = this._provider || window.rise;
|
203
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
204
|
+
|
205
|
+
const response = await provider?.signAndSubmitTransaction(transaction);
|
206
|
+
if (response) {
|
207
|
+
return response;
|
208
|
+
} else {
|
209
|
+
throw new Error('Transaction failed');
|
210
|
+
}
|
211
|
+
} catch (error: any) {
|
212
|
+
const errMsg = error.message;
|
213
|
+
this.emit('error', new WalletSignTransactionError(errMsg));
|
214
|
+
throw error;
|
215
|
+
}
|
216
|
+
}
|
217
|
+
|
218
|
+
async signMessage(msgPayload: SignMessagePayload): Promise<SignMessageResponse> {
|
219
|
+
try {
|
220
|
+
const wallet = this._wallet;
|
221
|
+
const provider = this._provider || window.rise;
|
222
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
223
|
+
if (typeof msgPayload !== 'object' || !msgPayload.nonce) {
|
224
|
+
throw new WalletSignMessageError('Invalid signMessage Payload');
|
225
|
+
}
|
226
|
+
const response = await provider?.signMessage(msgPayload);
|
227
|
+
if (response) {
|
228
|
+
return response;
|
229
|
+
} else {
|
230
|
+
throw new Error('Sign Message failed');
|
231
|
+
}
|
232
|
+
} catch (error: any) {
|
233
|
+
const errMsg = error.message;
|
234
|
+
this.emit('error', new WalletSignMessageError(errMsg));
|
235
|
+
throw error;
|
236
|
+
}
|
237
|
+
}
|
238
|
+
}
|
@@ -6,4 +6,8 @@ export * from './MartianWallet';
|
|
6
6
|
export * from './FewchaWallet';
|
7
7
|
export * from './PontemWallet';
|
8
8
|
// export * from './NightlyWallet';
|
9
|
+
export * from './RiseWallet';
|
9
10
|
export * from './SpikaWallet';
|
11
|
+
export * from './HyperPayWallet';
|
12
|
+
export * from './FletchWallet';
|
13
|
+
export * from './AptosSnap';
|
@@ -105,6 +105,7 @@ export const WalletProvider: FC<WalletProviderProps> = ({
|
|
105
105
|
useEffect(() => {
|
106
106
|
const selectedWallet = wallets.find((wAdapter) => wAdapter.adapter.name === name);
|
107
107
|
if (selectedWallet) {
|
108
|
+
console.log('selectedWallets', selectedWallet);
|
108
109
|
setState({
|
109
110
|
wallet: selectedWallet,
|
110
111
|
adapter: selectedWallet.adapter,
|
@@ -180,14 +181,20 @@ export const WalletProvider: FC<WalletProviderProps> = ({
|
|
180
181
|
|
181
182
|
// If autoConnect is enabled, try to connect when the adapter changes and is ready
|
182
183
|
useEffect(() => {
|
183
|
-
if (
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
184
|
+
if (isConnecting.current || connected || !autoConnect || !adapter) return;
|
185
|
+
|
186
|
+
// Handle wallet not installed in Auto-connect mode
|
187
|
+
if (!(readyState === WalletReadyState.Installed || readyState === WalletReadyState.Loadable)) {
|
188
|
+
// Clear the selected wallet
|
189
|
+
setName(null);
|
190
|
+
|
191
|
+
if (typeof window !== 'undefined') {
|
192
|
+
window.open(adapter.url, '_blank');
|
193
|
+
}
|
194
|
+
|
195
|
+
handleError(new WalletNotReadyError());
|
190
196
|
return;
|
197
|
+
}
|
191
198
|
|
192
199
|
(async function () {
|
193
200
|
isConnecting.current = true;
|