@aptos-labs/wallet-adapter-core 2.1.0 → 2.2.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 +6 -0
- package/dist/index.d.ts +14 -1
- package/dist/index.js +49 -2
- package/dist/index.mjs +41 -1
- package/package.json +1 -1
- package/src/WalletCore.ts +11 -0
- 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
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>;
|
|
@@ -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 = {
|
|
@@ -317,6 +348,15 @@ var WalletCore = class extends import_eventemitter3.default {
|
|
|
317
348
|
return;
|
|
318
349
|
await this.disconnect();
|
|
319
350
|
}
|
|
351
|
+
if (isRedirectable()) {
|
|
352
|
+
if (selectedWallet.deeplinkProvider) {
|
|
353
|
+
const url = encodeURIComponent(window.location.href);
|
|
354
|
+
const location = selectedWallet.deeplinkProvider({ url });
|
|
355
|
+
window.location.href = location;
|
|
356
|
+
} else {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
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 = {
|
|
@@ -283,6 +307,15 @@ var WalletCore = class extends EventEmitter {
|
|
|
283
307
|
return;
|
|
284
308
|
await this.disconnect();
|
|
285
309
|
}
|
|
310
|
+
if (isRedirectable()) {
|
|
311
|
+
if (selectedWallet.deeplinkProvider) {
|
|
312
|
+
const url = encodeURIComponent(window.location.href);
|
|
313
|
+
const location = selectedWallet.deeplinkProvider({ url });
|
|
314
|
+
window.location.href = location;
|
|
315
|
+
} else {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
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,6 +34,7 @@ import {
|
|
|
34
34
|
removeLocalStorage,
|
|
35
35
|
setLocalStorage,
|
|
36
36
|
scopePollingDetectionStrategy,
|
|
37
|
+
isRedirectable,
|
|
37
38
|
} from "./utils";
|
|
38
39
|
import { getNameByAddress } from "./ans";
|
|
39
40
|
|
|
@@ -200,6 +201,16 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
200
201
|
|
|
201
202
|
await this.disconnect();
|
|
202
203
|
}
|
|
204
|
+
if (isRedirectable()) {
|
|
205
|
+
// use wallet deep link
|
|
206
|
+
if (selectedWallet.deeplinkProvider) {
|
|
207
|
+
const url = encodeURIComponent(window.location.href);
|
|
208
|
+
const location = selectedWallet.deeplinkProvider({ url });
|
|
209
|
+
window.location.href = location;
|
|
210
|
+
} else {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
203
214
|
this._connecting = true;
|
|
204
215
|
this.setWallet(selectedWallet);
|
|
205
216
|
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