@reown/appkit-utils 1.6.6-rc.3.0 → 1.6.7-basic-test.7.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/dist/esm/package.json +2 -1
- package/dist/esm/src/MobileWallet.js +10 -22
- package/dist/esm/src/MobileWallet.js.map +1 -1
- package/dist/esm/tests/MobileWallet.test.js +6 -42
- package/dist/esm/tests/MobileWallet.test.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/types/src/MobileWallet.d.ts +3 -2
- package/package.json +6 -5
package/dist/esm/package.json
CHANGED
|
@@ -1,27 +1,15 @@
|
|
|
1
|
-
import { ConstantsUtil } from '@reown/appkit-common';
|
|
2
|
-
import { ChainController, ConnectorController, RouterController } from '@reown/appkit-core';
|
|
3
1
|
export const MobileWalletUtil = {
|
|
4
|
-
handleMobileWalletRedirection(
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const host = href.split('/')[2];
|
|
13
|
-
const encodedRef = encodeURIComponent(`${protocol}://${host}`);
|
|
14
|
-
window.location.href = `https://phantom.app/ul/browse/${encodedHref}?ref=${encodedRef}`;
|
|
15
|
-
}
|
|
16
|
-
if (name === 'Coinbase Wallet' && !('coinbaseSolana' in window)) {
|
|
17
|
-
window.location.href = `https://go.cb-w.com/dapp?cb_url=${encodedHref}`;
|
|
18
|
-
}
|
|
2
|
+
handleMobileWalletRedirection(properties) {
|
|
3
|
+
const href = window.location.href;
|
|
4
|
+
const encodedHref = encodeURIComponent(href);
|
|
5
|
+
if (properties?.name === 'Phantom' && !('phantom' in window)) {
|
|
6
|
+
const protocol = href.startsWith('https') ? 'https' : 'http';
|
|
7
|
+
const host = href.split('/')[2];
|
|
8
|
+
const encodedRef = encodeURIComponent(`${protocol}://${host}`);
|
|
9
|
+
window.location.href = `https://phantom.app/ul/browse/${encodedHref}?ref=${encodedRef}`;
|
|
19
10
|
}
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
RouterController.push('ConnectingWalletConnect', { wallet });
|
|
11
|
+
if (properties?.name === 'Coinbase Wallet' && !('coinbaseSolana' in window)) {
|
|
12
|
+
window.location.href = `https://go.cb-w.com/dapp?cb_url=${encodedHref}`;
|
|
25
13
|
}
|
|
26
14
|
}
|
|
27
15
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileWallet.js","sourceRoot":"","sources":["../../../src/MobileWallet.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"MobileWallet.js","sourceRoot":"","sources":["../../../src/MobileWallet.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAO9B,6BAA6B,CAAC,UAA4B;QACxD,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAA;QACjC,MAAM,WAAW,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAA;QAE5C,IAAI,UAAU,EAAE,IAAI,KAAK,SAAS,IAAI,CAAC,CAAC,SAAS,IAAI,MAAM,CAAC,EAAE,CAAC;YAC7D,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAA;YAC5D,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;YAC/B,MAAM,UAAU,GAAG,kBAAkB,CAAC,GAAG,QAAQ,MAAM,IAAI,EAAE,CAAC,CAAA;YAE9D,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,iCAAiC,WAAW,QAAQ,UAAU,EAAE,CAAA;QACzF,CAAC;QAED,IAAI,UAAU,EAAE,IAAI,KAAK,iBAAiB,IAAI,CAAC,CAAC,gBAAgB,IAAI,MAAM,CAAC,EAAE,CAAC;YAC5E,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,mCAAmC,WAAW,EAAE,CAAA;QACzE,CAAC;IACH,CAAC;CACF,CAAA"}
|
|
@@ -1,22 +1,11 @@
|
|
|
1
1
|
import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
import { MobileWalletUtil } from '../../core/src/utils/MobileWallet';
|
|
2
|
+
import { MobileWalletUtil } from '../src/MobileWallet';
|
|
4
3
|
const ORIGINAL_HREF = 'https://example.com/path';
|
|
5
4
|
const mockWindow = {
|
|
6
5
|
location: {
|
|
7
6
|
href: ORIGINAL_HREF
|
|
8
7
|
}
|
|
9
8
|
};
|
|
10
|
-
const WALLETS = {
|
|
11
|
-
phantom: {
|
|
12
|
-
name: 'Phantom',
|
|
13
|
-
id: 'phantom'
|
|
14
|
-
},
|
|
15
|
-
coinbase: {
|
|
16
|
-
name: 'Coinbase Wallet',
|
|
17
|
-
id: 'cbw'
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
9
|
describe('MobileWalletUtil', () => {
|
|
21
10
|
beforeEach(() => {
|
|
22
11
|
vi.stubGlobal('window', {
|
|
@@ -24,16 +13,13 @@ describe('MobileWalletUtil', () => {
|
|
|
24
13
|
href: ORIGINAL_HREF
|
|
25
14
|
}
|
|
26
15
|
});
|
|
27
|
-
vi.spyOn(ChainController, 'state', 'get').mockReturnValue({
|
|
28
|
-
activeChain: 'solana'
|
|
29
|
-
});
|
|
30
16
|
});
|
|
31
17
|
afterAll(() => {
|
|
32
18
|
vi.unstubAllGlobals();
|
|
33
19
|
});
|
|
34
20
|
describe('handleMobileWalletRedirection', () => {
|
|
35
21
|
it('should redirect to Phantom app when Phantom is not installed', () => {
|
|
36
|
-
MobileWalletUtil.handleMobileWalletRedirection(
|
|
22
|
+
MobileWalletUtil.handleMobileWalletRedirection({ name: 'Phantom' });
|
|
37
23
|
const encodedHref = encodeURIComponent(ORIGINAL_HREF);
|
|
38
24
|
const encodedRef = encodeURIComponent('https://example.com');
|
|
39
25
|
const expectedUrl = `https://phantom.app/ul/browse/${encodedHref}?ref=${encodedRef}`;
|
|
@@ -45,11 +31,11 @@ describe('MobileWalletUtil', () => {
|
|
|
45
31
|
phantom: {}
|
|
46
32
|
});
|
|
47
33
|
const originalHref = window.location.href;
|
|
48
|
-
MobileWalletUtil.handleMobileWalletRedirection(
|
|
34
|
+
MobileWalletUtil.handleMobileWalletRedirection({ name: 'Phantom' });
|
|
49
35
|
expect(window.location.href).toBe(originalHref);
|
|
50
36
|
});
|
|
51
37
|
it('should redirect to Coinbase Wallet when it is not installed', () => {
|
|
52
|
-
MobileWalletUtil.handleMobileWalletRedirection(
|
|
38
|
+
MobileWalletUtil.handleMobileWalletRedirection({ name: 'Coinbase Wallet' });
|
|
53
39
|
const encodedHref = encodeURIComponent(ORIGINAL_HREF);
|
|
54
40
|
const expectedUrl = `https://go.cb-w.com/dapp?cb_url=${encodedHref}`;
|
|
55
41
|
expect(window.location.href).toBe(expectedUrl);
|
|
@@ -60,36 +46,14 @@ describe('MobileWalletUtil', () => {
|
|
|
60
46
|
coinbaseSolana: {}
|
|
61
47
|
});
|
|
62
48
|
const originalHref = window.location.href;
|
|
63
|
-
MobileWalletUtil.handleMobileWalletRedirection(
|
|
49
|
+
MobileWalletUtil.handleMobileWalletRedirection({ name: 'Coinbase Wallet' });
|
|
64
50
|
expect(window.location.href).toBe(originalHref);
|
|
65
51
|
});
|
|
66
52
|
it('should not redirect for unknown wallet names', () => {
|
|
67
53
|
const originalHref = window.location.href;
|
|
68
|
-
MobileWalletUtil.handleMobileWalletRedirection({ name: 'Unknown
|
|
54
|
+
MobileWalletUtil.handleMobileWalletRedirection({ name: 'Unknown Wallet' });
|
|
69
55
|
expect(window.location.href).toBe(originalHref);
|
|
70
56
|
});
|
|
71
|
-
it('should route to ConnectingExternal if there is a connector', () => {
|
|
72
|
-
const mockConnector = {
|
|
73
|
-
id: 'connector',
|
|
74
|
-
name: 'Connector',
|
|
75
|
-
type: 'INJECTED',
|
|
76
|
-
chain: 'solana'
|
|
77
|
-
};
|
|
78
|
-
vi.spyOn(ConnectorController, 'getConnector').mockReturnValue(mockConnector);
|
|
79
|
-
vi.spyOn(RouterController, 'push');
|
|
80
|
-
MobileWalletUtil.handleMobileWalletRedirection({ name: 'Connector', id: 'connector' });
|
|
81
|
-
expect(RouterController.push).toHaveBeenCalledWith('ConnectingExternal', {
|
|
82
|
-
connector: mockConnector
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
it('should route to ConnectingWalletConnect if there is not a connector', () => {
|
|
86
|
-
vi.spyOn(ConnectorController, 'getConnector').mockReturnValue(undefined);
|
|
87
|
-
vi.spyOn(RouterController, 'push');
|
|
88
|
-
MobileWalletUtil.handleMobileWalletRedirection({ name: 'WalletConnect', id: 'wc' });
|
|
89
|
-
expect(RouterController.push).toHaveBeenCalledWith('ConnectingWalletConnect', {
|
|
90
|
-
wallet: { name: 'WalletConnect', id: 'wc' }
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
57
|
});
|
|
94
58
|
});
|
|
95
59
|
//# sourceMappingURL=MobileWallet.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileWallet.test.js","sourceRoot":"","sources":["../../../tests/MobileWallet.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAEvE,OAAO,
|
|
1
|
+
{"version":3,"file":"MobileWallet.test.js","sourceRoot":"","sources":["../../../tests/MobileWallet.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAEvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAEtD,MAAM,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