@dynamic-labs-sdk/client 1.31.2 → 1.32.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/{apiClient-d2qJyIvx.native.esm.js → apiClient-Bwd6cllS.native.esm.js} +2 -2
- package/dist/{apiClient-d2qJyIvx.native.esm.js.map → apiClient-Bwd6cllS.native.esm.js.map} +1 -1
- package/dist/core.cjs +6 -76
- package/dist/core.cjs.map +1 -1
- package/dist/core.esm.js +7 -77
- package/dist/core.esm.js.map +1 -1
- package/dist/core.native.esm.js +7 -77
- package/dist/core.native.esm.js.map +1 -1
- package/dist/errors/AmbiguousWalletChainError.d.ts +7 -9
- package/dist/errors/AmbiguousWalletChainError.d.ts.map +1 -1
- package/dist/errors/ConnectionUriHandlerMissingError.d.ts +10 -12
- package/dist/errors/ConnectionUriHandlerMissingError.d.ts.map +1 -1
- package/dist/errors/NoConnectionOptionAvailableError.d.ts +2 -2
- package/dist/errors/WalletBrowserRedirectHandlerMissingError.d.ts +39 -0
- package/dist/errors/WalletBrowserRedirectHandlerMissingError.d.ts.map +1 -0
- package/dist/errors/WalletOptionNotFoundError.d.ts +3 -3
- package/dist/exports/index.d.ts +5 -0
- package/dist/exports/index.d.ts.map +1 -1
- package/dist/{getNetworkProviderFromNetworkId-DueBnAl6.cjs → getNetworkProviderFromNetworkId-5UBZwUg2.cjs} +78 -2
- package/dist/getNetworkProviderFromNetworkId-5UBZwUg2.cjs.map +1 -0
- package/dist/{getNetworkProviderFromNetworkId-DF9kPibD.native.esm.js → getNetworkProviderFromNetworkId-DSsGkava.native.esm.js} +79 -9
- package/dist/getNetworkProviderFromNetworkId-DSsGkava.native.esm.js.map +1 -0
- package/dist/{getNetworkProviderFromNetworkId-D9nx6Od5.esm.js → getNetworkProviderFromNetworkId-TTqmAiJh.esm.js} +78 -8
- package/dist/getNetworkProviderFromNetworkId-TTqmAiJh.esm.js.map +1 -0
- package/dist/{getSignedSessionId-5q4uyZsv.native.esm.js → getSignedSessionId-BkYhH1zc.native.esm.js} +3 -3
- package/dist/{getSignedSessionId-5q4uyZsv.native.esm.js.map → getSignedSessionId-BkYhH1zc.native.esm.js.map} +1 -1
- package/dist/{getSignedSessionId-B5oxmSTs.cjs → getSignedSessionId-DBUnRGjt.cjs} +3 -3
- package/dist/{getSignedSessionId-B5oxmSTs.cjs.map → getSignedSessionId-DBUnRGjt.cjs.map} +1 -1
- package/dist/{getSignedSessionId-BKfQycNo.esm.js → getSignedSessionId-DeeDyino.esm.js} +3 -3
- package/dist/{getSignedSessionId-BKfQycNo.esm.js.map → getSignedSessionId-DeeDyino.esm.js.map} +1 -1
- package/dist/{getVerifiedCredentialForWalletAccount-Bx0HlvfW.cjs → getVerifiedCredentialForWalletAccount-BSxiaaVp.cjs} +2 -2
- package/dist/{getVerifiedCredentialForWalletAccount-Bx0HlvfW.cjs.map → getVerifiedCredentialForWalletAccount-BSxiaaVp.cjs.map} +1 -1
- package/dist/{getVerifiedCredentialForWalletAccount-_3MExyld.esm.js → getVerifiedCredentialForWalletAccount-C--Dza_K.esm.js} +2 -2
- package/dist/{getVerifiedCredentialForWalletAccount-_3MExyld.esm.js.map → getVerifiedCredentialForWalletAccount-C--Dza_K.esm.js.map} +1 -1
- package/dist/highLevelFunctions/connectWalletOption/connectWalletOption.d.ts +55 -0
- package/dist/highLevelFunctions/connectWalletOption/connectWalletOption.d.ts.map +1 -0
- package/dist/highLevelFunctions/connectWalletOption/connectWalletOption.types.d.ts +46 -0
- package/dist/highLevelFunctions/connectWalletOption/connectWalletOption.types.d.ts.map +1 -0
- package/dist/highLevelFunctions/connectWalletOption/index.d.ts +2 -0
- package/dist/highLevelFunctions/connectWalletOption/index.d.ts.map +1 -0
- package/dist/index.cjs +562 -188
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +562 -191
- package/dist/index.esm.js.map +1 -1
- package/dist/index.native.esm.js +562 -191
- package/dist/index.native.esm.js.map +1 -1
- package/dist/{isMfaRequiredForAction-DnKzPDZk.cjs → isMfaRequiredForAction-62zh3W-2.cjs} +2 -2
- package/dist/{isMfaRequiredForAction-DnKzPDZk.cjs.map → isMfaRequiredForAction-62zh3W-2.cjs.map} +1 -1
- package/dist/{isMfaRequiredForAction-BDmY2_Sj.esm.js → isMfaRequiredForAction-BPEXPqSt.esm.js} +2 -2
- package/dist/{isMfaRequiredForAction-BDmY2_Sj.esm.js.map → isMfaRequiredForAction-BPEXPqSt.esm.js.map} +1 -1
- package/dist/{isMfaRequiredForAction-BrRCSvEX.native.esm.js → isMfaRequiredForAction-DfrEFvU2.native.esm.js} +2 -2
- package/dist/{isMfaRequiredForAction-BrRCSvEX.native.esm.js.map → isMfaRequiredForAction-DfrEFvU2.native.esm.js.map} +1 -1
- package/dist/{isUserOnboardingComplete-BfMMBtkF.native.esm.js → isUserOnboardingComplete-BWrCHXXO.native.esm.js} +3 -3
- package/dist/{isUserOnboardingComplete-BfMMBtkF.native.esm.js.map → isUserOnboardingComplete-BWrCHXXO.native.esm.js.map} +1 -1
- package/dist/{isUserOnboardingComplete-D1-QluDm.esm.js → isUserOnboardingComplete-Dmck83_2.esm.js} +3 -3
- package/dist/{isUserOnboardingComplete-D1-QluDm.esm.js.map → isUserOnboardingComplete-Dmck83_2.esm.js.map} +1 -1
- package/dist/{isUserOnboardingComplete-7GzNYU2g.cjs → isUserOnboardingComplete-DtxIznZD.cjs} +3 -3
- package/dist/{isUserOnboardingComplete-7GzNYU2g.cjs.map → isUserOnboardingComplete-DtxIznZD.cjs.map} +1 -1
- package/dist/{logoutWithReason-3UICYir7.native.esm.js → logoutWithReason-DIc7cC6T.native.esm.js} +2 -2
- package/dist/{logoutWithReason-3UICYir7.native.esm.js.map → logoutWithReason-DIc7cC6T.native.esm.js.map} +1 -1
- package/dist/{logoutWithReason-CHyuBHdx.esm.js → logoutWithReason-x8mE7EAy.esm.js} +2 -2
- package/dist/{logoutWithReason-CHyuBHdx.esm.js.map → logoutWithReason-x8mE7EAy.esm.js.map} +1 -1
- package/dist/{logoutWithReason-C_T7KddM.cjs → logoutWithReason-yDqQ0UIt.cjs} +2 -2
- package/dist/{logoutWithReason-C_T7KddM.cjs.map → logoutWithReason-yDqQ0UIt.cjs.map} +1 -1
- package/dist/{migrateFromFireblocks-DJt9bktR.native.esm.js → migrateFromFireblocks-BUhWQCqm.native.esm.js} +2 -2
- package/dist/{migrateFromFireblocks-DJt9bktR.native.esm.js.map → migrateFromFireblocks-BUhWQCqm.native.esm.js.map} +1 -1
- package/dist/{migrateFromFireblocks-BMO3u6rO.esm.js → migrateFromFireblocks-BapjEhra.esm.js} +2 -2
- package/dist/{migrateFromFireblocks-BMO3u6rO.esm.js.map → migrateFromFireblocks-BapjEhra.esm.js.map} +1 -1
- package/dist/{migrateFromFireblocks-C9Kuke5V.cjs → migrateFromFireblocks-qYPrnWF8.cjs} +2 -2
- package/dist/{migrateFromFireblocks-C9Kuke5V.cjs.map → migrateFromFireblocks-qYPrnWF8.cjs.map} +1 -1
- package/dist/modules/wallets/connectWithUriConnectionOption/connectWithUriConnectionOption.d.ts +6 -5
- package/dist/modules/wallets/connectWithUriConnectionOption/connectWithUriConnectionOption.d.ts.map +1 -1
- package/dist/modules/wallets/redirectToInAppBrowser/redirectToInAppBrowser.d.ts +3 -3
- package/dist/modules/wallets/resolveWalletConnectionOption/resolveWalletConnectionOption.d.ts +2 -2
- package/dist/modules/wallets/walletConnectionHandlers.types.d.ts +62 -0
- package/dist/modules/wallets/walletConnectionHandlers.types.d.ts.map +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/utils/getCurrentPageUrl/getCurrentPageUrl.d.ts +15 -0
- package/dist/utils/getCurrentPageUrl/getCurrentPageUrl.d.ts.map +1 -0
- package/dist/utils/getCurrentPageUrl/index.d.ts +2 -0
- package/dist/utils/getCurrentPageUrl/index.d.ts.map +1 -0
- package/dist/{waas-9QajYGeK.native.esm.js → waas-CyUrvkQr.native.esm.js} +4 -4
- package/dist/{waas-9QajYGeK.native.esm.js.map → waas-CyUrvkQr.native.esm.js.map} +1 -1
- package/dist/{waas-T_dHXyI9.esm.js → waas-DzcYsWU8.esm.js} +4 -4
- package/dist/{waas-T_dHXyI9.esm.js.map → waas-DzcYsWU8.esm.js.map} +1 -1
- package/dist/{waas-Bxsd0-HG.cjs → waas-WID2Fy_N.cjs} +4 -4
- package/dist/{waas-Bxsd0-HG.cjs.map → waas-WID2Fy_N.cjs.map} +1 -1
- package/dist/waas.cjs +4 -4
- package/dist/waas.esm.js +4 -4
- package/dist/waas.native.esm.js +4 -4
- package/dist/waasCore.cjs +5 -5
- package/dist/waasCore.esm.js +5 -5
- package/dist/waasCore.native.esm.js +5 -5
- package/package.json +2 -2
- package/dist/getNetworkProviderFromNetworkId-D9nx6Od5.esm.js.map +0 -1
- package/dist/getNetworkProviderFromNetworkId-DF9kPibD.native.esm.js.map +0 -1
- package/dist/getNetworkProviderFromNetworkId-DueBnAl6.cjs.map +0 -1
- package/dist/modules/wallets/connectWallet.types.d.ts +0 -35
- package/dist/modules/wallets/connectWallet.types.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const require_logoutWithReason = require('./logoutWithReason-
|
|
2
|
-
const require_migrateFromFireblocks = require('./migrateFromFireblocks-
|
|
3
|
-
const require_waas = require('./waas-
|
|
4
|
-
const require_getNetworkProviderFromNetworkId = require('./getNetworkProviderFromNetworkId-
|
|
5
|
-
const require_getVerifiedCredentialForWalletAccount = require('./getVerifiedCredentialForWalletAccount-
|
|
6
|
-
const require_isUserOnboardingComplete = require('./isUserOnboardingComplete-
|
|
7
|
-
const require_isMfaRequiredForAction = require('./isMfaRequiredForAction-
|
|
1
|
+
const require_logoutWithReason = require('./logoutWithReason-yDqQ0UIt.cjs');
|
|
2
|
+
const require_migrateFromFireblocks = require('./migrateFromFireblocks-qYPrnWF8.cjs');
|
|
3
|
+
const require_waas = require('./waas-WID2Fy_N.cjs');
|
|
4
|
+
const require_getNetworkProviderFromNetworkId = require('./getNetworkProviderFromNetworkId-5UBZwUg2.cjs');
|
|
5
|
+
const require_getVerifiedCredentialForWalletAccount = require('./getVerifiedCredentialForWalletAccount-BSxiaaVp.cjs');
|
|
6
|
+
const require_isUserOnboardingComplete = require('./isUserOnboardingComplete-DtxIznZD.cjs');
|
|
7
|
+
const require_isMfaRequiredForAction = require('./isMfaRequiredForAction-62zh3W-2.cjs');
|
|
8
8
|
let _dynamic_labs_sdk_assert_package_version = require("@dynamic-labs-sdk/assert-package-version");
|
|
9
9
|
let _dynamic_labs_sdk_api_core = require("@dynamic-labs/sdk-api-core");
|
|
10
10
|
let zod_mini = require("zod/mini");
|
|
@@ -1208,7 +1208,7 @@ const __createDynamicClient_wrapped = require_logoutWithReason.instrumentFunctio
|
|
|
1208
1208
|
//#region src/errors/AmbiguousWalletChainError.ts
|
|
1209
1209
|
/**
|
|
1210
1210
|
* Thrown when a wallet can be connected on more than one of the client's
|
|
1211
|
-
* enabled chains and no chain was passed to `
|
|
1211
|
+
* enabled chains and no chain was passed to `connectWalletOption`.
|
|
1212
1212
|
*
|
|
1213
1213
|
* Multi-chain wallets such as MetaMask or Phantom connect to a different
|
|
1214
1214
|
* account per chain, so the chain has to be an explicit choice rather than one
|
|
@@ -1216,15 +1216,13 @@ const __createDynamicClient_wrapped = require_logoutWithReason.instrumentFunctio
|
|
|
1216
1216
|
*
|
|
1217
1217
|
* @example
|
|
1218
1218
|
* ```ts
|
|
1219
|
-
*
|
|
1220
|
-
*
|
|
1221
|
-
*
|
|
1222
|
-
*
|
|
1223
|
-
*
|
|
1224
|
-
* }
|
|
1225
|
-
* }
|
|
1219
|
+
* // Throws, since Phantom connects on both SOL and EVM
|
|
1220
|
+
* await connectWalletOption({ walletKey: 'phantom' });
|
|
1221
|
+
*
|
|
1222
|
+
* // Connects the wallet's Solana account
|
|
1223
|
+
* await connectWalletOption({ chain: 'SOL', walletKey: 'phantom' });
|
|
1226
1224
|
* ```
|
|
1227
|
-
* @see
|
|
1225
|
+
* @see connectWalletOption
|
|
1228
1226
|
* @see getWalletOptionsCatalogue
|
|
1229
1227
|
*/
|
|
1230
1228
|
var AmbiguousWalletChainError = class extends require_logoutWithReason.BaseError {
|
|
@@ -1402,6 +1400,48 @@ var CoinbaseTravelRuleRequiredError = class extends require_logoutWithReason.Bas
|
|
|
1402
1400
|
}
|
|
1403
1401
|
};
|
|
1404
1402
|
|
|
1403
|
+
//#endregion
|
|
1404
|
+
//#region src/errors/ConnectionUriHandlerMissingError.ts
|
|
1405
|
+
/**
|
|
1406
|
+
* Thrown when the only connection path for a wallet is a URI pairing and no
|
|
1407
|
+
* `onConnectionUri` handler was passed to `connectWalletOption`.
|
|
1408
|
+
*
|
|
1409
|
+
* The pairing URI has to reach the user — as a QR code on desktop, or by opening
|
|
1410
|
+
* the wallet's deeplink on mobile — for the wallet to be able to
|
|
1411
|
+
* approve the connection.
|
|
1412
|
+
*
|
|
1413
|
+
* @example
|
|
1414
|
+
* ```ts
|
|
1415
|
+
* // Throws, since the wallet can only be reached through a URI pairing
|
|
1416
|
+
* await connectWalletOption({ walletKey: 'trust' });
|
|
1417
|
+
*
|
|
1418
|
+
* // Connects, once the user approves the pairing
|
|
1419
|
+
* await connectWalletOption({
|
|
1420
|
+
* onConnectionUri: ({ uri }) => renderQrCode(uri),
|
|
1421
|
+
* walletKey: 'trust',
|
|
1422
|
+
* });
|
|
1423
|
+
* ```
|
|
1424
|
+
* @see connectWalletOption
|
|
1425
|
+
* @see ConnectionUriHandlerParams
|
|
1426
|
+
*/
|
|
1427
|
+
var ConnectionUriHandlerMissingError = class extends require_logoutWithReason.BaseError {
|
|
1428
|
+
constructor({ chain, type, walletKey }) {
|
|
1429
|
+
super({
|
|
1430
|
+
cause: null,
|
|
1431
|
+
code: "connection_uri_handler_missing",
|
|
1432
|
+
docsUrl: null,
|
|
1433
|
+
metaMessages: [
|
|
1434
|
+
`Wallet key: ${walletKey}`,
|
|
1435
|
+
`Chain: ${chain}`,
|
|
1436
|
+
`URI connection type: ${type}`,
|
|
1437
|
+
"Pass onConnectionUri to render the pairing URI it hands you as a QR code, or to open it as a link on mobile."
|
|
1438
|
+
],
|
|
1439
|
+
name: "ConnectionUriHandlerMissingError",
|
|
1440
|
+
shortMessage: `Connecting to ${walletKey} requires a URI pairing, so the onConnectionUri param is required.`
|
|
1441
|
+
});
|
|
1442
|
+
}
|
|
1443
|
+
};
|
|
1444
|
+
|
|
1405
1445
|
//#endregion
|
|
1406
1446
|
//#region src/errors/DeeplinkConnectAndVerifyUnsupportedError.ts
|
|
1407
1447
|
var DeeplinkConnectAndVerifyUnsupportedError = class extends require_logoutWithReason.BaseError {
|
|
@@ -1656,14 +1696,14 @@ var NoAddressFoundError = class extends require_logoutWithReason.BaseError {
|
|
|
1656
1696
|
* @example
|
|
1657
1697
|
* ```ts
|
|
1658
1698
|
* try {
|
|
1659
|
-
* await
|
|
1699
|
+
* await connectWalletOption({ walletKey: 'rainbow' });
|
|
1660
1700
|
* } catch (error) {
|
|
1661
1701
|
* if (error instanceof NoConnectionOptionAvailableError) {
|
|
1662
1702
|
* promptWalletInstall(error.installationUrls);
|
|
1663
1703
|
* }
|
|
1664
1704
|
* }
|
|
1665
1705
|
* ```
|
|
1666
|
-
* @see
|
|
1706
|
+
* @see connectWalletOption
|
|
1667
1707
|
* @see getWalletOptionsCatalogue
|
|
1668
1708
|
*/
|
|
1669
1709
|
var NoConnectionOptionAvailableError = class extends require_logoutWithReason.BaseError {
|
|
@@ -1885,10 +1925,57 @@ var WalletAccountNotSelectedError = class extends require_logoutWithReason.BaseE
|
|
|
1885
1925
|
}
|
|
1886
1926
|
};
|
|
1887
1927
|
|
|
1928
|
+
//#endregion
|
|
1929
|
+
//#region src/errors/WalletBrowserRedirectHandlerMissingError.ts
|
|
1930
|
+
/**
|
|
1931
|
+
* Thrown when the connection option resolved for a wallet is its in-app
|
|
1932
|
+
* browser, no `handleWalletBrowserRedirect` handler was passed to
|
|
1933
|
+
* `connectWalletOption`, and there is no current page URL to redirect into
|
|
1934
|
+
* that browser — as on React Native and during server-side rendering.
|
|
1935
|
+
*
|
|
1936
|
+
* That path connects by reloading your app inside the wallet's own browser,
|
|
1937
|
+
* so it needs the URL of the page to reload.
|
|
1938
|
+
*
|
|
1939
|
+
* @example
|
|
1940
|
+
* ```ts
|
|
1941
|
+
* // Throws on React Native, where there is no page URL to reuse
|
|
1942
|
+
* await connectWalletOption({ walletKey: 'coinbase' });
|
|
1943
|
+
*
|
|
1944
|
+
* // Connects, redirecting into the wallet's browser
|
|
1945
|
+
* await connectWalletOption({
|
|
1946
|
+
* handleWalletBrowserRedirect: ({ chain, walletKey }) =>
|
|
1947
|
+
* redirectToInAppBrowser({
|
|
1948
|
+
* appUrl: 'https://mydapp.xyz/login',
|
|
1949
|
+
* chain,
|
|
1950
|
+
* walletKey,
|
|
1951
|
+
* }),
|
|
1952
|
+
* walletKey: 'coinbase',
|
|
1953
|
+
* });
|
|
1954
|
+
* ```
|
|
1955
|
+
* @see connectWalletOption
|
|
1956
|
+
* @see redirectToInAppBrowser
|
|
1957
|
+
*/
|
|
1958
|
+
var WalletBrowserRedirectHandlerMissingError = class extends require_logoutWithReason.BaseError {
|
|
1959
|
+
constructor({ chain, walletKey }) {
|
|
1960
|
+
super({
|
|
1961
|
+
cause: null,
|
|
1962
|
+
code: "wallet_browser_redirect_handler_missing",
|
|
1963
|
+
docsUrl: null,
|
|
1964
|
+
metaMessages: [
|
|
1965
|
+
`Wallet key: ${walletKey}`,
|
|
1966
|
+
`Chain: ${chain}`,
|
|
1967
|
+
"Pass handleWalletBrowserRedirect and call redirectToInAppBrowser from it with the URL of the page to reload inside the wallet's browser."
|
|
1968
|
+
],
|
|
1969
|
+
name: "WalletBrowserRedirectHandlerMissingError",
|
|
1970
|
+
shortMessage: `Connecting to ${walletKey} requires opening its in-app browser, so the handleWalletBrowserRedirect param is required where there is no page URL to redirect.`
|
|
1971
|
+
});
|
|
1972
|
+
}
|
|
1973
|
+
};
|
|
1974
|
+
|
|
1888
1975
|
//#endregion
|
|
1889
1976
|
//#region src/errors/WalletOptionNotFoundError.ts
|
|
1890
1977
|
/**
|
|
1891
|
-
* Thrown when `
|
|
1978
|
+
* Thrown when `connectWalletOption` is given a wallet key that no wallet option in
|
|
1892
1979
|
* the catalogue matches.
|
|
1893
1980
|
*
|
|
1894
1981
|
* A wallet is only surfaced for the chains this client has an extension for, so
|
|
@@ -1898,14 +1985,14 @@ var WalletAccountNotSelectedError = class extends require_logoutWithReason.BaseE
|
|
|
1898
1985
|
* @example
|
|
1899
1986
|
* ```ts
|
|
1900
1987
|
* try {
|
|
1901
|
-
* await
|
|
1988
|
+
* await connectWalletOption({ walletKey: 'metmask' });
|
|
1902
1989
|
* } catch (error) {
|
|
1903
1990
|
* if (error instanceof WalletOptionNotFoundError) {
|
|
1904
1991
|
* showUnknownWalletMessage();
|
|
1905
1992
|
* }
|
|
1906
1993
|
* }
|
|
1907
1994
|
* ```
|
|
1908
|
-
* @see
|
|
1995
|
+
* @see connectWalletOption
|
|
1909
1996
|
* @see getWalletOptionsCatalogue
|
|
1910
1997
|
*/
|
|
1911
1998
|
var WalletOptionNotFoundError = class extends require_logoutWithReason.BaseError {
|
|
@@ -9075,6 +9162,457 @@ const __connectAndVerifyWithWalletProvider_wrapped = require_logoutWithReason.in
|
|
|
9075
9162
|
}
|
|
9076
9163
|
});
|
|
9077
9164
|
|
|
9165
|
+
//#endregion
|
|
9166
|
+
//#region src/utils/appendConnectionUriToDeeplink/appendConnectionUriToDeeplink.ts
|
|
9167
|
+
/**
|
|
9168
|
+
* Appends a wallet connection URI to a deeplink URL.
|
|
9169
|
+
*
|
|
9170
|
+
* Generic across URI-deeplink connection options — works for both
|
|
9171
|
+
* WalletConnect pairing URIs and MetaMask SDK URIs. Determines the
|
|
9172
|
+
* appropriate query parameter separator based on whether the deeplink
|
|
9173
|
+
* already contains query parameters.
|
|
9174
|
+
*
|
|
9175
|
+
* @param params.deeplinkUrl - The base deeplink URL (e.g., `walletapp://wc` or `walletapp://wc?param=value`).
|
|
9176
|
+
* @param params.connectionUri - The connection URI to append.
|
|
9177
|
+
* @returns The deeplink URL with the connection URI appended as a query parameter.
|
|
9178
|
+
*
|
|
9179
|
+
* @example
|
|
9180
|
+
* ```ts
|
|
9181
|
+
* appendConnectionUriToDeeplink({ deeplinkUrl: 'walletapp://wc', connectionUri: 'wc:123-456' })
|
|
9182
|
+
* // Returns: 'walletapp://wc?uri=wc%3A123-456'
|
|
9183
|
+
*
|
|
9184
|
+
* appendConnectionUriToDeeplink({ deeplinkUrl: 'walletapp://wc?param=value', connectionUri: 'wc:123-456' })
|
|
9185
|
+
* // Returns: 'walletapp://wc?param=value&uri=wc%3A123-456'
|
|
9186
|
+
* ```
|
|
9187
|
+
* @notInstrumented
|
|
9188
|
+
*/
|
|
9189
|
+
const appendConnectionUriToDeeplink = ({ connectionUri, deeplinkUrl }) => {
|
|
9190
|
+
const url = new URL(deeplinkUrl);
|
|
9191
|
+
url.searchParams.set("uri", connectionUri);
|
|
9192
|
+
return url.href;
|
|
9193
|
+
};
|
|
9194
|
+
|
|
9195
|
+
//#endregion
|
|
9196
|
+
//#region src/utils/getPreferredWalletDeepLink/getPreferredWalletDeepLink.ts
|
|
9197
|
+
/**
|
|
9198
|
+
* Picks the most appropriate deep link variant for the current platform.
|
|
9199
|
+
*
|
|
9200
|
+
* Mobile (Android, iOS, tablets) prefers `native` because the OS treats
|
|
9201
|
+
* custom URL schemes as first-class app links and gives the wallet a faster
|
|
9202
|
+
* round-trip back to the dApp. Desktop prefers `universal` because browsers
|
|
9203
|
+
* cannot resolve mobile-only custom schemes and need an `https://` link
|
|
9204
|
+
* that opens the wallet's web flow.
|
|
9205
|
+
*
|
|
9206
|
+
* In either case, the alternative is used as a fallback when the preferred
|
|
9207
|
+
* variant is missing. Returns `undefined` only when both variants are
|
|
9208
|
+
* absent.
|
|
9209
|
+
*
|
|
9210
|
+
* @example
|
|
9211
|
+
* ```ts
|
|
9212
|
+
* const deepLink = getPreferredWalletDeepLink({
|
|
9213
|
+
* deeplinks: wallet.deeplinks,
|
|
9214
|
+
* });
|
|
9215
|
+
* ```
|
|
9216
|
+
*
|
|
9217
|
+
* @param params.deeplinks - The deep link variants for a wallet (typically `WalletConnectCatalogWallet.deeplinks`).
|
|
9218
|
+
* @returns The preferred deep link URL, or `undefined` if neither variant is available.
|
|
9219
|
+
* @see appendConnectionUriToDeeplink
|
|
9220
|
+
* @see getConnectionUriDeeplink
|
|
9221
|
+
* @notInstrumented
|
|
9222
|
+
*/
|
|
9223
|
+
const getPreferredWalletDeepLink = ({ deeplinks }) => {
|
|
9224
|
+
const { native, universal } = deeplinks;
|
|
9225
|
+
if (isMobile()) return native ?? universal;
|
|
9226
|
+
return universal ?? native;
|
|
9227
|
+
};
|
|
9228
|
+
|
|
9229
|
+
//#endregion
|
|
9230
|
+
//#region src/modules/wallets/connectWithUriConnectionOption/getConnectionUriDeeplink/getConnectionUriDeeplink.ts
|
|
9231
|
+
/**
|
|
9232
|
+
* Builds the single deeplink that hands a pairing URI to the wallet, picking
|
|
9233
|
+
* the shape the URI's protocol expects.
|
|
9234
|
+
*
|
|
9235
|
+
* A WalletConnect URI travels as the `uri` query parameter of the wallet's own
|
|
9236
|
+
* deeplink, whereas the MetaMask SDK mints a launch link that already targets
|
|
9237
|
+
* MetaMask, so it is handed over untouched.
|
|
9238
|
+
*
|
|
9239
|
+
* @example
|
|
9240
|
+
* ```ts
|
|
9241
|
+
* const deeplink = getConnectionUriDeeplink({
|
|
9242
|
+
* deeplinks: connectionOption.deeplinks,
|
|
9243
|
+
* type: connectionOption.type,
|
|
9244
|
+
* uri,
|
|
9245
|
+
* });
|
|
9246
|
+
* ```
|
|
9247
|
+
*
|
|
9248
|
+
* @param params.deeplinks - The wallet's deeplink variants, as carried by the wallet book.
|
|
9249
|
+
* @param params.type - The URI connection type that minted the URI.
|
|
9250
|
+
* @param params.uri - The pairing URI.
|
|
9251
|
+
* @returns The deeplink to open, or `undefined` when the wallet publishes no deeplink to carry the URI.
|
|
9252
|
+
* @see getPreferredWalletDeepLink
|
|
9253
|
+
* @see appendConnectionUriToDeeplink
|
|
9254
|
+
* @notInstrumented
|
|
9255
|
+
*/
|
|
9256
|
+
const getConnectionUriDeeplink = ({ deeplinks, type, uri }) => {
|
|
9257
|
+
if (type === "metamaskSdkUri") return uri;
|
|
9258
|
+
const deeplinkUrl = getPreferredWalletDeepLink({ deeplinks });
|
|
9259
|
+
if (!deeplinkUrl) return;
|
|
9260
|
+
return appendConnectionUriToDeeplink({
|
|
9261
|
+
connectionUri: uri,
|
|
9262
|
+
deeplinkUrl
|
|
9263
|
+
});
|
|
9264
|
+
};
|
|
9265
|
+
|
|
9266
|
+
//#endregion
|
|
9267
|
+
//#region src/modules/wallets/connectWithUriConnectionOption/connectWithUriConnectionOption.ts
|
|
9268
|
+
/**
|
|
9269
|
+
* Connects to a wallet through a URI pairing and returns the connected wallet
|
|
9270
|
+
* account.
|
|
9271
|
+
*
|
|
9272
|
+
* Mints the pairing URI with the starter the chain extension registered for
|
|
9273
|
+
* the option's chain and URI type, hands it to `onConnectionUri` as the
|
|
9274
|
+
* wallet's deeplink carrying the pairing so the customer can render a QR code
|
|
9275
|
+
* or open the wallet app, then waits for the user to approve the pairing on
|
|
9276
|
+
* the wallet side.
|
|
9277
|
+
*
|
|
9278
|
+
* The handler is awaited, so an async handler that fails to open the wallet
|
|
9279
|
+
* rejects the connection rather than letting the pairing resolve into an
|
|
9280
|
+
* account nobody asked for.
|
|
9281
|
+
*
|
|
9282
|
+
* @example
|
|
9283
|
+
* ```ts
|
|
9284
|
+
* const walletAccount = await connectWithUriConnectionOption(
|
|
9285
|
+
* {
|
|
9286
|
+
* addToDynamicWalletAccounts: true,
|
|
9287
|
+
* connectionOption,
|
|
9288
|
+
* onConnectionUri: ({ uri }) => renderQrCode(uri),
|
|
9289
|
+
* walletKey: 'trust',
|
|
9290
|
+
* },
|
|
9291
|
+
* client
|
|
9292
|
+
* );
|
|
9293
|
+
* ```
|
|
9294
|
+
*
|
|
9295
|
+
* @param params.addToDynamicWalletAccounts - Whether the connected wallet account should be added to the client's wallet accounts.
|
|
9296
|
+
* @param params.connectionOption - The URI deeplink connection option to drive.
|
|
9297
|
+
* @param params.onConnectionUri - Called with the pairing URI once it is minted. Awaited before the approval is waited on.
|
|
9298
|
+
* @param params.walletKey - The wallet being connected, keyed as in the wallet options catalogue.
|
|
9299
|
+
* @param client - The Dynamic client instance.
|
|
9300
|
+
* @returns A promise that resolves to the connected wallet account.
|
|
9301
|
+
* @throws ConnectionUriHandlerMissingError If no onConnectionUri handler was passed.
|
|
9302
|
+
* @throws NoConnectionOptionAvailableError If no URI connection starter is registered for the option's chain and type.
|
|
9303
|
+
* @throws NoAddressFoundError If the pairing was approved but no address was shared with your app.
|
|
9304
|
+
* @see getUriConnectionStarterRegistry
|
|
9305
|
+
* @see getWalletOptionsCatalogue
|
|
9306
|
+
* @notInstrumented
|
|
9307
|
+
*/
|
|
9308
|
+
const connectWithUriConnectionOption = async ({ addToDynamicWalletAccounts, connectionOption, onConnectionUri, walletKey }, client) => {
|
|
9309
|
+
const { chain, deeplinks, type } = connectionOption;
|
|
9310
|
+
if (!onConnectionUri) throw new ConnectionUriHandlerMissingError({
|
|
9311
|
+
chain,
|
|
9312
|
+
type,
|
|
9313
|
+
walletKey
|
|
9314
|
+
});
|
|
9315
|
+
const starter = require_getNetworkProviderFromNetworkId.getUriConnectionStarterRegistry(client).get({
|
|
9316
|
+
chain,
|
|
9317
|
+
type
|
|
9318
|
+
});
|
|
9319
|
+
if (!starter) throw new NoConnectionOptionAvailableError({
|
|
9320
|
+
chain,
|
|
9321
|
+
walletKey
|
|
9322
|
+
});
|
|
9323
|
+
const { approval, uri } = await starter.start({ addToDynamicWalletAccounts });
|
|
9324
|
+
const walletAccountsPromise = approval();
|
|
9325
|
+
walletAccountsPromise.catch(() => void 0);
|
|
9326
|
+
await onConnectionUri({ uri: getConnectionUriDeeplink({
|
|
9327
|
+
deeplinks,
|
|
9328
|
+
type,
|
|
9329
|
+
uri
|
|
9330
|
+
}) ?? uri });
|
|
9331
|
+
const { walletAccounts } = await walletAccountsPromise;
|
|
9332
|
+
const [walletAccount] = walletAccounts;
|
|
9333
|
+
if (!walletAccount) throw new NoAddressFoundError();
|
|
9334
|
+
return walletAccount;
|
|
9335
|
+
};
|
|
9336
|
+
|
|
9337
|
+
//#endregion
|
|
9338
|
+
//#region src/utils/buildInAppBrowserUrl/buildInAppBrowserUrl.ts
|
|
9339
|
+
/**
|
|
9340
|
+
* Placeholder the wallet book leaves in in-app-browser URLs for the app URL
|
|
9341
|
+
* the wallet should open.
|
|
9342
|
+
*/
|
|
9343
|
+
const DAPP_URL_PLACEHOLDER = "{{encodedDappURI}}";
|
|
9344
|
+
/**
|
|
9345
|
+
* Fills a wallet's in-app-browser URL template with the app URL to open.
|
|
9346
|
+
*
|
|
9347
|
+
* Wallet book entries carry the entry point as a template (e.g.
|
|
9348
|
+
* `https://go.base.app/dapp?cb_url={{encodedDappURI}}`), so the URL is only
|
|
9349
|
+
* usable once every occurrence of the placeholder is substituted in,
|
|
9350
|
+
* percent-encoded. Templates without the placeholder are returned untouched —
|
|
9351
|
+
* some wallets open a fixed landing page.
|
|
9352
|
+
*
|
|
9353
|
+
* @example
|
|
9354
|
+
* ```ts
|
|
9355
|
+
* buildInAppBrowserUrl({
|
|
9356
|
+
* appUrl: 'https://myapp.xyz/login',
|
|
9357
|
+
* inAppBrowserUrl: 'https://go.base.app/dapp?cb_url={{encodedDappURI}}',
|
|
9358
|
+
* });
|
|
9359
|
+
* // Returns: 'https://go.base.app/dapp?cb_url=https%3A%2F%2Fmyapp.xyz%2Flogin'
|
|
9360
|
+
* ```
|
|
9361
|
+
*
|
|
9362
|
+
* @param params.appUrl - The URL of your app for the wallet's browser to open.
|
|
9363
|
+
* @param params.inAppBrowserUrl - The wallet's in-app-browser URL template.
|
|
9364
|
+
* @returns The in-app-browser URL to open.
|
|
9365
|
+
* @see redirectToInAppBrowser
|
|
9366
|
+
* @see getWalletOptionsCatalogue
|
|
9367
|
+
* @notInstrumented
|
|
9368
|
+
*/
|
|
9369
|
+
const buildInAppBrowserUrl = ({ appUrl, inAppBrowserUrl }) => inAppBrowserUrl.replaceAll(DAPP_URL_PLACEHOLDER, encodeURIComponent(appUrl));
|
|
9370
|
+
|
|
9371
|
+
//#endregion
|
|
9372
|
+
//#region src/modules/wallets/redirectToInAppBrowser/redirectToInAppBrowser.ts
|
|
9373
|
+
/**
|
|
9374
|
+
* Leaves your app for a wallet's in-app browser, which reloads `appUrl`
|
|
9375
|
+
* inside it.
|
|
9376
|
+
*
|
|
9377
|
+
* Call this from `handleWalletBrowserRedirect` with the URL of the page the
|
|
9378
|
+
* wallet should reload. The wallet's in-app-browser entry point is read from
|
|
9379
|
+
* the wallet options catalogue, so you only need the wallet's key. The wallet
|
|
9380
|
+
* is only injected on that reload, so the connection is made on the next page
|
|
9381
|
+
* load rather than in the current one.
|
|
9382
|
+
*
|
|
9383
|
+
* @example
|
|
9384
|
+
* ```ts
|
|
9385
|
+
* await connectWalletOption({
|
|
9386
|
+
* handleWalletBrowserRedirect: ({ chain, walletKey }) =>
|
|
9387
|
+
* redirectToInAppBrowser({ appUrl: window.location.href, chain, walletKey }),
|
|
9388
|
+
* walletKey: 'coinbase',
|
|
9389
|
+
* });
|
|
9390
|
+
* ```
|
|
9391
|
+
*
|
|
9392
|
+
* @param params.appUrl - The URL of your app for the wallet's browser to open.
|
|
9393
|
+
* @param params.walletKey - The wallet to open, keyed as in the wallet options catalogue.
|
|
9394
|
+
* @param [params.chain] - The chain to open the wallet's browser for. Required only when the wallet exposes an in-app browser on more than one enabled chain.
|
|
9395
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
9396
|
+
* @returns A promise that resolves once the redirect is triggered.
|
|
9397
|
+
* @throws WalletOptionNotFoundError If no wallet option matches the key.
|
|
9398
|
+
* @throws NoConnectionOptionAvailableError If the wallet exposes no in-app browser on the requested chain.
|
|
9399
|
+
* @throws AmbiguousWalletChainError If the wallet exposes an in-app browser on more than one chain and no chain was passed.
|
|
9400
|
+
* @throws UnsafeDeeplinkUrlError If the wallet's in-app-browser URL has a scheme that can execute script.
|
|
9401
|
+
* @see connectWalletOption
|
|
9402
|
+
* @see WalletBrowserRedirectHandlerParams
|
|
9403
|
+
* @instrumented
|
|
9404
|
+
*/
|
|
9405
|
+
const redirectToInAppBrowser = async ({ appUrl, chain, walletKey }, client = require_logoutWithReason.getDefaultClient()) => {
|
|
9406
|
+
const walletOption = (await getWalletOptionsCatalogue({ includeMobileOptions: true }, client)).find(({ key }) => key === walletKey);
|
|
9407
|
+
if (!walletOption) throw new WalletOptionNotFoundError({ walletKey });
|
|
9408
|
+
const inAppBrowserOptions = walletOption.connectionOptions.filter((option) => option.type === "inAppBrowser" && (!chain || option.chain === chain));
|
|
9409
|
+
if (inAppBrowserOptions.length === 0) throw new NoConnectionOptionAvailableError({
|
|
9410
|
+
chain,
|
|
9411
|
+
installationUrls: walletOption.installationUrls,
|
|
9412
|
+
walletKey
|
|
9413
|
+
});
|
|
9414
|
+
const availableChains = [...new Set(inAppBrowserOptions.map((option) => option.chain))];
|
|
9415
|
+
if (!chain && availableChains.length > 1) throw new AmbiguousWalletChainError({
|
|
9416
|
+
chains: availableChains,
|
|
9417
|
+
walletKey
|
|
9418
|
+
});
|
|
9419
|
+
const [inAppBrowserOption] = inAppBrowserOptions;
|
|
9420
|
+
const urlToOpen = buildInAppBrowserUrl({
|
|
9421
|
+
appUrl,
|
|
9422
|
+
inAppBrowserUrl: inAppBrowserOption.url
|
|
9423
|
+
});
|
|
9424
|
+
require_getNetworkProviderFromNetworkId.assertSafeDeeplinkUrl(urlToOpen);
|
|
9425
|
+
await require_logoutWithReason.getCore(client).openDeeplink(urlToOpen);
|
|
9426
|
+
};
|
|
9427
|
+
const __redirectToInAppBrowser_impl = redirectToInAppBrowser;
|
|
9428
|
+
const __redirectToInAppBrowser_wrapped = require_logoutWithReason.instrumentFunction({
|
|
9429
|
+
fn: __redirectToInAppBrowser_impl,
|
|
9430
|
+
functionName: "redirectToInAppBrowser",
|
|
9431
|
+
getCore: () => {
|
|
9432
|
+
try {
|
|
9433
|
+
return require_logoutWithReason.getCore(require_logoutWithReason.getDefaultClient());
|
|
9434
|
+
} catch {
|
|
9435
|
+
return;
|
|
9436
|
+
}
|
|
9437
|
+
}
|
|
9438
|
+
});
|
|
9439
|
+
|
|
9440
|
+
//#endregion
|
|
9441
|
+
//#region src/modules/wallets/resolveWalletConnectionOption/resolveWalletConnectionOption.ts
|
|
9442
|
+
/**
|
|
9443
|
+
* Picks the connection option `connectWalletOption` should drive for a wallet.
|
|
9444
|
+
*
|
|
9445
|
+
* Reads the wallet options catalogue, keeps the options this client can
|
|
9446
|
+
* actually drive — a registered wallet provider, an in-app-browser entry, or
|
|
9447
|
+
* a URI pairing whose starter a chain extension has registered — and returns
|
|
9448
|
+
* the best one by the catalogue's ordering.
|
|
9449
|
+
*
|
|
9450
|
+
* @example
|
|
9451
|
+
* ```ts
|
|
9452
|
+
* const connectionOption = await resolveWalletConnectionOption(
|
|
9453
|
+
* { walletKey: 'metamask' },
|
|
9454
|
+
* client
|
|
9455
|
+
* );
|
|
9456
|
+
* ```
|
|
9457
|
+
*
|
|
9458
|
+
* @param params.walletKey - The wallet to connect, keyed as in the wallet options catalogue.
|
|
9459
|
+
* @param [params.chain] - The chain to connect on. Required only when the wallet resolves on more than one enabled chain.
|
|
9460
|
+
* @param client - The Dynamic client instance.
|
|
9461
|
+
* @returns A promise that resolves to the connection option to drive.
|
|
9462
|
+
* @throws WalletOptionNotFoundError If no wallet option matches the key.
|
|
9463
|
+
* @throws AmbiguousWalletChainError If the wallet resolves on more than one chain and no chain was passed.
|
|
9464
|
+
* @throws NoConnectionOptionAvailableError If the wallet has no connection option this client can drive on the requested chain.
|
|
9465
|
+
* @see connectWalletOption
|
|
9466
|
+
* @see getWalletOptionsCatalogue
|
|
9467
|
+
* @notInstrumented
|
|
9468
|
+
*/
|
|
9469
|
+
const resolveWalletConnectionOption = async ({ walletKey, chain }, client) => {
|
|
9470
|
+
const walletOption = (await getWalletOptionsCatalogue({ includeMobileOptions: true }, client)).find(({ key }) => key === walletKey);
|
|
9471
|
+
if (!walletOption) throw new WalletOptionNotFoundError({ walletKey });
|
|
9472
|
+
const uriConnectionStarterRegistry = require_getNetworkProviderFromNetworkId.getUriConnectionStarterRegistry(client);
|
|
9473
|
+
const availableOptions = walletOption.connectionOptions.filter((option) => !chain || option.chain === chain).filter((option) => {
|
|
9474
|
+
if (option.type !== "walletConnect" && option.type !== "metamaskSdkUri") return true;
|
|
9475
|
+
const starter = uriConnectionStarterRegistry.get({
|
|
9476
|
+
chain: option.chain,
|
|
9477
|
+
type: option.type
|
|
9478
|
+
});
|
|
9479
|
+
return Boolean(starter);
|
|
9480
|
+
});
|
|
9481
|
+
if (availableOptions.length === 0) throw new NoConnectionOptionAvailableError({
|
|
9482
|
+
chain,
|
|
9483
|
+
installationUrls: walletOption.installationUrls,
|
|
9484
|
+
walletKey
|
|
9485
|
+
});
|
|
9486
|
+
const availableChains = [...new Set(availableOptions.map((option) => option.chain))];
|
|
9487
|
+
if (!chain && availableChains.length > 1) throw new AmbiguousWalletChainError({
|
|
9488
|
+
chains: availableChains,
|
|
9489
|
+
walletKey
|
|
9490
|
+
});
|
|
9491
|
+
const [connectionOption] = availableOptions;
|
|
9492
|
+
return connectionOption;
|
|
9493
|
+
};
|
|
9494
|
+
|
|
9495
|
+
//#endregion
|
|
9496
|
+
//#region src/utils/getCurrentPageUrl/getCurrentPageUrl.ts
|
|
9497
|
+
/**
|
|
9498
|
+
* Returns the URL of the page the app is running in.
|
|
9499
|
+
*
|
|
9500
|
+
* @example
|
|
9501
|
+
* ```ts
|
|
9502
|
+
* const appUrl = getCurrentPageUrl() ?? 'https://mydapp.xyz';
|
|
9503
|
+
* ```
|
|
9504
|
+
*
|
|
9505
|
+
* @returns The current page URL, or null where there is no page to read it from, such as on React Native and during server-side rendering.
|
|
9506
|
+
* @see isServerSideRendering
|
|
9507
|
+
* @see redirectToInAppBrowser
|
|
9508
|
+
* @notInstrumented
|
|
9509
|
+
*/
|
|
9510
|
+
const getCurrentPageUrl = () => {
|
|
9511
|
+
if (typeof window === "undefined") return null;
|
|
9512
|
+
const href = window.location?.href;
|
|
9513
|
+
if (typeof href !== "string") return null;
|
|
9514
|
+
return href;
|
|
9515
|
+
};
|
|
9516
|
+
|
|
9517
|
+
//#endregion
|
|
9518
|
+
//#region src/highLevelFunctions/connectWalletOption/connectWalletOption.ts
|
|
9519
|
+
/**
|
|
9520
|
+
* Connects to an external wallet by its wallet options catalogue key and
|
|
9521
|
+
* returns the connected wallet account.
|
|
9522
|
+
*
|
|
9523
|
+
* Picks the connection path for the wallet so the customer does not have to:
|
|
9524
|
+
* a registered wallet provider when the user has the wallet installed,
|
|
9525
|
+
* otherwise a URI pairing (WalletConnect or the MetaMask SDK), with the
|
|
9526
|
+
* pairing URI handed to `onConnectionUri` while the returned promise waits for
|
|
9527
|
+
* the user to approve on the wallet side.
|
|
9528
|
+
*
|
|
9529
|
+
* Wallets that can only be reached through their own in-app browser — no
|
|
9530
|
+
* extension, no URI pairing — resolve to a redirect instead: the wallet and
|
|
9531
|
+
* chain are handed to `handleWalletBrowserRedirect`, which leaves for that
|
|
9532
|
+
* browser with `redirectToInAppBrowser`. Without that handler, the current
|
|
9533
|
+
* page is redirected into the wallet's browser directly, so the handler is
|
|
9534
|
+
* only needed to pick a different page to come back to, or where there is no
|
|
9535
|
+
* page URL to reuse (React Native, server-side rendering). The returned
|
|
9536
|
+
* promise never settles either way, since the connection completes on the
|
|
9537
|
+
* next page load inside the wallet's browser.
|
|
9538
|
+
*
|
|
9539
|
+
* Note: This function does not verify the wallet account — use
|
|
9540
|
+
* `verifyWalletAccount` afterwards to link it to the user.
|
|
9541
|
+
*
|
|
9542
|
+
* @example
|
|
9543
|
+
* ```ts
|
|
9544
|
+
* const walletAccount = await connectWalletOption({
|
|
9545
|
+
* handleWalletBrowserRedirect: ({ chain, walletKey }) =>
|
|
9546
|
+
* redirectToInAppBrowser({ appUrl: 'https://mydapp.xyz', chain, walletKey }),
|
|
9547
|
+
* onConnectionUri: ({ uri }) => renderQrCode(uri),
|
|
9548
|
+
* walletKey: 'metamask',
|
|
9549
|
+
* });
|
|
9550
|
+
* console.log(walletAccount.address);
|
|
9551
|
+
* ```
|
|
9552
|
+
*
|
|
9553
|
+
* @param params.walletKey - The wallet to connect, keyed as in the wallet options catalogue (e.g. 'metamask', 'phantom').
|
|
9554
|
+
* @param [params.chain] - The chain to connect on. Required only when the wallet resolves on more than one enabled chain.
|
|
9555
|
+
* @param [params.onConnectionUri] - Called with the pairing URI when the connection runs through a URI pairing.
|
|
9556
|
+
* @param [params.handleWalletBrowserRedirect] - Called with the wallet and chain when the wallet can only be connected through its own in-app browser. Defaults to redirecting the current page into that browser.
|
|
9557
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
9558
|
+
* @returns A promise that resolves to the connected wallet account, or that never settles on the in-app-browser path.
|
|
9559
|
+
* @throws WalletOptionNotFoundError If no wallet option matches the key.
|
|
9560
|
+
* @throws AmbiguousWalletChainError If the wallet resolves on more than one chain and no chain was passed.
|
|
9561
|
+
* @throws NoConnectionOptionAvailableError If the wallet has no connection option this client can drive on the requested chain.
|
|
9562
|
+
* @throws ConnectionUriHandlerMissingError If the wallet resolves to a URI pairing and no onConnectionUri handler was passed.
|
|
9563
|
+
* @throws WalletBrowserRedirectHandlerMissingError If the wallet resolves to its in-app browser, no handleWalletBrowserRedirect handler was passed, and there is no current page URL to redirect.
|
|
9564
|
+
* @throws UnsafeDeeplinkUrlError If the wallet's in-app-browser URL has a scheme that can execute script.
|
|
9565
|
+
* @see verifyWalletAccount
|
|
9566
|
+
* @see redirectToInAppBrowser
|
|
9567
|
+
* @see getWalletOptionsCatalogue
|
|
9568
|
+
* @instrumented
|
|
9569
|
+
*/
|
|
9570
|
+
const connectWalletOption = async ({ walletKey, chain, handleWalletBrowserRedirect, onConnectionUri }, client = require_logoutWithReason.getDefaultClient()) => {
|
|
9571
|
+
const connectionOption = await resolveWalletConnectionOption({
|
|
9572
|
+
chain,
|
|
9573
|
+
walletKey
|
|
9574
|
+
}, client);
|
|
9575
|
+
if (connectionOption.type === "withWalletProvider") return __connectWithWalletProvider_wrapped({ walletProviderKey: connectionOption.walletProviderKey }, client);
|
|
9576
|
+
if (connectionOption.type === "inAppBrowser") {
|
|
9577
|
+
const { chain: inAppBrowserChain } = connectionOption;
|
|
9578
|
+
if (handleWalletBrowserRedirect) handleWalletBrowserRedirect({
|
|
9579
|
+
chain: inAppBrowserChain,
|
|
9580
|
+
walletKey
|
|
9581
|
+
});
|
|
9582
|
+
else {
|
|
9583
|
+
const currentPageUrl = getCurrentPageUrl();
|
|
9584
|
+
if (!currentPageUrl) throw new WalletBrowserRedirectHandlerMissingError({
|
|
9585
|
+
chain: inAppBrowserChain,
|
|
9586
|
+
walletKey
|
|
9587
|
+
});
|
|
9588
|
+
await __redirectToInAppBrowser_wrapped({
|
|
9589
|
+
appUrl: currentPageUrl,
|
|
9590
|
+
chain: inAppBrowserChain,
|
|
9591
|
+
walletKey
|
|
9592
|
+
}, client);
|
|
9593
|
+
}
|
|
9594
|
+
return new Promise(() => void 0);
|
|
9595
|
+
}
|
|
9596
|
+
return connectWithUriConnectionOption({
|
|
9597
|
+
addToDynamicWalletAccounts: true,
|
|
9598
|
+
connectionOption,
|
|
9599
|
+
onConnectionUri,
|
|
9600
|
+
walletKey
|
|
9601
|
+
}, client);
|
|
9602
|
+
};
|
|
9603
|
+
const __connectWalletOption_impl = connectWalletOption;
|
|
9604
|
+
const __connectWalletOption_wrapped = require_logoutWithReason.instrumentFunction({
|
|
9605
|
+
fn: __connectWalletOption_impl,
|
|
9606
|
+
functionName: "connectWalletOption",
|
|
9607
|
+
getCore: () => {
|
|
9608
|
+
try {
|
|
9609
|
+
return require_logoutWithReason.getCore(require_logoutWithReason.getDefaultClient());
|
|
9610
|
+
} catch {
|
|
9611
|
+
return;
|
|
9612
|
+
}
|
|
9613
|
+
}
|
|
9614
|
+
});
|
|
9615
|
+
|
|
9078
9616
|
//#endregion
|
|
9079
9617
|
//#region src/modules/wallets/getAvailableWalletProvidersData/getAvailableWalletProvidersData.ts
|
|
9080
9618
|
/**
|
|
@@ -9672,109 +10210,6 @@ const __selectPrimaryWalletAccount_wrapped = require_logoutWithReason.instrument
|
|
|
9672
10210
|
}
|
|
9673
10211
|
});
|
|
9674
10212
|
|
|
9675
|
-
//#endregion
|
|
9676
|
-
//#region src/utils/buildInAppBrowserUrl/buildInAppBrowserUrl.ts
|
|
9677
|
-
/**
|
|
9678
|
-
* Placeholder the wallet book leaves in in-app-browser URLs for the app URL
|
|
9679
|
-
* the wallet should open.
|
|
9680
|
-
*/
|
|
9681
|
-
const DAPP_URL_PLACEHOLDER = "{{encodedDappURI}}";
|
|
9682
|
-
/**
|
|
9683
|
-
* Fills a wallet's in-app-browser URL template with the app URL to open.
|
|
9684
|
-
*
|
|
9685
|
-
* Wallet book entries carry the entry point as a template (e.g.
|
|
9686
|
-
* `https://go.base.app/dapp?cb_url={{encodedDappURI}}`), so the URL is only
|
|
9687
|
-
* usable once every occurrence of the placeholder is substituted in,
|
|
9688
|
-
* percent-encoded. Templates without the placeholder are returned untouched —
|
|
9689
|
-
* some wallets open a fixed landing page.
|
|
9690
|
-
*
|
|
9691
|
-
* @example
|
|
9692
|
-
* ```ts
|
|
9693
|
-
* buildInAppBrowserUrl({
|
|
9694
|
-
* appUrl: 'https://myapp.xyz/login',
|
|
9695
|
-
* inAppBrowserUrl: 'https://go.base.app/dapp?cb_url={{encodedDappURI}}',
|
|
9696
|
-
* });
|
|
9697
|
-
* // Returns: 'https://go.base.app/dapp?cb_url=https%3A%2F%2Fmyapp.xyz%2Flogin'
|
|
9698
|
-
* ```
|
|
9699
|
-
*
|
|
9700
|
-
* @param params.appUrl - The URL of your app for the wallet's browser to open.
|
|
9701
|
-
* @param params.inAppBrowserUrl - The wallet's in-app-browser URL template.
|
|
9702
|
-
* @returns The in-app-browser URL to open.
|
|
9703
|
-
* @see redirectToInAppBrowser
|
|
9704
|
-
* @see getWalletOptionsCatalogue
|
|
9705
|
-
* @notInstrumented
|
|
9706
|
-
*/
|
|
9707
|
-
const buildInAppBrowserUrl = ({ appUrl, inAppBrowserUrl }) => inAppBrowserUrl.replaceAll(DAPP_URL_PLACEHOLDER, encodeURIComponent(appUrl));
|
|
9708
|
-
|
|
9709
|
-
//#endregion
|
|
9710
|
-
//#region src/modules/wallets/redirectToInAppBrowser/redirectToInAppBrowser.ts
|
|
9711
|
-
/**
|
|
9712
|
-
* Leaves your app for a wallet's in-app browser, which reloads `appUrl`
|
|
9713
|
-
* inside it.
|
|
9714
|
-
*
|
|
9715
|
-
* Call this from `handleWalletBrowserRedirect` with the URL of the page the
|
|
9716
|
-
* wallet should reload. The wallet's in-app-browser entry point is read from
|
|
9717
|
-
* the wallet options catalogue, so you only need the wallet's key. The wallet
|
|
9718
|
-
* is only injected on that reload, so the connection is made on the next page
|
|
9719
|
-
* load rather than in the current one.
|
|
9720
|
-
*
|
|
9721
|
-
* @example
|
|
9722
|
-
* ```ts
|
|
9723
|
-
* await connectWallet({
|
|
9724
|
-
* handleWalletBrowserRedirect: ({ chain, walletKey }) =>
|
|
9725
|
-
* redirectToInAppBrowser({ appUrl: window.location.href, chain, walletKey }),
|
|
9726
|
-
* walletKey: 'coinbase',
|
|
9727
|
-
* });
|
|
9728
|
-
* ```
|
|
9729
|
-
*
|
|
9730
|
-
* @param params.appUrl - The URL of your app for the wallet's browser to open.
|
|
9731
|
-
* @param params.walletKey - The wallet to open, keyed as in the wallet options catalogue.
|
|
9732
|
-
* @param [params.chain] - The chain to open the wallet's browser for. Required only when the wallet exposes an in-app browser on more than one enabled chain.
|
|
9733
|
-
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
9734
|
-
* @returns A promise that resolves once the redirect is triggered.
|
|
9735
|
-
* @throws WalletOptionNotFoundError If no wallet option matches the key.
|
|
9736
|
-
* @throws NoConnectionOptionAvailableError If the wallet exposes no in-app browser on the requested chain.
|
|
9737
|
-
* @throws AmbiguousWalletChainError If the wallet exposes an in-app browser on more than one chain and no chain was passed.
|
|
9738
|
-
* @throws UnsafeDeeplinkUrlError If the wallet's in-app-browser URL has a scheme that can execute script.
|
|
9739
|
-
* @see connectWallet
|
|
9740
|
-
* @see WalletBrowserRedirectHandlerParams
|
|
9741
|
-
* @instrumented
|
|
9742
|
-
*/
|
|
9743
|
-
const redirectToInAppBrowser = async ({ appUrl, chain, walletKey }, client = require_logoutWithReason.getDefaultClient()) => {
|
|
9744
|
-
const walletOption = (await getWalletOptionsCatalogue({ includeMobileOptions: true }, client)).find(({ key }) => key === walletKey);
|
|
9745
|
-
if (!walletOption) throw new WalletOptionNotFoundError({ walletKey });
|
|
9746
|
-
const inAppBrowserOptions = walletOption.connectionOptions.filter((option) => option.type === "inAppBrowser" && (!chain || option.chain === chain));
|
|
9747
|
-
if (inAppBrowserOptions.length === 0) throw new NoConnectionOptionAvailableError({
|
|
9748
|
-
chain,
|
|
9749
|
-
installationUrls: walletOption.installationUrls,
|
|
9750
|
-
walletKey
|
|
9751
|
-
});
|
|
9752
|
-
const availableChains = [...new Set(inAppBrowserOptions.map((option) => option.chain))];
|
|
9753
|
-
if (!chain && availableChains.length > 1) throw new AmbiguousWalletChainError({
|
|
9754
|
-
chains: availableChains,
|
|
9755
|
-
walletKey
|
|
9756
|
-
});
|
|
9757
|
-
const [inAppBrowserOption] = inAppBrowserOptions;
|
|
9758
|
-
const urlToOpen = buildInAppBrowserUrl({
|
|
9759
|
-
appUrl,
|
|
9760
|
-
inAppBrowserUrl: inAppBrowserOption.url
|
|
9761
|
-
});
|
|
9762
|
-
require_getNetworkProviderFromNetworkId.assertSafeDeeplinkUrl(urlToOpen);
|
|
9763
|
-
await require_logoutWithReason.getCore(client).openDeeplink(urlToOpen);
|
|
9764
|
-
};
|
|
9765
|
-
const __redirectToInAppBrowser_impl = redirectToInAppBrowser;
|
|
9766
|
-
const __redirectToInAppBrowser_wrapped = require_logoutWithReason.instrumentFunction({
|
|
9767
|
-
fn: __redirectToInAppBrowser_impl,
|
|
9768
|
-
functionName: "redirectToInAppBrowser",
|
|
9769
|
-
getCore: () => {
|
|
9770
|
-
try {
|
|
9771
|
-
return require_logoutWithReason.getCore(require_logoutWithReason.getDefaultClient());
|
|
9772
|
-
} catch {
|
|
9773
|
-
return;
|
|
9774
|
-
}
|
|
9775
|
-
}
|
|
9776
|
-
});
|
|
9777
|
-
|
|
9778
10213
|
//#endregion
|
|
9779
10214
|
//#region src/modules/wallets/disconnectWalletAccount/disconnectWalletAccount.ts
|
|
9780
10215
|
/**
|
|
@@ -10376,70 +10811,6 @@ const __withdrawFromYieldVault_wrapped = require_logoutWithReason.instrumentFunc
|
|
|
10376
10811
|
}
|
|
10377
10812
|
});
|
|
10378
10813
|
|
|
10379
|
-
//#endregion
|
|
10380
|
-
//#region src/utils/appendConnectionUriToDeeplink/appendConnectionUriToDeeplink.ts
|
|
10381
|
-
/**
|
|
10382
|
-
* Appends a wallet connection URI to a deeplink URL.
|
|
10383
|
-
*
|
|
10384
|
-
* Generic across URI-deeplink connection options — works for both
|
|
10385
|
-
* WalletConnect pairing URIs and MetaMask SDK URIs. Determines the
|
|
10386
|
-
* appropriate query parameter separator based on whether the deeplink
|
|
10387
|
-
* already contains query parameters.
|
|
10388
|
-
*
|
|
10389
|
-
* @param params.deeplinkUrl - The base deeplink URL (e.g., `walletapp://wc` or `walletapp://wc?param=value`).
|
|
10390
|
-
* @param params.connectionUri - The connection URI to append.
|
|
10391
|
-
* @returns The deeplink URL with the connection URI appended as a query parameter.
|
|
10392
|
-
*
|
|
10393
|
-
* @example
|
|
10394
|
-
* ```ts
|
|
10395
|
-
* appendConnectionUriToDeeplink({ deeplinkUrl: 'walletapp://wc', connectionUri: 'wc:123-456' })
|
|
10396
|
-
* // Returns: 'walletapp://wc?uri=wc%3A123-456'
|
|
10397
|
-
*
|
|
10398
|
-
* appendConnectionUriToDeeplink({ deeplinkUrl: 'walletapp://wc?param=value', connectionUri: 'wc:123-456' })
|
|
10399
|
-
* // Returns: 'walletapp://wc?param=value&uri=wc%3A123-456'
|
|
10400
|
-
* ```
|
|
10401
|
-
* @notInstrumented
|
|
10402
|
-
*/
|
|
10403
|
-
const appendConnectionUriToDeeplink = ({ connectionUri, deeplinkUrl }) => {
|
|
10404
|
-
const url = new URL(deeplinkUrl);
|
|
10405
|
-
url.searchParams.set("uri", connectionUri);
|
|
10406
|
-
return url.href;
|
|
10407
|
-
};
|
|
10408
|
-
|
|
10409
|
-
//#endregion
|
|
10410
|
-
//#region src/utils/getPreferredWalletDeepLink/getPreferredWalletDeepLink.ts
|
|
10411
|
-
/**
|
|
10412
|
-
* Picks the most appropriate deep link variant for the current platform.
|
|
10413
|
-
*
|
|
10414
|
-
* Mobile (Android, iOS, tablets) prefers `native` because the OS treats
|
|
10415
|
-
* custom URL schemes as first-class app links and gives the wallet a faster
|
|
10416
|
-
* round-trip back to the dApp. Desktop prefers `universal` because browsers
|
|
10417
|
-
* cannot resolve mobile-only custom schemes and need an `https://` link
|
|
10418
|
-
* that opens the wallet's web flow.
|
|
10419
|
-
*
|
|
10420
|
-
* In either case, the alternative is used as a fallback when the preferred
|
|
10421
|
-
* variant is missing. Returns `undefined` only when both variants are
|
|
10422
|
-
* absent.
|
|
10423
|
-
*
|
|
10424
|
-
* @example
|
|
10425
|
-
* ```ts
|
|
10426
|
-
* const deepLink = getPreferredWalletDeepLink({
|
|
10427
|
-
* deeplinks: wallet.deeplinks,
|
|
10428
|
-
* });
|
|
10429
|
-
* ```
|
|
10430
|
-
*
|
|
10431
|
-
* @param params.deeplinks - The deep link variants for a wallet (typically `WalletConnectCatalogWallet.deeplinks`).
|
|
10432
|
-
* @returns The preferred deep link URL, or `undefined` if neither variant is available.
|
|
10433
|
-
* @see appendConnectionUriToDeeplink
|
|
10434
|
-
* @see getConnectionUriDeeplink
|
|
10435
|
-
* @notInstrumented
|
|
10436
|
-
*/
|
|
10437
|
-
const getPreferredWalletDeepLink = ({ deeplinks }) => {
|
|
10438
|
-
const { native, universal } = deeplinks;
|
|
10439
|
-
if (isMobile()) return native ?? universal;
|
|
10440
|
-
return universal ?? native;
|
|
10441
|
-
};
|
|
10442
|
-
|
|
10443
10814
|
//#endregion
|
|
10444
10815
|
//#region src/utils/parseUserAgent/parseUserAgent.ts
|
|
10445
10816
|
const browserMatchers = [
|
|
@@ -10533,6 +10904,7 @@ exports.CoinbaseTransferMfaFailedError = CoinbaseTransferMfaFailedError;
|
|
|
10533
10904
|
exports.CoinbaseTransferMfaRequiredError = CoinbaseTransferMfaRequiredError;
|
|
10534
10905
|
exports.CoinbaseTravelRuleFieldName = CoinbaseTravelRuleFieldName;
|
|
10535
10906
|
exports.CoinbaseTravelRuleRequiredError = CoinbaseTravelRuleRequiredError;
|
|
10907
|
+
exports.ConnectionUriHandlerMissingError = ConnectionUriHandlerMissingError;
|
|
10536
10908
|
exports.DeeplinkConnectAndVerifyUnsupportedError = DeeplinkConnectAndVerifyUnsupportedError;
|
|
10537
10909
|
exports.DeviceRegistrationIdentityMismatchError = DeviceRegistrationIdentityMismatchError;
|
|
10538
10910
|
exports.FeeEstimationFailedError = FeeEstimationFailedError;
|
|
@@ -10582,6 +10954,7 @@ exports.WaasRbacStaleRetryUnsafeError = require_isUserOnboardingComplete.WaasRba
|
|
|
10582
10954
|
exports.WalletAccountAlreadyVerifiedError = WalletAccountAlreadyVerifiedError;
|
|
10583
10955
|
exports.WalletAccountNotSelectedError = WalletAccountNotSelectedError;
|
|
10584
10956
|
exports.WalletAlreadyLinkedToAnotherUserError = require_getNetworkProviderFromNetworkId.WalletAlreadyLinkedToAnotherUserError;
|
|
10957
|
+
exports.WalletBrowserRedirectHandlerMissingError = WalletBrowserRedirectHandlerMissingError;
|
|
10585
10958
|
exports.WalletOptionNotFoundError = WalletOptionNotFoundError;
|
|
10586
10959
|
exports.WalletProviderMethodUnavailableError = WalletProviderMethodUnavailableError;
|
|
10587
10960
|
exports.WalletScreeningBlockedError = require_getNetworkProviderFromNetworkId.WalletScreeningBlockedError;
|
|
@@ -10612,6 +10985,7 @@ exports.completeSocialAuthentication = __completeSocialAuthentication_wrapped;
|
|
|
10612
10985
|
exports.completeSocialRedirect = __completeSocialRedirect_wrapped;
|
|
10613
10986
|
exports.confirmTransaction = __confirmTransaction_wrapped;
|
|
10614
10987
|
exports.connectAndVerifyWithWalletProvider = __connectAndVerifyWithWalletProvider_wrapped;
|
|
10988
|
+
exports.connectWalletOption = __connectWalletOption_wrapped;
|
|
10615
10989
|
exports.connectWithWalletProvider = __connectWithWalletProvider_wrapped;
|
|
10616
10990
|
exports.consumeMfaToken = require_isMfaRequiredForAction.__consumeMfaToken_wrapped;
|
|
10617
10991
|
exports.createCheckoutTransaction = __createCheckoutTransaction_wrapped;
|