@getpara/evm-wallet-connectors 1.8.0 → 2.0.0-alpha.3
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/index.d.ts +4 -1
- package/dist/index.js +952 -6
- package/dist/index.js.br +0 -0
- package/dist/index.js.gz +0 -0
- package/dist/providers/EvmExternalWalletContext.d.ts +19 -26
- package/dist/providers/ParaEvmContext.d.ts +10 -11
- package/dist/types/Wallet.d.ts +1 -1
- package/dist/types/utils.d.ts +1 -1
- package/dist/utils/getWalletConnectConnector.d.ts +1 -1
- package/dist/wallets/connectors/index.d.ts +2 -2
- package/package.json +9 -10
- package/dist/chunk-MMUBH76A.js +0 -59
- package/dist/global.d.js +0 -1
- package/dist/package.json +0 -3
- package/dist/providers/EvmExternalWalletContext.js +0 -345
- package/dist/providers/ParaEvmContext.js +0 -115
- package/dist/stores/useStore.js +0 -22
- package/dist/types/Wallet.js +0 -1
- package/dist/types/utils.js +0 -1
- package/dist/utils/computeWalletConnectMetaData.js +0 -18
- package/dist/utils/getInjectedConnector.js +0 -69
- package/dist/utils/getWalletConnectConnector.js +0 -63
- package/dist/utils/getWalletConnectUri.js +0 -22
- package/dist/utils/isEIP6963Connector.js +0 -9
- package/dist/utils/omitUndefinedValues.js +0 -11
- package/dist/utils/uniqueBy.js +0 -14
- package/dist/wallets/connectors/coinbase/coinbase.js +0 -35
- package/dist/wallets/connectors/coinbase/coinbaseIcon.js +0 -6
- package/dist/wallets/connectors/index.js +0 -18
- package/dist/wallets/connectors/metaMask/metaMask.js +0 -84
- package/dist/wallets/connectors/metaMask/metaMaskIcon.js +0 -6
- package/dist/wallets/connectors/rabby/rabby.js +0 -25
- package/dist/wallets/connectors/rabby/rabbyIcon.js +0 -6
- package/dist/wallets/connectors/rainbow/rainbow.js +0 -30
- package/dist/wallets/connectors/rainbow/rainbowIcon.js +0 -6
- package/dist/wallets/connectors/safe/safe.d.ts +0 -2
- package/dist/wallets/connectors/safe/safe.js +0 -26
- package/dist/wallets/connectors/safe/safeIcon.d.ts +0 -1
- package/dist/wallets/connectors/safe/safeIcon.js +0 -6
- package/dist/wallets/connectors/walletConnect/walletConnect.js +0 -22
- package/dist/wallets/connectors/walletConnect/walletConnectIcon.js +0 -6
- package/dist/wallets/connectors/zerion/zerion.js +0 -36
- package/dist/wallets/connectors/zerion/zerionIcon.js +0 -6
- package/dist/wallets/connectorsForWallets.js +0 -73
- package/dist/window.d.js +0 -1
package/dist/index.js.br
ADDED
|
Binary file
|
package/dist/index.js.gz
ADDED
|
Binary file
|
|
@@ -1,28 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
chains: any[];
|
|
6
|
-
chainId: any;
|
|
7
|
-
username: any;
|
|
8
|
-
avatar: any;
|
|
9
|
-
balance: any;
|
|
10
|
-
disconnect: () => Promise<void>;
|
|
11
|
-
switchChain: () => Promise<{}>;
|
|
12
|
-
signMessage: () => Promise<{}>;
|
|
13
|
-
signVerificationMessage: () => Promise<{}>;
|
|
14
|
-
};
|
|
15
|
-
export declare const EvmExternalWalletContext: import("react").Context<{
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
import type { CommonChain, CommonWallet, TExternalWallet } from '@getpara/react-common';
|
|
3
|
+
import ParaWeb, { Wallet } from '@getpara/web-sdk';
|
|
4
|
+
export type EvmExternalWalletContextType = {
|
|
16
5
|
wallets: CommonWallet[];
|
|
17
6
|
chains: CommonChain[];
|
|
18
|
-
chainId
|
|
19
|
-
username
|
|
7
|
+
chainId?: number;
|
|
8
|
+
username?: string;
|
|
20
9
|
avatar?: string;
|
|
21
|
-
balance?: string;
|
|
22
10
|
disconnect: () => Promise<void>;
|
|
23
11
|
switchChain: (chainId: number) => Promise<{
|
|
24
12
|
error?: string[];
|
|
25
13
|
}>;
|
|
14
|
+
connectParaEmbedded: () => Promise<{
|
|
15
|
+
result?: unknown;
|
|
16
|
+
error?: string;
|
|
17
|
+
}>;
|
|
26
18
|
signMessage: (message: string) => Promise<{
|
|
27
19
|
signature?: string;
|
|
28
20
|
error?: string;
|
|
@@ -32,14 +24,15 @@ export declare const EvmExternalWalletContext: import("react").Context<{
|
|
|
32
24
|
signature?: string;
|
|
33
25
|
error?: string;
|
|
34
26
|
}>;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
onSwitchWallet: (args: {
|
|
27
|
+
};
|
|
28
|
+
export declare const EvmExternalWalletContext: import("react").Context<EvmExternalWalletContextType>;
|
|
29
|
+
export type EvmExternalWalletProviderConfig = {
|
|
30
|
+
onSwitchWallet?: (args: {
|
|
40
31
|
address?: string;
|
|
41
32
|
error?: string;
|
|
42
33
|
}) => void;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
34
|
+
para: ParaWeb;
|
|
35
|
+
walletsWithFullAuth: TExternalWallet[];
|
|
36
|
+
connectedWallet?: Omit<Wallet, 'signer'> | null;
|
|
37
|
+
};
|
|
38
|
+
export declare function EvmExternalWalletProvider({ children, onSwitchWallet, para, walletsWithFullAuth, connectedWallet, }: EvmExternalWalletProviderConfig & PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
2
|
import { CreateConfigParameters, WagmiProviderProps } from 'wagmi';
|
|
3
3
|
import { WalletList } from '../types/Wallet.js';
|
|
4
4
|
import { Chain, Transport } from 'viem';
|
|
5
|
-
import
|
|
5
|
+
import { EvmExternalWalletProviderConfig } from './EvmExternalWalletContext.js';
|
|
6
6
|
import { InjectedParameters } from 'wagmi/connectors';
|
|
7
|
-
interface
|
|
7
|
+
export interface ParaEvmProviderConfig<chains extends readonly [Chain, ...Chain[]], transports extends Record<chains[number]['id'], Transport>> extends Omit<CreateConfigParameters<chains, transports>, 'connectors'> {
|
|
8
8
|
appName: string;
|
|
9
9
|
appDescription?: string;
|
|
10
10
|
appUrl?: string;
|
|
11
11
|
appIcon?: string;
|
|
12
12
|
wallets?: WalletList;
|
|
13
13
|
projectId: string;
|
|
14
|
-
|
|
15
|
-
paraDisableModal?: boolean;
|
|
16
|
-
paraOptions?: InjectedParameters;
|
|
14
|
+
paraConnectorOptions?: InjectedParameters;
|
|
17
15
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
config:
|
|
16
|
+
export type ParaWagmiProviderProps = Omit<WagmiProviderProps, 'config'>;
|
|
17
|
+
export interface ParaEvmProviderProps<chains extends readonly [Chain, ...Chain[]], transports extends Record<chains[number]['id'], Transport>> {
|
|
18
|
+
config: ParaEvmProviderConfig<chains, transports>;
|
|
19
|
+
internalConfig: EvmExternalWalletProviderConfig;
|
|
20
|
+
wagmiProviderProps?: ParaWagmiProviderProps;
|
|
21
21
|
}
|
|
22
|
-
export declare function ParaEvmProvider<const chains extends readonly [Chain, ...Chain[]], transports extends Record<chains[number]['id'], Transport>>({ children, config: _config,
|
|
23
|
-
export {};
|
|
22
|
+
export declare function ParaEvmProvider<const chains extends readonly [Chain, ...Chain[]], transports extends Record<chains[number]['id'], Transport>>({ children, internalConfig, config: _config, wagmiProviderProps, }: ParaEvmProviderProps<chains, transports> & PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|
package/dist/types/Wallet.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Connector, CreateConnectorFn } from 'wagmi';
|
|
|
2
2
|
import { WalletConnectParameters } from 'wagmi/connectors';
|
|
3
3
|
import { CoinbaseWalletOptions } from '../wallets/connectors/coinbase/coinbase.js';
|
|
4
4
|
import { WalletConnectWalletOptions } from '../wallets/connectors/walletConnect/walletConnect.js';
|
|
5
|
-
import { WalletMetadata } from '@getpara/react-
|
|
5
|
+
import { type WalletMetadata } from '@getpara/react-common';
|
|
6
6
|
export type Wallet = {
|
|
7
7
|
createConnector?: (walletDetails: WalletDetailsParams) => CreateConnectorFn;
|
|
8
8
|
createMobileConnector?: (walletDetails: WalletDetailsParams) => CreateConnectorFn;
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export type Mutable<type extends object> = {
|
|
|
9
9
|
};
|
|
10
10
|
/** Strict version of built-in Omit type */
|
|
11
11
|
export type Omit<type, keys extends keyof type> = Pick<type, Exclude<keyof type, keys>>;
|
|
12
|
-
export type WalletProviderFlags = 'isApexWallet' | 'isAvalanche' | 'isBackpack' | 'isBifrost' | 'isBitKeep' | 'isBitski' | 'isBlockWallet' | 'isBraveWallet' | 'isCoinbaseWallet' | 'isDawn' | 'isEnkrypt' | 'isExodus' | 'isFrame' | 'isFrontier' | 'isGamestop' | 'isHyperPay' | 'isImToken' | 'isKuCoinWallet' | 'isMathWallet' | 'isMetaMask' | 'isNestWallet' | 'isOkxWallet' | 'isOKExWallet' | 'isOneInchAndroidWallet' | 'isOneInchIOSWallet' | 'isOpera' | 'isPhantom' | 'isPortal' | 'isRabby' | 'isRainbow' | '
|
|
12
|
+
export type WalletProviderFlags = 'isApexWallet' | 'isAvalanche' | 'isBackpack' | 'isBifrost' | 'isBitKeep' | 'isBitski' | 'isBlockWallet' | 'isBraveWallet' | 'isCoinbaseWallet' | 'isDawn' | 'isEnkrypt' | 'isExodus' | 'isFrame' | 'isFrontier' | 'isGamestop' | 'isHyperPay' | 'isImToken' | 'isKuCoinWallet' | 'isMathWallet' | 'isMetaMask' | 'isNestWallet' | 'isOkxWallet' | 'isOKExWallet' | 'isOneInchAndroidWallet' | 'isOneInchIOSWallet' | 'isOpera' | 'isPhantom' | 'isPortal' | 'isRabby' | 'isRainbow' | 'isStatus' | 'isTally' | 'isTokenPocket' | 'isTokenary' | 'isTrust' | 'isTrustWallet' | 'isXDEFI' | 'isZerion' | 'isTalisman' | 'isZeal' | 'isCoin98' | 'isMEWwallet' | 'isSafeheron' | 'isSafePal' | '__seif';
|
|
13
13
|
export type WalletProvider = Evaluate<EIP1193Provider & {
|
|
14
14
|
[key in WalletProviderFlags]?: true | undefined;
|
|
15
15
|
} & {
|
|
@@ -3,5 +3,5 @@ interface GetWalletConnectConnectorParams {
|
|
|
3
3
|
projectId: string;
|
|
4
4
|
walletConnectParameters?: ParaWalletConnectParameters;
|
|
5
5
|
}
|
|
6
|
-
export declare function getWalletConnectConnector({ projectId, walletConnectParameters, }: GetWalletConnectConnectorParams): CreateConnector;
|
|
6
|
+
export declare function getWalletConnectConnector({ projectId, walletConnectParameters, }: GetWalletConnectConnectorParams): CreateConnector | undefined;
|
|
7
7
|
export {};
|
|
@@ -4,5 +4,5 @@ import { walletConnectWallet } from './walletConnect/walletConnect.js';
|
|
|
4
4
|
import { coinbaseWallet } from './coinbase/coinbase.js';
|
|
5
5
|
import { zerionWallet } from './zerion/zerion.js';
|
|
6
6
|
import { rabbyWallet } from './rabby/rabby.js';
|
|
7
|
-
|
|
8
|
-
export {
|
|
7
|
+
export { metaMaskWallet, rainbowWallet, walletConnectWallet, coinbaseWallet, zerionWallet, rabbyWallet };
|
|
8
|
+
export declare const allWallets: ((({ appName, appIcon }: import("./coinbase/coinbase.js").CoinbaseWalletOptions) => import("../../types/Wallet.js").Wallet) | (({ projectId, options }: import("./walletConnect/walletConnect.js").WalletConnectWalletOptions) => import("../../types/Wallet.js").Wallet) | (({ projectId, walletConnectParameters }: import("./metaMask/metaMask.js").MetaMaskWalletOptions) => import("../../types/Wallet.js").Wallet))[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/evm-wallet-connectors",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,8 +10,10 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@coinbase/wallet-sdk": "4.3.0",
|
|
13
|
-
"@getpara/
|
|
14
|
-
"@getpara/
|
|
13
|
+
"@getpara/wagmi-v2-connector": "2.0.0-alpha.3",
|
|
14
|
+
"@getpara/web-sdk": "2.0.0-alpha.3",
|
|
15
|
+
"viem": "2.x",
|
|
16
|
+
"wagmi": "2.x",
|
|
15
17
|
"zustand": "^4.5.2",
|
|
16
18
|
"zustand-sync-tabs": "^0.2.2"
|
|
17
19
|
},
|
|
@@ -21,21 +23,18 @@
|
|
|
21
23
|
"test": "vitest run --coverage"
|
|
22
24
|
},
|
|
23
25
|
"devDependencies": {
|
|
26
|
+
"@getpara/react-common": "2.0.0-alpha.3",
|
|
24
27
|
"@types/react": "^18.0.31",
|
|
25
28
|
"@types/react-dom": "^18.2.7",
|
|
26
|
-
"typescript": "^5.4.3"
|
|
27
|
-
"viem": "^2.23.5",
|
|
28
|
-
"wagmi": "^2.14.12"
|
|
29
|
+
"typescript": "^5.4.3"
|
|
29
30
|
},
|
|
30
31
|
"peerDependencies": {
|
|
31
32
|
"react": ">=18",
|
|
32
|
-
"react-dom": ">=18"
|
|
33
|
-
"viem": "2.x",
|
|
34
|
-
"wagmi": "2.x"
|
|
33
|
+
"react-dom": ">=18"
|
|
35
34
|
},
|
|
36
35
|
"files": [
|
|
37
36
|
"dist",
|
|
38
37
|
"package.json"
|
|
39
38
|
],
|
|
40
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "77a1e04b06258842ca9c81e3db2a2b0092517659"
|
|
41
40
|
}
|
package/dist/chunk-MMUBH76A.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __spreadValues = (a, b) => {
|
|
10
|
-
for (var prop in b || (b = {}))
|
|
11
|
-
if (__hasOwnProp.call(b, prop))
|
|
12
|
-
__defNormalProp(a, prop, b[prop]);
|
|
13
|
-
if (__getOwnPropSymbols)
|
|
14
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
-
if (__propIsEnum.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
}
|
|
18
|
-
return a;
|
|
19
|
-
};
|
|
20
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
-
var __objRest = (source, exclude) => {
|
|
22
|
-
var target = {};
|
|
23
|
-
for (var prop in source)
|
|
24
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
25
|
-
target[prop] = source[prop];
|
|
26
|
-
if (source != null && __getOwnPropSymbols)
|
|
27
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
28
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
29
|
-
target[prop] = source[prop];
|
|
30
|
-
}
|
|
31
|
-
return target;
|
|
32
|
-
};
|
|
33
|
-
var __async = (__this, __arguments, generator) => {
|
|
34
|
-
return new Promise((resolve, reject) => {
|
|
35
|
-
var fulfilled = (value) => {
|
|
36
|
-
try {
|
|
37
|
-
step(generator.next(value));
|
|
38
|
-
} catch (e) {
|
|
39
|
-
reject(e);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
var rejected = (value) => {
|
|
43
|
-
try {
|
|
44
|
-
step(generator.throw(value));
|
|
45
|
-
} catch (e) {
|
|
46
|
-
reject(e);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
50
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export {
|
|
55
|
-
__spreadValues,
|
|
56
|
-
__spreadProps,
|
|
57
|
-
__objRest,
|
|
58
|
-
__async
|
|
59
|
-
};
|
package/dist/global.d.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use client";
|
package/dist/package.json
DELETED
|
@@ -1,345 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import {
|
|
3
|
-
__async,
|
|
4
|
-
__spreadProps,
|
|
5
|
-
__spreadValues
|
|
6
|
-
} from "../chunk-MMUBH76A.js";
|
|
7
|
-
import { jsx } from "react/jsx-runtime";
|
|
8
|
-
import { createContext, useEffect, useMemo, useRef } from "react";
|
|
9
|
-
import {
|
|
10
|
-
useAccount,
|
|
11
|
-
useSwitchChain,
|
|
12
|
-
useConnect,
|
|
13
|
-
useDisconnect,
|
|
14
|
-
useEnsName,
|
|
15
|
-
useEnsAvatar,
|
|
16
|
-
useSwitchAccount,
|
|
17
|
-
useConnections,
|
|
18
|
-
useSignMessage,
|
|
19
|
-
useBalance
|
|
20
|
-
} from "wagmi";
|
|
21
|
-
import { isEIP6963Connector } from "../utils/isEIP6963Connector.js";
|
|
22
|
-
import { getWalletConnectUri } from "../utils/getWalletConnectUri.js";
|
|
23
|
-
import {
|
|
24
|
-
isMobile,
|
|
25
|
-
useExternalWalletProviderStore,
|
|
26
|
-
useWalletState,
|
|
27
|
-
WalletType
|
|
28
|
-
} from "@getpara/react-sdk";
|
|
29
|
-
import { normalize } from "viem/ens";
|
|
30
|
-
import { useExternalWalletStore } from "../stores/useStore.js";
|
|
31
|
-
import { etherUnits, formatUnits } from "viem";
|
|
32
|
-
const defaultEvmExternalWallet = {
|
|
33
|
-
wallets: [],
|
|
34
|
-
chains: [],
|
|
35
|
-
chainId: void 0,
|
|
36
|
-
username: void 0,
|
|
37
|
-
avatar: void 0,
|
|
38
|
-
balance: void 0,
|
|
39
|
-
disconnect: () => Promise.resolve(),
|
|
40
|
-
switchChain: () => Promise.resolve({}),
|
|
41
|
-
signMessage: () => Promise.resolve({}),
|
|
42
|
-
signVerificationMessage: () => Promise.resolve({})
|
|
43
|
-
};
|
|
44
|
-
const EvmExternalWalletContext = createContext(defaultEvmExternalWallet);
|
|
45
|
-
function EvmExternalWalletProvider({ children, para, onSwitchWallet }) {
|
|
46
|
-
const { connectAsync, connectors: untypedConnectors } = useConnect();
|
|
47
|
-
const connections = useConnections();
|
|
48
|
-
const { address: wagmiAddress, isConnecting, isReconnecting, chainId, connector: connectedConnector } = useAccount();
|
|
49
|
-
const { chains, switchChainAsync } = useSwitchChain();
|
|
50
|
-
const { disconnectAsync } = useDisconnect();
|
|
51
|
-
const { switchAccountAsync } = useSwitchAccount();
|
|
52
|
-
const { signMessageAsync } = useSignMessage();
|
|
53
|
-
const { data: ensName, refetch: refetchEnsName } = useEnsName({ address: wagmiAddress });
|
|
54
|
-
const { data: ensAvatar, refetch: refetchEnsAvatar } = useEnsAvatar({
|
|
55
|
-
name: normalize(ensName)
|
|
56
|
-
});
|
|
57
|
-
const { data: wagmiBalance, isLoading: isBalanceLoading } = useBalance({ address: wagmiAddress });
|
|
58
|
-
const fullAuthWallets = useExternalWalletProviderStore((state) => state.fullAuthWallets);
|
|
59
|
-
const { selectedWallet } = useWalletState();
|
|
60
|
-
const isLocalConnecting = useExternalWalletStore((state) => state.isConnecting);
|
|
61
|
-
const updateExternalWalletState = useExternalWalletStore((state) => state.updateState);
|
|
62
|
-
const verificationMessage = useRef();
|
|
63
|
-
const getStoredExternalWallets = () => {
|
|
64
|
-
const storedExternalWalletsString = localStorage.getItem("@CAPSULE/externalWallets");
|
|
65
|
-
let storedExternalWallets = {};
|
|
66
|
-
if (storedExternalWalletsString) {
|
|
67
|
-
storedExternalWallets = JSON.parse(storedExternalWalletsString);
|
|
68
|
-
}
|
|
69
|
-
return storedExternalWallets;
|
|
70
|
-
};
|
|
71
|
-
const balance = useMemo(
|
|
72
|
-
// Format from wei to eth
|
|
73
|
-
() => isBalanceLoading || wagmiBalance === void 0 ? void 0 : formatUnits(wagmiBalance.value, etherUnits.wei),
|
|
74
|
-
[wagmiBalance, isBalanceLoading]
|
|
75
|
-
);
|
|
76
|
-
useEffect(() => {
|
|
77
|
-
const storedExternalWallet = getStoredExternalWallets()[wagmiAddress != null ? wagmiAddress : ""];
|
|
78
|
-
if (!isConnecting && !isReconnecting && !isLocalConnecting && !!wagmiAddress && !storedExternalWallet && (connectedConnector == null ? void 0 : connectedConnector.id) !== "para") {
|
|
79
|
-
reset();
|
|
80
|
-
}
|
|
81
|
-
}, [isConnecting, isReconnecting, isLocalConnecting, wagmiAddress, connectedConnector]);
|
|
82
|
-
useEffect(() => {
|
|
83
|
-
const storedExternalWallet = Object.values(para.externalWallets || {})[0];
|
|
84
|
-
if (!isLocalConnecting && !isConnecting && !isReconnecting && (storedExternalWallet == null ? void 0 : storedExternalWallet.type) === WalletType.EVM && (storedExternalWallet == null ? void 0 : storedExternalWallet.address) !== wagmiAddress && (connectedConnector == null ? void 0 : connectedConnector.id) !== "para") {
|
|
85
|
-
switchWallet(wagmiAddress);
|
|
86
|
-
}
|
|
87
|
-
}, [isLocalConnecting, wagmiAddress, isReconnecting, isConnecting]);
|
|
88
|
-
useEffect(() => {
|
|
89
|
-
const wallet = para.findWallet(selectedWallet.id, selectedWallet.type);
|
|
90
|
-
if (wallet && connectedConnector && wallet.type === WalletType.EVM && (connectedConnector.id === "para" && wallet.isExternal || connectedConnector.id !== "para" && !wallet.isExternal)) {
|
|
91
|
-
switchAccount(wallet.isExternal ? wallet.name : "Para");
|
|
92
|
-
}
|
|
93
|
-
}, [selectedWallet]);
|
|
94
|
-
const connectors = untypedConnectors;
|
|
95
|
-
const reset = () => __async(this, null, function* () {
|
|
96
|
-
yield disconnectAsync();
|
|
97
|
-
yield para.logout();
|
|
98
|
-
});
|
|
99
|
-
const signMessage = (message) => __async(this, null, function* () {
|
|
100
|
-
try {
|
|
101
|
-
const signature = yield signMessageAsync({
|
|
102
|
-
message,
|
|
103
|
-
account: wagmiAddress
|
|
104
|
-
});
|
|
105
|
-
return { address: wagmiAddress, signature };
|
|
106
|
-
} catch (e) {
|
|
107
|
-
switch (e.name) {
|
|
108
|
-
case "UserRejectedRequestError": {
|
|
109
|
-
return { error: "Signature request rejected" };
|
|
110
|
-
}
|
|
111
|
-
default: {
|
|
112
|
-
return { error: "An unknown error occurred" };
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
const signVerificationMessage = () => __async(this, null, function* () {
|
|
118
|
-
const signature = yield signMessage(verificationMessage.current);
|
|
119
|
-
return signature;
|
|
120
|
-
});
|
|
121
|
-
const switchAccount = (connectorName) => __async(this, null, function* () {
|
|
122
|
-
var _a;
|
|
123
|
-
const connector = (_a = connections.find((c) => c.connector.name === connectorName)) == null ? void 0 : _a.connector;
|
|
124
|
-
if (!connector) {
|
|
125
|
-
throw new Error(`connector not found: ${connectorName}`);
|
|
126
|
-
}
|
|
127
|
-
yield switchAccountAsync({ connector });
|
|
128
|
-
});
|
|
129
|
-
const switchChain = (chainId2) => __async(this, null, function* () {
|
|
130
|
-
var _a, _b, _c;
|
|
131
|
-
let error;
|
|
132
|
-
try {
|
|
133
|
-
yield switchChainAsync({ chainId: chainId2 });
|
|
134
|
-
} catch (e) {
|
|
135
|
-
if (e.details.includes("Missing or invalid.")) {
|
|
136
|
-
const chain = chains.find((c) => c.id === chainId2);
|
|
137
|
-
error = [
|
|
138
|
-
"Network not supported.",
|
|
139
|
-
`You may need to add ${chain == null ? void 0 : chain.name} support to ${(_c = (_b = (_a = connectedConnector == null ? void 0 : connectedConnector.paraDetails) == null ? void 0 : _a.name) != null ? _b : connectedConnector == null ? void 0 : connectedConnector.name) != null ? _c : "the wallet"} manually.`
|
|
140
|
-
];
|
|
141
|
-
} else {
|
|
142
|
-
switch (e.name) {
|
|
143
|
-
case "UserRejectedRequestError": {
|
|
144
|
-
error = ["Change request rejected"];
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
default: {
|
|
148
|
-
error = ["An unknown error occurred"];
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return { error };
|
|
155
|
-
});
|
|
156
|
-
const login = (_0) => __async(this, [_0], function* ({
|
|
157
|
-
address,
|
|
158
|
-
walletId,
|
|
159
|
-
connectorName
|
|
160
|
-
}) {
|
|
161
|
-
var _a;
|
|
162
|
-
try {
|
|
163
|
-
refetchEnsName();
|
|
164
|
-
refetchEnsAvatar();
|
|
165
|
-
return yield para.externalWalletLogin({
|
|
166
|
-
address,
|
|
167
|
-
type: WalletType.EVM,
|
|
168
|
-
provider: connectorName,
|
|
169
|
-
withFullParaAuth: fullAuthWallets == null ? void 0 : fullAuthWallets.includes((_a = walletId == null ? void 0 : walletId.toUpperCase()) != null ? _a : "")
|
|
170
|
-
});
|
|
171
|
-
} catch (err) {
|
|
172
|
-
yield disconnectAsync();
|
|
173
|
-
yield para.logout();
|
|
174
|
-
throw "Error logging you in. Please try again.";
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
const switchWallet = (address) => __async(this, null, function* () {
|
|
178
|
-
var _a;
|
|
179
|
-
updateExternalWalletState({ isConnecting: true });
|
|
180
|
-
let error;
|
|
181
|
-
if (!address) {
|
|
182
|
-
yield para.logout();
|
|
183
|
-
} else {
|
|
184
|
-
if (para.isExternalWalletAuth) {
|
|
185
|
-
yield reset();
|
|
186
|
-
} else {
|
|
187
|
-
try {
|
|
188
|
-
yield login({
|
|
189
|
-
address,
|
|
190
|
-
connectorName: connectedConnector == null ? void 0 : connectedConnector.name,
|
|
191
|
-
walletId: (_a = getParaDetails(connectedConnector.id)) == null ? void 0 : _a.id
|
|
192
|
-
});
|
|
193
|
-
} catch (err) {
|
|
194
|
-
error = err;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
onSwitchWallet({ address, error });
|
|
199
|
-
updateExternalWalletState({ isConnecting: false });
|
|
200
|
-
});
|
|
201
|
-
const connect = (connector) => __async(this, null, function* () {
|
|
202
|
-
var _a, _b, _c, _d;
|
|
203
|
-
updateExternalWalletState({ isConnecting: true });
|
|
204
|
-
yield disconnectAsync();
|
|
205
|
-
const walletChainId = yield connector.getChainId();
|
|
206
|
-
let address;
|
|
207
|
-
let error;
|
|
208
|
-
let userExists = false;
|
|
209
|
-
let isVerified = false;
|
|
210
|
-
try {
|
|
211
|
-
const data = yield connectAsync({
|
|
212
|
-
// If the wallet is already on a supported chain, use that to avoid a chain switch prompt.
|
|
213
|
-
chainId: (_c = (_a = chains.find(({ id }) => id === walletChainId)) == null ? void 0 : _a.id) != null ? _c : (
|
|
214
|
-
// Fall back to the first chain provided.
|
|
215
|
-
(_b = chains[0]) == null ? void 0 : _b.id
|
|
216
|
-
),
|
|
217
|
-
connector
|
|
218
|
-
});
|
|
219
|
-
address = (_d = data.accounts) == null ? void 0 : _d[0];
|
|
220
|
-
if (address) {
|
|
221
|
-
try {
|
|
222
|
-
const loginResp = yield login({ address, connectorName: connector.name, walletId: connector.paraDetails.id });
|
|
223
|
-
userExists = loginResp.userExists;
|
|
224
|
-
isVerified = loginResp.isVerified;
|
|
225
|
-
verificationMessage.current = loginResp.signatureVerificationMessage;
|
|
226
|
-
} catch (err) {
|
|
227
|
-
address = void 0;
|
|
228
|
-
error = err;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
} catch (e) {
|
|
232
|
-
switch (e.name) {
|
|
233
|
-
case "UserRejectedRequestError": {
|
|
234
|
-
error = "Connection request rejected";
|
|
235
|
-
break;
|
|
236
|
-
}
|
|
237
|
-
case "ResourceUnavailableRpcError": {
|
|
238
|
-
`${connector.name} not detected`;
|
|
239
|
-
break;
|
|
240
|
-
}
|
|
241
|
-
default: {
|
|
242
|
-
error = "An unknown error occurred";
|
|
243
|
-
break;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
updateExternalWalletState({ isConnecting: false });
|
|
248
|
-
return { address, error, userExists, isVerified };
|
|
249
|
-
});
|
|
250
|
-
const connectMobile = (connector, isManualWalletConnect) => __async(this, null, function* () {
|
|
251
|
-
const _isMobile = isManualWalletConnect !== void 0 ? isManualWalletConnect : isMobile();
|
|
252
|
-
const _connector = connector.walletConnectModalConnector && _isMobile ? connector.walletConnectModalConnector : connector;
|
|
253
|
-
return yield connect(_connector);
|
|
254
|
-
});
|
|
255
|
-
const getQrUri = (connector) => () => {
|
|
256
|
-
var _a;
|
|
257
|
-
return getWalletConnectUri(connector, (_a = connector.paraDetails) == null ? void 0 : _a.getUri);
|
|
258
|
-
};
|
|
259
|
-
const nonEip6963ConnectorsByRdns = {};
|
|
260
|
-
let walletConnectModalConnector;
|
|
261
|
-
connectors.filter((c) => !isEIP6963Connector(c)).forEach((c) => {
|
|
262
|
-
if (c.paraDetails) {
|
|
263
|
-
nonEip6963ConnectorsByRdns[c.paraDetails.rdns] = c.paraDetails;
|
|
264
|
-
if (c.paraDetails.isWalletConnectModalConnector) {
|
|
265
|
-
walletConnectModalConnector = c;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
const eip6963ids = connectors.filter((c) => isEIP6963Connector(c)).map((c) => c.id);
|
|
270
|
-
const dedupedConnectors = connectors.map((c) => {
|
|
271
|
-
var _a, _b, _c;
|
|
272
|
-
if ((_a = c.paraDetails) == null ? void 0 : _a.isWalletConnectModalConnector) {
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
if (!isEIP6963Connector(c) && eip6963ids.includes((_b = c.paraDetails) == null ? void 0 : _b.rdns)) {
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
if (isEIP6963Connector(c)) {
|
|
279
|
-
const paraMetadata = nonEip6963ConnectorsByRdns[c.id];
|
|
280
|
-
return __spreadProps(__spreadValues({}, c), { paraDetails: paraMetadata });
|
|
281
|
-
}
|
|
282
|
-
if (((_c = c.paraDetails) == null ? void 0 : _c.id) === "walletConnect" && walletConnectModalConnector) {
|
|
283
|
-
return __spreadProps(__spreadValues({}, c), { walletConnectModalConnector });
|
|
284
|
-
}
|
|
285
|
-
return c;
|
|
286
|
-
}).filter((c) => !!c);
|
|
287
|
-
const wallets = dedupedConnectors.map((c) => {
|
|
288
|
-
const connector = __spreadValues(__spreadValues({}, c), c.paraDetails);
|
|
289
|
-
return __spreadProps(__spreadValues({}, connector), {
|
|
290
|
-
connect: () => connect(connector),
|
|
291
|
-
connectMobile: ({ isManualWalletConnect }) => connectMobile(connector, isManualWalletConnect),
|
|
292
|
-
type: WalletType.EVM,
|
|
293
|
-
getQrUri: getQrUri(connector)
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
const getParaDetails = (id) => {
|
|
297
|
-
var _a;
|
|
298
|
-
return (_a = connectors.find((w) => w.id === id)) == null ? void 0 : _a.paraDetails;
|
|
299
|
-
};
|
|
300
|
-
const formattedChains = chains.map((c) => {
|
|
301
|
-
return {
|
|
302
|
-
id: c.id,
|
|
303
|
-
name: c.name
|
|
304
|
-
};
|
|
305
|
-
});
|
|
306
|
-
const username = useMemo(() => ensName != null ? ensName : wagmiAddress, [ensName, wagmiAddress]);
|
|
307
|
-
const disconnect = disconnectAsync;
|
|
308
|
-
return /* @__PURE__ */ jsx(
|
|
309
|
-
EvmExternalWalletContext.Provider,
|
|
310
|
-
{
|
|
311
|
-
value: useMemo(
|
|
312
|
-
() => ({
|
|
313
|
-
wallets,
|
|
314
|
-
chains: formattedChains,
|
|
315
|
-
chainId,
|
|
316
|
-
username,
|
|
317
|
-
avatar: ensAvatar,
|
|
318
|
-
balance,
|
|
319
|
-
disconnect,
|
|
320
|
-
switchChain,
|
|
321
|
-
signMessage,
|
|
322
|
-
signVerificationMessage
|
|
323
|
-
}),
|
|
324
|
-
[
|
|
325
|
-
wallets,
|
|
326
|
-
formattedChains,
|
|
327
|
-
chainId,
|
|
328
|
-
username,
|
|
329
|
-
ensAvatar,
|
|
330
|
-
balance,
|
|
331
|
-
disconnect,
|
|
332
|
-
switchChain,
|
|
333
|
-
signMessage,
|
|
334
|
-
signVerificationMessage
|
|
335
|
-
]
|
|
336
|
-
),
|
|
337
|
-
children
|
|
338
|
-
}
|
|
339
|
-
);
|
|
340
|
-
}
|
|
341
|
-
export {
|
|
342
|
-
EvmExternalWalletContext,
|
|
343
|
-
EvmExternalWalletProvider,
|
|
344
|
-
defaultEvmExternalWallet
|
|
345
|
-
};
|