@aptos-labs/wallet-adapter-core 2.1.0 → 2.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/CHANGELOG.md +13 -0
- package/dist/index.d.ts +16 -3
- package/dist/index.js +51 -4
- package/dist/index.mjs +43 -3
- package/package.json +1 -1
- package/src/WalletCore.ts +23 -10
- package/src/index.ts +1 -0
- package/src/types.ts +1 -0
- package/src/utils/helpers.ts +26 -0
- package/src/utils/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @aptos-labs/wallet-adapter-core
|
|
2
2
|
|
|
3
|
+
## 2.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- bb1595e: Fix deeplink redirect
|
|
8
|
+
- 1605d28: Support ReadonlyArray of Wallets in AptosWalletAdapterProvider and WalletCore
|
|
9
|
+
|
|
10
|
+
## 2.2.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- 814939c: Add deeplink support
|
|
15
|
+
|
|
3
16
|
## 2.1.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -69,6 +69,9 @@ interface AdapterPluginProps<Name extends string = string> {
|
|
|
69
69
|
icon: `data:image/${"svg+xml" | "webp" | "png" | "gif"};base64,${string}`;
|
|
70
70
|
providerName?: string;
|
|
71
71
|
provider: any;
|
|
72
|
+
deeplinkProvider?: (data: {
|
|
73
|
+
url: string;
|
|
74
|
+
}) => string;
|
|
72
75
|
connect(): Promise<any>;
|
|
73
76
|
disconnect: () => Promise<any>;
|
|
74
77
|
network: () => Promise<any>;
|
|
@@ -119,7 +122,7 @@ declare class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
119
122
|
private _network;
|
|
120
123
|
private _connecting;
|
|
121
124
|
private _connected;
|
|
122
|
-
constructor(plugins: Wallet
|
|
125
|
+
constructor(plugins: ReadonlyArray<Wallet>);
|
|
123
126
|
private scopePollingDetectionStrategy;
|
|
124
127
|
private doesWalletExist;
|
|
125
128
|
private clearData;
|
|
@@ -128,7 +131,7 @@ declare class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
128
131
|
setAccount(account: AccountInfo | null): void;
|
|
129
132
|
setNetwork(network: NetworkInfo | null): void;
|
|
130
133
|
isConnected(): boolean;
|
|
131
|
-
get wallets(): Wallet
|
|
134
|
+
get wallets(): ReadonlyArray<Wallet>;
|
|
132
135
|
/**
|
|
133
136
|
* Getter for the current connected wallet
|
|
134
137
|
* @return wallet info
|
|
@@ -208,4 +211,14 @@ declare class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
208
211
|
signMessageAndVerify(message: SignMessagePayload): Promise<boolean>;
|
|
209
212
|
}
|
|
210
213
|
|
|
211
|
-
|
|
214
|
+
declare function scopePollingDetectionStrategy(detect: () => boolean): void;
|
|
215
|
+
|
|
216
|
+
declare function setLocalStorage(walletName: WalletName): void;
|
|
217
|
+
declare function removeLocalStorage(): void;
|
|
218
|
+
declare function getLocalStorage(): void;
|
|
219
|
+
|
|
220
|
+
declare function isMobile(): boolean;
|
|
221
|
+
declare function isInAppBrowser(): boolean;
|
|
222
|
+
declare function isRedirectable(): boolean;
|
|
223
|
+
|
|
224
|
+
export { AccountInfo, AdapterPlugin, AdapterPluginEvents, AdapterPluginProps, AptosWalletErrorResult, NetworkInfo, NetworkName, PluginProvider, SignMessagePayload, SignMessageResponse, Wallet, WalletCore, WalletCoreEvents, WalletInfo, WalletName, WalletReadyState, getLocalStorage, isInAppBrowser, isMobile, isRedirectable, removeLocalStorage, scopePollingDetectionStrategy, setLocalStorage };
|
package/dist/index.js
CHANGED
|
@@ -28,7 +28,14 @@ var src_exports = {};
|
|
|
28
28
|
__export(src_exports, {
|
|
29
29
|
NetworkName: () => NetworkName,
|
|
30
30
|
WalletCore: () => WalletCore,
|
|
31
|
-
WalletReadyState: () => WalletReadyState
|
|
31
|
+
WalletReadyState: () => WalletReadyState,
|
|
32
|
+
getLocalStorage: () => getLocalStorage,
|
|
33
|
+
isInAppBrowser: () => isInAppBrowser,
|
|
34
|
+
isMobile: () => isMobile,
|
|
35
|
+
isRedirectable: () => isRedirectable,
|
|
36
|
+
removeLocalStorage: () => removeLocalStorage,
|
|
37
|
+
scopePollingDetectionStrategy: () => scopePollingDetectionStrategy,
|
|
38
|
+
setLocalStorage: () => setLocalStorage
|
|
32
39
|
});
|
|
33
40
|
module.exports = __toCommonJS(src_exports);
|
|
34
41
|
|
|
@@ -183,6 +190,30 @@ function setLocalStorage(walletName) {
|
|
|
183
190
|
function removeLocalStorage() {
|
|
184
191
|
localStorage.removeItem(LOCAL_STORAGE_ITEM_KEY);
|
|
185
192
|
}
|
|
193
|
+
function getLocalStorage() {
|
|
194
|
+
localStorage.getItem(LOCAL_STORAGE_ITEM_KEY);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// src/utils/helpers.ts
|
|
198
|
+
function isMobile() {
|
|
199
|
+
return /Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Kindle|NetFront|Silk-Accelerated|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune/i.test(
|
|
200
|
+
navigator.userAgent
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
function isInAppBrowser() {
|
|
204
|
+
const isIphone = /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(
|
|
205
|
+
navigator.userAgent
|
|
206
|
+
);
|
|
207
|
+
const isAndroid = /(Android).*Version\/[\d.]+.*Chrome\/[^\s]+ Mobile/i.test(
|
|
208
|
+
navigator.userAgent
|
|
209
|
+
);
|
|
210
|
+
return isIphone || isAndroid;
|
|
211
|
+
}
|
|
212
|
+
function isRedirectable() {
|
|
213
|
+
if (!navigator)
|
|
214
|
+
return false;
|
|
215
|
+
return isMobile() && !isInAppBrowser();
|
|
216
|
+
}
|
|
186
217
|
|
|
187
218
|
// src/ans.ts
|
|
188
219
|
var ChainIdToAnsContractAddressMap = {
|
|
@@ -309,14 +340,23 @@ var WalletCore = class extends import_eventemitter3.default {
|
|
|
309
340
|
const selectedWallet = (_a = this._wallets) == null ? void 0 : _a.find(
|
|
310
341
|
(wallet) => wallet.name === walletName
|
|
311
342
|
);
|
|
312
|
-
if (!selectedWallet
|
|
343
|
+
if (!selectedWallet)
|
|
313
344
|
return;
|
|
314
|
-
}
|
|
315
345
|
if (this._connected) {
|
|
316
346
|
if (((_b = this.wallet) == null ? void 0 : _b.name) === walletName)
|
|
317
347
|
return;
|
|
318
348
|
await this.disconnect();
|
|
319
349
|
}
|
|
350
|
+
if (isRedirectable()) {
|
|
351
|
+
if (selectedWallet.deeplinkProvider) {
|
|
352
|
+
const url = encodeURIComponent(window.location.href);
|
|
353
|
+
const location = selectedWallet.deeplinkProvider({ url });
|
|
354
|
+
window.location.href = location;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
if (selectedWallet.readyState !== "Installed" /* Installed */ && selectedWallet.readyState !== "Loadable" /* Loadable */) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
320
360
|
this._connecting = true;
|
|
321
361
|
this.setWallet(selectedWallet);
|
|
322
362
|
const account = await selectedWallet.connect();
|
|
@@ -496,5 +536,12 @@ var WalletCore = class extends import_eventemitter3.default {
|
|
|
496
536
|
0 && (module.exports = {
|
|
497
537
|
NetworkName,
|
|
498
538
|
WalletCore,
|
|
499
|
-
WalletReadyState
|
|
539
|
+
WalletReadyState,
|
|
540
|
+
getLocalStorage,
|
|
541
|
+
isInAppBrowser,
|
|
542
|
+
isMobile,
|
|
543
|
+
isRedirectable,
|
|
544
|
+
removeLocalStorage,
|
|
545
|
+
scopePollingDetectionStrategy,
|
|
546
|
+
setLocalStorage
|
|
500
547
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -149,6 +149,30 @@ function setLocalStorage(walletName) {
|
|
|
149
149
|
function removeLocalStorage() {
|
|
150
150
|
localStorage.removeItem(LOCAL_STORAGE_ITEM_KEY);
|
|
151
151
|
}
|
|
152
|
+
function getLocalStorage() {
|
|
153
|
+
localStorage.getItem(LOCAL_STORAGE_ITEM_KEY);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// src/utils/helpers.ts
|
|
157
|
+
function isMobile() {
|
|
158
|
+
return /Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Kindle|NetFront|Silk-Accelerated|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune/i.test(
|
|
159
|
+
navigator.userAgent
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
function isInAppBrowser() {
|
|
163
|
+
const isIphone = /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(
|
|
164
|
+
navigator.userAgent
|
|
165
|
+
);
|
|
166
|
+
const isAndroid = /(Android).*Version\/[\d.]+.*Chrome\/[^\s]+ Mobile/i.test(
|
|
167
|
+
navigator.userAgent
|
|
168
|
+
);
|
|
169
|
+
return isIphone || isAndroid;
|
|
170
|
+
}
|
|
171
|
+
function isRedirectable() {
|
|
172
|
+
if (!navigator)
|
|
173
|
+
return false;
|
|
174
|
+
return isMobile() && !isInAppBrowser();
|
|
175
|
+
}
|
|
152
176
|
|
|
153
177
|
// src/ans.ts
|
|
154
178
|
var ChainIdToAnsContractAddressMap = {
|
|
@@ -275,14 +299,23 @@ var WalletCore = class extends EventEmitter {
|
|
|
275
299
|
const selectedWallet = (_a = this._wallets) == null ? void 0 : _a.find(
|
|
276
300
|
(wallet) => wallet.name === walletName
|
|
277
301
|
);
|
|
278
|
-
if (!selectedWallet
|
|
302
|
+
if (!selectedWallet)
|
|
279
303
|
return;
|
|
280
|
-
}
|
|
281
304
|
if (this._connected) {
|
|
282
305
|
if (((_b = this.wallet) == null ? void 0 : _b.name) === walletName)
|
|
283
306
|
return;
|
|
284
307
|
await this.disconnect();
|
|
285
308
|
}
|
|
309
|
+
if (isRedirectable()) {
|
|
310
|
+
if (selectedWallet.deeplinkProvider) {
|
|
311
|
+
const url = encodeURIComponent(window.location.href);
|
|
312
|
+
const location = selectedWallet.deeplinkProvider({ url });
|
|
313
|
+
window.location.href = location;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
if (selectedWallet.readyState !== "Installed" /* Installed */ && selectedWallet.readyState !== "Loadable" /* Loadable */) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
286
319
|
this._connecting = true;
|
|
287
320
|
this.setWallet(selectedWallet);
|
|
288
321
|
const account = await selectedWallet.connect();
|
|
@@ -461,5 +494,12 @@ var WalletCore = class extends EventEmitter {
|
|
|
461
494
|
export {
|
|
462
495
|
NetworkName,
|
|
463
496
|
WalletCore,
|
|
464
|
-
WalletReadyState
|
|
497
|
+
WalletReadyState,
|
|
498
|
+
getLocalStorage,
|
|
499
|
+
isInAppBrowser,
|
|
500
|
+
isMobile,
|
|
501
|
+
isRedirectable,
|
|
502
|
+
removeLocalStorage,
|
|
503
|
+
scopePollingDetectionStrategy,
|
|
504
|
+
setLocalStorage
|
|
465
505
|
};
|
package/package.json
CHANGED
package/src/WalletCore.ts
CHANGED
|
@@ -34,11 +34,12 @@ import {
|
|
|
34
34
|
removeLocalStorage,
|
|
35
35
|
setLocalStorage,
|
|
36
36
|
scopePollingDetectionStrategy,
|
|
37
|
+
isRedirectable,
|
|
37
38
|
} from "./utils";
|
|
38
39
|
import { getNameByAddress } from "./ans";
|
|
39
40
|
|
|
40
41
|
export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
41
|
-
private _wallets: Wallet
|
|
42
|
+
private _wallets: ReadonlyArray<Wallet> = [];
|
|
42
43
|
private _wallet: Wallet | null = null;
|
|
43
44
|
private _account: AccountInfo | null = null;
|
|
44
45
|
private _network: NetworkInfo | null = null;
|
|
@@ -46,7 +47,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
46
47
|
private _connecting: boolean = false;
|
|
47
48
|
private _connected: boolean = false;
|
|
48
49
|
|
|
49
|
-
constructor(plugins: Wallet
|
|
50
|
+
constructor(plugins: ReadonlyArray<Wallet>) {
|
|
50
51
|
super();
|
|
51
52
|
this._wallets = plugins;
|
|
52
53
|
this.scopePollingDetectionStrategy();
|
|
@@ -122,7 +123,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
122
123
|
return this._connected;
|
|
123
124
|
}
|
|
124
125
|
|
|
125
|
-
get wallets(): Wallet
|
|
126
|
+
get wallets(): ReadonlyArray<Wallet> {
|
|
126
127
|
return this._wallets;
|
|
127
128
|
}
|
|
128
129
|
|
|
@@ -186,13 +187,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
186
187
|
(wallet: Wallet) => wallet.name === walletName
|
|
187
188
|
);
|
|
188
189
|
|
|
189
|
-
if (
|
|
190
|
-
!selectedWallet ||
|
|
191
|
-
(selectedWallet.readyState !== WalletReadyState.Installed &&
|
|
192
|
-
selectedWallet.readyState !== WalletReadyState.Loadable)
|
|
193
|
-
) {
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
190
|
+
if (!selectedWallet) return;
|
|
196
191
|
|
|
197
192
|
if (this._connected) {
|
|
198
193
|
// if the selected wallet is already connected, we don't need to connect again
|
|
@@ -200,6 +195,24 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
200
195
|
|
|
201
196
|
await this.disconnect();
|
|
202
197
|
}
|
|
198
|
+
|
|
199
|
+
// check if we are in a redirectable view (i.e on mobile AND not in an in-app browser) and
|
|
200
|
+
// since wallet readyState can be NotDetected, we check it before the next check
|
|
201
|
+
if (isRedirectable()) {
|
|
202
|
+
// use wallet deep link
|
|
203
|
+
if (selectedWallet.deeplinkProvider) {
|
|
204
|
+
const url = encodeURIComponent(window.location.href);
|
|
205
|
+
const location = selectedWallet.deeplinkProvider({ url });
|
|
206
|
+
window.location.href = location;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (
|
|
210
|
+
selectedWallet.readyState !== WalletReadyState.Installed &&
|
|
211
|
+
selectedWallet.readyState !== WalletReadyState.Loadable
|
|
212
|
+
) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
|
|
203
216
|
this._connecting = true;
|
|
204
217
|
this.setWallet(selectedWallet);
|
|
205
218
|
const account = await selectedWallet.connect();
|
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -53,6 +53,7 @@ export interface AdapterPluginProps<Name extends string = string> {
|
|
|
53
53
|
icon: `data:image/${"svg+xml" | "webp" | "png" | "gif"};base64,${string}`;
|
|
54
54
|
providerName?: string;
|
|
55
55
|
provider: any;
|
|
56
|
+
deeplinkProvider?: (data: { url: string }) => string;
|
|
56
57
|
connect(): Promise<any>;
|
|
57
58
|
disconnect: () => Promise<any>;
|
|
58
59
|
network: () => Promise<any>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export function isMobile(): boolean {
|
|
2
|
+
return /Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Kindle|NetFront|Silk-Accelerated|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune/i.test(
|
|
3
|
+
navigator.userAgent
|
|
4
|
+
);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function isInAppBrowser(): boolean {
|
|
8
|
+
const isIphone = /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(
|
|
9
|
+
navigator.userAgent
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
const isAndroid = /(Android).*Version\/[\d.]+.*Chrome\/[^\s]+ Mobile/i.test(
|
|
13
|
+
navigator.userAgent
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
return isIphone || isAndroid;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function isRedirectable(): boolean {
|
|
20
|
+
// SSR: return false
|
|
21
|
+
if (!navigator) return false;
|
|
22
|
+
|
|
23
|
+
// if we are on mobile and NOT in a in-app browser we will redirect to a wallet app
|
|
24
|
+
|
|
25
|
+
return isMobile() && !isInAppBrowser();
|
|
26
|
+
}
|
package/src/utils/index.ts
CHANGED