@layerswap/wallets 1.7.0-next.1 → 2.0.0-next.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 +38 -33
- package/dist/esm/descriptors/bitcoin.js +34 -0
- package/dist/esm/descriptors/defineWalletDescriptor.js +17 -0
- package/dist/esm/descriptors/fuel.js +26 -0
- package/dist/esm/descriptors/imtblPassport.js +22 -0
- package/dist/esm/descriptors/paradex.js +32 -0
- package/dist/esm/descriptors/persistedSession.js +26 -0
- package/dist/esm/descriptors/starknet.js +32 -0
- package/dist/esm/descriptors/svm.js +39 -0
- package/dist/esm/descriptors/ton.js +29 -0
- package/dist/esm/descriptors/tron.js +24 -0
- package/dist/esm/eager/imtblPassport.js +8 -0
- package/dist/esm/index.js +57 -85
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/descriptors/bitcoin.d.ts +9 -0
- package/dist/types/descriptors/bitcoin.d.ts.map +1 -0
- package/dist/types/descriptors/defineWalletDescriptor.d.ts +26 -0
- package/dist/types/descriptors/defineWalletDescriptor.d.ts.map +1 -0
- package/dist/types/descriptors/fuel.d.ts +9 -0
- package/dist/types/descriptors/fuel.d.ts.map +1 -0
- package/dist/types/descriptors/imtblPassport.d.ts +12 -0
- package/dist/types/descriptors/imtblPassport.d.ts.map +1 -0
- package/dist/types/descriptors/paradex.d.ts +8 -0
- package/dist/types/descriptors/paradex.d.ts.map +1 -0
- package/dist/types/descriptors/persistedSession.d.ts +8 -0
- package/dist/types/descriptors/persistedSession.d.ts.map +1 -0
- package/dist/types/descriptors/starknet.d.ts +9 -0
- package/dist/types/descriptors/starknet.d.ts.map +1 -0
- package/dist/types/descriptors/svm.d.ts +11 -0
- package/dist/types/descriptors/svm.d.ts.map +1 -0
- package/dist/types/descriptors/ton.d.ts +11 -0
- package/dist/types/descriptors/ton.d.ts.map +1 -0
- package/dist/types/descriptors/tron.d.ts +10 -0
- package/dist/types/descriptors/tron.d.ts.map +1 -0
- package/dist/types/eager/imtblPassport.d.ts +3 -0
- package/dist/types/eager/imtblPassport.d.ts.map +1 -0
- package/dist/types/index.d.ts +28 -68
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +18 -12
package/README.md
CHANGED
|
@@ -47,16 +47,16 @@ export default function Page() {
|
|
|
47
47
|
}
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
Render the Layerswap Widget with the wallet providers you want to enable. Only the
|
|
50
|
+
Render the Layerswap Widget with the wallet providers you want to enable. Only EVM is wired eagerly; every other chain is a lazy descriptor whose SDK is dynamic-imported when the user first opens the connect modal, so it stays out of your entry chunk.
|
|
51
51
|
|
|
52
52
|
```tsx
|
|
53
53
|
import { LayerswapProvider, Swap } from "@layerswap/widget";
|
|
54
54
|
import {
|
|
55
55
|
createEVMProvider,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
createStarknetDescriptor,
|
|
57
|
+
createSVMDescriptor,
|
|
58
|
+
createTONDescriptor,
|
|
59
|
+
createTronDescriptor,
|
|
60
60
|
} from "@layerswap/wallets";
|
|
61
61
|
|
|
62
62
|
export default function Page() {
|
|
@@ -73,21 +73,15 @@ export default function Page() {
|
|
|
73
73
|
createEVMProvider({
|
|
74
74
|
walletConnectConfigs
|
|
75
75
|
}),
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}),
|
|
82
|
-
createTONProvider({
|
|
83
|
-
tonConfigs: {
|
|
84
|
-
tonApiKey: "your-ton-api-key",
|
|
85
|
-
manifestUrl: "https://your-app.com/tonconnect-manifest.json"
|
|
86
|
-
}
|
|
76
|
+
createStarknetDescriptor(),
|
|
77
|
+
createSVMDescriptor(walletConnectConfigs),
|
|
78
|
+
createTONDescriptor({
|
|
79
|
+
tonApiKey: "your-ton-api-key",
|
|
80
|
+
manifestUrl: "https://your-app.com/tonconnect-manifest.json"
|
|
87
81
|
}),
|
|
88
|
-
|
|
82
|
+
createTronDescriptor(),
|
|
89
83
|
];
|
|
90
|
-
|
|
84
|
+
|
|
91
85
|
return (
|
|
92
86
|
<LayerswapProvider walletProviders={walletProviders}>
|
|
93
87
|
<Swap />
|
|
@@ -98,21 +92,32 @@ export default function Page() {
|
|
|
98
92
|
|
|
99
93
|
## Usage by network
|
|
100
94
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
- EVM (Ethereum, L2s): `createEVMProvider()`
|
|
104
|
-
- Starknet: `
|
|
105
|
-
- Solana: `
|
|
106
|
-
- TON: `
|
|
107
|
-
- Tron: `
|
|
108
|
-
- Fuel: `
|
|
109
|
-
- Bitcoin: `
|
|
110
|
-
- Paradex: `
|
|
111
|
-
- Immutable Passport: `
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
95
|
+
Exported from the `@layerswap/wallets` root:
|
|
96
|
+
|
|
97
|
+
- EVM (Ethereum, L2s): `createEVMProvider()` — eager
|
|
98
|
+
- Starknet: `createStarknetDescriptor()`
|
|
99
|
+
- Solana: `createSVMDescriptor()`
|
|
100
|
+
- TON: `createTONDescriptor()`
|
|
101
|
+
- Tron: `createTronDescriptor()`
|
|
102
|
+
- Fuel: `createFuelDescriptor()`
|
|
103
|
+
- Bitcoin: `createBitcoinDescriptor()`
|
|
104
|
+
- Paradex: `createParadexDescriptor()`
|
|
105
|
+
- Immutable Passport: `createImmutablePassportDescriptor()`
|
|
106
|
+
|
|
107
|
+
You can mix and match any subset depending on your app needs. If you need the eager (non-descriptor) factory for a chain, import it directly from that chain's package, e.g. `import { createStarknetProvider } from "@layerswap/wallet-starknet"`.
|
|
108
|
+
|
|
109
|
+
### Eager Immutable Passport subpath
|
|
110
|
+
|
|
111
|
+
`createImmutablePassportProvider` and `imtblPassportLoginCallback` are intentionally not exported from the package root — a static root import would pull `@imtbl/sdk` (~993 KB Brotli) into every consumer's bundle. Import them from the dedicated subpath, and only from chunks that genuinely need them eagerly (e.g. an OAuth callback page):
|
|
112
|
+
|
|
113
|
+
```tsx
|
|
114
|
+
import {
|
|
115
|
+
createImmutablePassportProvider,
|
|
116
|
+
imtblPassportLoginCallback,
|
|
117
|
+
} from "@layerswap/wallets/eager/imtbl-passport";
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
For the common case, use the lazy descriptor via `getDefaultProviders({ immutablePassport })` or `createImmutablePassportDescriptor()` instead.
|
|
116
121
|
|
|
117
122
|
## Included packages
|
|
118
123
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { defineWalletDescriptor } from "./defineWalletDescriptor";
|
|
2
|
+
import { readStorageJson } from "./persistedSession";
|
|
3
|
+
const BITCOIN_NETWORKS = ['BITCOIN_MAINNET', 'BITCOIN_TESTNET'];
|
|
4
|
+
/**
|
|
5
|
+
* Tree-shake-safe stand-in for `createBitcoinProvider`. Defers `bitcoinjs-lib`,
|
|
6
|
+
* `@bigmi/client`, `bn.js`, and `tweetnacl` — combined ~280 KB parsed /
|
|
7
|
+
* ~88 KB gzip — out of the host's entry chunk.
|
|
8
|
+
*/
|
|
9
|
+
export function createBitcoinDescriptor(options) {
|
|
10
|
+
const supportedNetworks = options?.supportedNetworks ?? BITCOIN_NETWORKS;
|
|
11
|
+
return defineWalletDescriptor({
|
|
12
|
+
id: 'bitcoin',
|
|
13
|
+
name: 'Bitcoin',
|
|
14
|
+
autofillSupportedNetworks: supportedNetworks,
|
|
15
|
+
withdrawalSupportedNetworks: supportedNetworks,
|
|
16
|
+
asSourceSupportedNetworks: supportedNetworks,
|
|
17
|
+
// Mirrors the real provider's snapshot (BitcoinConnectionService.buildProvider):
|
|
18
|
+
// without it the pre-hydration stub counts Bitcoin as mobile-supported,
|
|
19
|
+
// flipping platform-gated state once the descriptor loads.
|
|
20
|
+
unsupportedPlatforms: ['mobile'],
|
|
21
|
+
// @bigmi/client's `<prefix>.recentConnectorId`. A MetaMask marker is
|
|
22
|
+
// not restorable (its reconnect opens a popup, so wallet-bitcoin's
|
|
23
|
+
// NON_SILENT_CONNECTOR_IDS excludes it from session restore); the id
|
|
24
|
+
// is inlined so this stub never imports the SDK.
|
|
25
|
+
hasPersistedSession: () => {
|
|
26
|
+
const recent = readStorageJson('bigmi.recentConnectorId');
|
|
27
|
+
return typeof recent === 'string' && recent !== 'io.metamask.bitcoin';
|
|
28
|
+
},
|
|
29
|
+
loadProvider: async () => {
|
|
30
|
+
const mod = await import('@layerswap/wallet-bitcoin');
|
|
31
|
+
return mod.createBitcoinProvider();
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identity helper that pins a default descriptor's `id` at the type level:
|
|
3
|
+
*
|
|
4
|
+
* 1. The id must be a member of the public `WalletProviderId` union in
|
|
5
|
+
* `@layerswap/widget-types` — the contract `walletProvidersConfig`'s
|
|
6
|
+
* `include`/`exclude` filters are typed against.
|
|
7
|
+
* 2. The provider returned by `loadProvider()` must declare the same literal
|
|
8
|
+
* id (chain packages type their factories as
|
|
9
|
+
* `WalletProvider & { id: typeof id }`), so the registry key cannot flip
|
|
10
|
+
* when a descriptor hydrates into its real provider.
|
|
11
|
+
*
|
|
12
|
+
* Either kind of drift is a compile error instead of a silently broken
|
|
13
|
+
* id-keyed lookup.
|
|
14
|
+
*/
|
|
15
|
+
export function defineWalletDescriptor(descriptor) {
|
|
16
|
+
return descriptor;
|
|
17
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defineWalletDescriptor } from "./defineWalletDescriptor";
|
|
2
|
+
import { hasStorageKey } from "./persistedSession";
|
|
3
|
+
const FUEL_NETWORKS = ['FUEL_MAINNET', 'FUEL_TESTNET', 'FUEL_DEVNET'];
|
|
4
|
+
/**
|
|
5
|
+
* Tree-shake-safe stand-in for `createFuelProvider`. Defers `@fuel-ts/*` +
|
|
6
|
+
* `@fuels/vm-asm` — ~373 KB parsed / ~116 KB gzip — out of the host's entry
|
|
7
|
+
* chunk.
|
|
8
|
+
*/
|
|
9
|
+
export function createFuelDescriptor(options) {
|
|
10
|
+
const supportedNetworks = options?.supportedNetworks ?? FUEL_NETWORKS;
|
|
11
|
+
return defineWalletDescriptor({
|
|
12
|
+
id: 'fuel',
|
|
13
|
+
name: 'Fuel',
|
|
14
|
+
autofillSupportedNetworks: supportedNetworks,
|
|
15
|
+
withdrawalSupportedNetworks: supportedNetworks,
|
|
16
|
+
asSourceSupportedNetworks: supportedNetworks,
|
|
17
|
+
// `Fuel.STORAGE_KEY` in @fuel-ts/account — written once a fuel
|
|
18
|
+
// connector was detected as installed, so hydration only triggers
|
|
19
|
+
// for users who actually have a Fuel-family extension.
|
|
20
|
+
hasPersistedSession: () => hasStorageKey('fuel-current-connector'),
|
|
21
|
+
loadProvider: async () => {
|
|
22
|
+
const mod = await import('@layerswap/wallet-fuel');
|
|
23
|
+
return mod.createFuelProvider();
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineWalletDescriptor } from "./defineWalletDescriptor";
|
|
2
|
+
/**
|
|
3
|
+
* Tree-shake-safe stand-in for `createImmutablePassportProvider`. The factory
|
|
4
|
+
* is small, but running it imports `ImtblPassportService`, whose `@imtbl/sdk`
|
|
5
|
+
* chunks (~993 KB) then load eagerly on `/` — so defer the factory call
|
|
6
|
+
* itself. `/imtblRedirect` is unaffected (it imports the real factory
|
|
7
|
+
* directly). Empty network arrays are intentional: Passport authenticates and
|
|
8
|
+
* delegates to the EVM provider, so it's a connector, never a route source.
|
|
9
|
+
*/
|
|
10
|
+
export function createImmutablePassportDescriptor(imtblPassportConfig) {
|
|
11
|
+
return defineWalletDescriptor({
|
|
12
|
+
id: 'imtblPassport',
|
|
13
|
+
name: 'Immutable Passport',
|
|
14
|
+
autofillSupportedNetworks: [],
|
|
15
|
+
withdrawalSupportedNetworks: [],
|
|
16
|
+
asSourceSupportedNetworks: [],
|
|
17
|
+
loadProvider: async () => {
|
|
18
|
+
const mod = await import('@layerswap/wallet-imtbl-passport');
|
|
19
|
+
return mod.createImmutablePassportProvider({ imtblPassportConfig });
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { defineWalletDescriptor } from "./defineWalletDescriptor";
|
|
2
|
+
import { readStorageJson } from "./persistedSession";
|
|
3
|
+
// Inlined — importing Paradex's runtime constants drags `starknet` (~884 KB
|
|
4
|
+
// parsed) into the host entry chunk. Keep in sync with the
|
|
5
|
+
// `ParadexMainnet`/`ParadexTestnet` entries in widget's `knownIds.ts`.
|
|
6
|
+
const PARADEX_NETWORKS = ['PARADEX_MAINNET', 'PARADEX_TESTNET'];
|
|
7
|
+
/**
|
|
8
|
+
* Tree-shake-safe stand-in for `createParadexProvider` — defers
|
|
9
|
+
* `@paradex/sdk` → `starknet` out of the host's entry chunk.
|
|
10
|
+
*/
|
|
11
|
+
export function createParadexDescriptor(options) {
|
|
12
|
+
const supportedNetworks = options?.supportedNetworks ?? PARADEX_NETWORKS;
|
|
13
|
+
return defineWalletDescriptor({
|
|
14
|
+
id: 'paradex',
|
|
15
|
+
name: 'Paradex',
|
|
16
|
+
autofillSupportedNetworks: supportedNetworks,
|
|
17
|
+
withdrawalSupportedNetworks: supportedNetworks,
|
|
18
|
+
asSourceSupportedNetworks: supportedNetworks,
|
|
19
|
+
hideFromList: true,
|
|
20
|
+
// Key presence isn't a session signal — any write to widget's
|
|
21
|
+
// walletStore creates `ls-paradex-accounts`, even with no accounts.
|
|
22
|
+
// Hydrate eagerly only when actual L1 → Paradex mappings exist.
|
|
23
|
+
hasPersistedSession: () => {
|
|
24
|
+
const persisted = readStorageJson('ls-paradex-accounts');
|
|
25
|
+
return Object.keys(persisted?.state?.paradexAccounts ?? {}).length > 0;
|
|
26
|
+
},
|
|
27
|
+
loadProvider: async () => {
|
|
28
|
+
const mod = await import('@layerswap/wallet-paradex');
|
|
29
|
+
return mod.createParadexProvider();
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Probe helpers for descriptor `hasPersistedSession`. Storage-key literals
|
|
3
|
+
* are inlined at each call site — importing an SDK's key constant would drag
|
|
4
|
+
* in the SDK that descriptors exist to defer.
|
|
5
|
+
*/
|
|
6
|
+
export function hasStorageKey(key) {
|
|
7
|
+
if (typeof window === 'undefined')
|
|
8
|
+
return false;
|
|
9
|
+
try {
|
|
10
|
+
return window.localStorage.getItem(key) !== null;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function readStorageJson(key) {
|
|
17
|
+
if (typeof window === 'undefined')
|
|
18
|
+
return undefined;
|
|
19
|
+
try {
|
|
20
|
+
const raw = window.localStorage.getItem(key);
|
|
21
|
+
return raw ? JSON.parse(raw) : undefined;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { defineWalletDescriptor } from "./defineWalletDescriptor";
|
|
2
|
+
import { readStorageJson } from "./persistedSession";
|
|
3
|
+
// Inlined — importing `KnownInternalNames` pulls a runtime barrel that
|
|
4
|
+
// defeats lazy-loading. Keep in sync with packages/wallets/adapters/starknet/src/constants.ts.
|
|
5
|
+
const STARKNET_NETWORKS = ['STARKNET_MAINNET', 'STARKNET_SEPOLIA', 'STARKNET_GOERLI'];
|
|
6
|
+
/**
|
|
7
|
+
* Tree-shake-safe stand-in for `createStarknetProvider` — defers
|
|
8
|
+
* `@layerswap/wallet-starknet` (`starknet`, starknetkit) out of the host's
|
|
9
|
+
* entry chunk.
|
|
10
|
+
*/
|
|
11
|
+
export function createStarknetDescriptor(options) {
|
|
12
|
+
const supportedNetworks = options?.supportedNetworks ?? STARKNET_NETWORKS;
|
|
13
|
+
return defineWalletDescriptor({
|
|
14
|
+
id: 'starknet',
|
|
15
|
+
name: 'Starknet',
|
|
16
|
+
autofillSupportedNetworks: supportedNetworks,
|
|
17
|
+
withdrawalSupportedNetworks: supportedNetworks,
|
|
18
|
+
asSourceSupportedNetworks: supportedNetworks,
|
|
19
|
+
// Key presence isn't a session signal — any write to wallet-starknet's
|
|
20
|
+
// store creates `ls-starknet-accounts`, even with empty state.
|
|
21
|
+
// Hydrate eagerly only when actual account state exists.
|
|
22
|
+
hasPersistedSession: () => {
|
|
23
|
+
const persisted = readStorageJson('ls-starknet-accounts');
|
|
24
|
+
const state = persisted?.state;
|
|
25
|
+
return !!state?.activeWalletAddress || Object.keys(state?.starknetAccounts ?? {}).length > 0;
|
|
26
|
+
},
|
|
27
|
+
loadProvider: async () => {
|
|
28
|
+
const mod = await import('@layerswap/wallet-starknet');
|
|
29
|
+
return mod.createStarknetProvider();
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { defineWalletDescriptor } from "./defineWalletDescriptor";
|
|
2
|
+
import { hasStorageKey } from "./persistedSession";
|
|
3
|
+
// SVM's runtime list is built dynamically from `NetworkType.Solana` networks
|
|
4
|
+
// in `SvmConnectionService` — for static gating we mirror the universe of
|
|
5
|
+
// Solana network ids from widget's `knownIds.ts`. Extras don't hurt the
|
|
6
|
+
// route filter (it intersects with the active networks list); missing entries
|
|
7
|
+
// would.
|
|
8
|
+
const SVM_NETWORKS = ['SOLANA_MAINNET', 'SOLANA_TESTNET', 'SOLANA_DEVNET'];
|
|
9
|
+
/**
|
|
10
|
+
* Tree-shake-safe stand-in for `createSVMProvider`. Defers the eager portion
|
|
11
|
+
* of `@solana/web3.js` (~142 KB parsed) and `@walletconnect` adapters dragged
|
|
12
|
+
* by `SolanaWalletConnectAdapter` (~138 KB parsed) out of the host's entry
|
|
13
|
+
* chunk.
|
|
14
|
+
*/
|
|
15
|
+
export function createSVMDescriptor(walletConnectConfigs, options) {
|
|
16
|
+
const supportedNetworks = options?.supportedNetworks ?? SVM_NETWORKS;
|
|
17
|
+
return defineWalletDescriptor({
|
|
18
|
+
id: 'solana',
|
|
19
|
+
name: 'Solana',
|
|
20
|
+
// Keep this descriptor's module graph type-only; loading the widget or
|
|
21
|
+
// Solana runtime here would defeat the lazy-provider boundary.
|
|
22
|
+
capabilities: {
|
|
23
|
+
walletConnectRegistry: {
|
|
24
|
+
networkTypes: ['solana'],
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
autofillSupportedNetworks: supportedNetworks,
|
|
28
|
+
withdrawalSupportedNetworks: supportedNetworks,
|
|
29
|
+
asSourceSupportedNetworks: supportedNetworks,
|
|
30
|
+
// `STORAGE_KEY` in wallet-svm's svmAdapterManager — persisted only
|
|
31
|
+
// after a selection actually connected, so it's a reliable
|
|
32
|
+
// restorable-session hint.
|
|
33
|
+
hasPersistedSession: () => hasStorageKey('walletAdapterPreviouslySelectedName'),
|
|
34
|
+
loadProvider: async () => {
|
|
35
|
+
const mod = await import('@layerswap/wallet-svm');
|
|
36
|
+
return mod.createSVMProvider({ walletConnectConfigs });
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { defineWalletDescriptor } from "./defineWalletDescriptor";
|
|
2
|
+
import { hasStorageKey } from "./persistedSession";
|
|
3
|
+
// Inlined — see notes in ./starknet.ts on why we don't import the chain
|
|
4
|
+
// package's constants (it would drag the SDK). Keep in sync with
|
|
5
|
+
// packages/wallets/adapters/ton/src/constants.ts and widget's `knownIds.ts`.
|
|
6
|
+
const TON_NETWORKS = ['TON_MAINNET', 'TON_TESTNET'];
|
|
7
|
+
/**
|
|
8
|
+
* Tree-shake-safe stand-in for `createTONProvider`. Defers `@tonconnect/sdk`
|
|
9
|
+
* + `@ton/*` (~404 KB parsed / 139 KB gzip on `apps/bridge`) out of the
|
|
10
|
+
* host's entry chunk. The TON wallet only appears when a tonConfigs is
|
|
11
|
+
* supplied, mirroring the previous conditional in `getDefaultProviders`.
|
|
12
|
+
*/
|
|
13
|
+
export function createTONDescriptor(tonConfigs, options) {
|
|
14
|
+
const supportedNetworks = options?.supportedNetworks ?? TON_NETWORKS;
|
|
15
|
+
return defineWalletDescriptor({
|
|
16
|
+
id: 'ton',
|
|
17
|
+
name: 'Ton',
|
|
18
|
+
autofillSupportedNetworks: supportedNetworks,
|
|
19
|
+
withdrawalSupportedNetworks: supportedNetworks,
|
|
20
|
+
asSourceSupportedNetworks: supportedNetworks,
|
|
21
|
+
// @tonconnect/sdk's connection storage key — holds both injected and
|
|
22
|
+
// http (bridge) sessions that restoreConnection() can resume.
|
|
23
|
+
hasPersistedSession: () => hasStorageKey('ton-connect-storage_bridge-connection'),
|
|
24
|
+
loadProvider: async () => {
|
|
25
|
+
const mod = await import('@layerswap/wallet-ton');
|
|
26
|
+
return mod.createTONProvider({ tonConfigs });
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { defineWalletDescriptor } from "./defineWalletDescriptor";
|
|
2
|
+
import { readStorageJson } from "./persistedSession";
|
|
3
|
+
const TRON_NETWORKS = ['TRON_MAINNET', 'TRON_TESTNET'];
|
|
4
|
+
/**
|
|
5
|
+
* Tree-shake-safe stand-in for `createTronProvider`. Defers `tronweb` +
|
|
6
|
+
* `validator` (a transitive 125 KB dep of tronweb) + `bignumber.js` +
|
|
7
|
+
* `google-protobuf` schemas — ~775 KB parsed / ~165 KB gzip — out of the
|
|
8
|
+
* host's entry chunk.
|
|
9
|
+
*/
|
|
10
|
+
export function createTronDescriptor(options) {
|
|
11
|
+
const supportedNetworks = options?.supportedNetworks ?? TRON_NETWORKS;
|
|
12
|
+
return defineWalletDescriptor({
|
|
13
|
+
id: 'tron',
|
|
14
|
+
name: 'Tron',
|
|
15
|
+
autofillSupportedNetworks: supportedNetworks,
|
|
16
|
+
withdrawalSupportedNetworks: supportedNetworks,
|
|
17
|
+
asSourceSupportedNetworks: supportedNetworks,
|
|
18
|
+
hasPersistedSession: () => typeof readStorageJson('tronAdapterName') === 'string',
|
|
19
|
+
loadProvider: async () => {
|
|
20
|
+
const mod = await import('@layerswap/wallet-tron');
|
|
21
|
+
return mod.createTronProvider();
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Eager re-exports of Immutable Passport. Importing this subpath pulls
|
|
2
|
+
// `@imtbl/sdk` (~993 KB Brotli) into your bundle eagerly — only do this
|
|
3
|
+
// from chunks that genuinely need it (e.g. the OAuth callback page).
|
|
4
|
+
//
|
|
5
|
+
// For the common case, use the lazy descriptor instead via
|
|
6
|
+
// `getDefaultProviders({ immutablePassport })` from the main entry of
|
|
7
|
+
// `@layerswap/wallets`.
|
|
8
|
+
export { createImmutablePassportProvider, imtblPassportLoginCallback, } from "@layerswap/wallet-imtbl-passport";
|
package/dist/esm/index.js
CHANGED
|
@@ -1,75 +1,44 @@
|
|
|
1
1
|
// Import all wallet provider factories and types
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
export {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
export { FuelProvider } from "@layerswap/wallet-fuel";
|
|
32
|
-
/**
|
|
33
|
-
* @deprecated Use createImmutablePassportProvider() instead. This export will be removed in a future version.
|
|
34
|
-
*/
|
|
35
|
-
export { ImtblPassportProvider } from "@layerswap/wallet-imtbl-passport";
|
|
36
|
-
/**
|
|
37
|
-
* @deprecated Use createParadexProvider() instead. This export will be removed in a future version.
|
|
38
|
-
*/
|
|
39
|
-
export { ParadexProvider } from "@layerswap/wallet-paradex";
|
|
40
|
-
/**
|
|
41
|
-
* @deprecated Use createStarknetProvider() instead. This export will be removed in a future version.
|
|
42
|
-
*/
|
|
43
|
-
export { StarknetProvider } from "@layerswap/wallet-starknet";
|
|
44
|
-
/**
|
|
45
|
-
* @deprecated Use createSVMProvider() instead. This export will be removed in a future version.
|
|
46
|
-
*/
|
|
47
|
-
export { SVMProvider } from "@layerswap/wallet-svm";
|
|
48
|
-
/**
|
|
49
|
-
* @deprecated Use createTONProvider() instead. This export will be removed in a future version.
|
|
50
|
-
*/
|
|
51
|
-
export { TONProvider } from "@layerswap/wallet-ton";
|
|
52
|
-
/**
|
|
53
|
-
* @deprecated Use createTronProvider() instead. This export will be removed in a future version.
|
|
54
|
-
*/
|
|
55
|
-
export { TronProvider } from "@layerswap/wallet-tron";
|
|
2
|
+
//
|
|
3
|
+
// IMPORTANT: only `createEVMProvider`, `createImmutablePassportProvider`, and
|
|
4
|
+
// `imtblPassportLoginCallback` are value-imported eagerly from the chain
|
|
5
|
+
// packages. Every other chain is wired via a descriptor (see
|
|
6
|
+
// ./descriptors/*) so the chain SDK stays out of the host's entry chunk
|
|
7
|
+
// until the user actually opens the connect modal. Direct consumers can
|
|
8
|
+
// still `import { create<X>Provider } from "@layerswap/wallet-<chain>"`
|
|
9
|
+
// themselves if they want the eager path.
|
|
10
|
+
import { createBitcoinDescriptor } from "./descriptors/bitcoin";
|
|
11
|
+
import { createEVMProvider } from "@layerswap/wallet-evm";
|
|
12
|
+
import { createFuelDescriptor } from "./descriptors/fuel";
|
|
13
|
+
import { createImmutablePassportDescriptor } from "./descriptors/imtblPassport";
|
|
14
|
+
import { createParadexDescriptor } from "./descriptors/paradex";
|
|
15
|
+
import { createStarknetDescriptor } from "./descriptors/starknet";
|
|
16
|
+
import { createSVMDescriptor } from "./descriptors/svm";
|
|
17
|
+
import { createTONDescriptor } from "./descriptors/ton";
|
|
18
|
+
import { createTronDescriptor } from "./descriptors/tron";
|
|
19
|
+
export { defineWalletDescriptor } from "./descriptors/defineWalletDescriptor";
|
|
20
|
+
export { createBitcoinDescriptor };
|
|
21
|
+
export { createEVMProvider };
|
|
22
|
+
export { createFuelDescriptor };
|
|
23
|
+
export { createImmutablePassportDescriptor };
|
|
24
|
+
// For eager `createImmutablePassportProvider` / `imtblPassportLoginCallback`
|
|
25
|
+
// see the dedicated subpath: `@layerswap/wallets/eager/imtbl-passport`.
|
|
26
|
+
export { createParadexDescriptor };
|
|
27
|
+
export { createStarknetDescriptor };
|
|
28
|
+
export { createSVMDescriptor };
|
|
29
|
+
export { createTONDescriptor };
|
|
30
|
+
export { createTronDescriptor };
|
|
56
31
|
/**
|
|
57
32
|
* Creates and returns a default configuration of all wallet providers.
|
|
58
33
|
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* - **Bitcoin, Fuel, Tron, Paradex, ImmutableX**: Always included (no configuration required)
|
|
66
|
-
* - **EVM**: Includes zkSync and Loopring modules by default
|
|
34
|
+
* Only EVM (and Immutable Passport, when configured) is wired eagerly. Every
|
|
35
|
+
* other chain ships as a `WalletProviderDescriptor` — the real SDK is
|
|
36
|
+
* dynamic-imported on first connect-modal open. This keeps starknet,
|
|
37
|
+
* @paradex/sdk, @ton/*, @tonconnect/sdk, @fuel-ts/*, @solana/web3.js,
|
|
38
|
+
* tronweb (+ its transitive `validator`/`bignumber.js`), bitcoinjs-lib,
|
|
39
|
+
* @bigmi, and the connector adapters out of the host's entry chunk.
|
|
67
40
|
*
|
|
68
41
|
* @param config - Configuration options for the wallet providers
|
|
69
|
-
* @param config.walletConnect - Optional WalletConnect configuration (projectId, name, description, url, icons)
|
|
70
|
-
* @param config.ton - Optional TON client configuration (tonApiKey, manifestUrl)
|
|
71
|
-
* @param config.immutablePassport - Optional Immutable Passport configuration (publishableKey, clientId, redirectUri, logoutRedirectUri)
|
|
72
|
-
*
|
|
73
42
|
* @returns Array of configured wallet providers ready to be passed to LayerswapProvider
|
|
74
43
|
*
|
|
75
44
|
* @example
|
|
@@ -103,28 +72,31 @@ export { TronProvider } from "@layerswap/wallet-tron";
|
|
|
103
72
|
export function getDefaultProviders(config = {}) {
|
|
104
73
|
const { walletConnect, ton, immutablePassport } = config;
|
|
105
74
|
const providers = [
|
|
106
|
-
// EVM
|
|
75
|
+
// EVM — eager (common case, kept on the initial bundle).
|
|
107
76
|
createEVMProvider({
|
|
108
77
|
walletConnectConfigs: walletConnect,
|
|
109
78
|
}),
|
|
110
|
-
// Starknet
|
|
111
|
-
|
|
112
|
-
// Fuel
|
|
113
|
-
|
|
114
|
-
// Paradex
|
|
115
|
-
|
|
116
|
-
// Bitcoin
|
|
117
|
-
|
|
118
|
-
// TON
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
//
|
|
127
|
-
|
|
79
|
+
// Starknet — lazy. Pulls starknet/starkware-crypto on connect.
|
|
80
|
+
createStarknetDescriptor(),
|
|
81
|
+
// Fuel — lazy. Pulls @fuel-ts/* + @fuels/vm-asm on connect.
|
|
82
|
+
createFuelDescriptor(),
|
|
83
|
+
// Paradex — lazy. Drags @paradex/sdk → starknet → starkware-crypto.
|
|
84
|
+
createParadexDescriptor(),
|
|
85
|
+
// Bitcoin — lazy. Pulls bitcoinjs-lib + @bigmi + bn.js + tweetnacl.
|
|
86
|
+
createBitcoinDescriptor(),
|
|
87
|
+
// TON — lazy and conditional (only included when tonConfigs supplied,
|
|
88
|
+
// matching the prior eager behaviour).
|
|
89
|
+
...(ton ? [createTONDescriptor(ton)] : []),
|
|
90
|
+
// SVM (Solana) — lazy. Pulls @solana/web3.js + SolanaWalletConnectAdapter.
|
|
91
|
+
createSVMDescriptor(walletConnect),
|
|
92
|
+
// Tron — lazy. Pulls tronweb + its transitive validator/bignumber/protobuf.
|
|
93
|
+
createTronDescriptor(),
|
|
94
|
+
// Immutable Passport — lazy and conditional. The SDK + service
|
|
95
|
+
// init chain pulls ~993 KB Brotli; deferring it to first
|
|
96
|
+
// connect-modal open removes that from the home page waterfall.
|
|
97
|
+
// The OAuth redirect page (`/imtblRedirect`) imports the
|
|
98
|
+
// eager factory + login callback directly so it still works.
|
|
99
|
+
...(immutablePassport ? [createImmutablePassportDescriptor(immutablePassport)] : [])
|
|
128
100
|
];
|
|
129
101
|
return providers;
|
|
130
102
|
}
|