@multiversx/sdk-dapp-liquidity 0.2.0-alpha.1
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 +186 -0
- package/all-networks-EJIVYZ_i.mjs +4 -0
- package/all-networks-NYACMyeN.js +4 -0
- package/api/confirmRate.d.ts +11 -0
- package/api/confirmRate.js +30 -0
- package/api/confirmRate.mjs +29 -0
- package/api/getChains.d.ts +6 -0
- package/api/getChains.js +12 -0
- package/api/getChains.mjs +11 -0
- package/api/getRate.d.ts +10 -0
- package/api/getRate.js +28 -0
- package/api/getRate.mjs +27 -0
- package/api/getTokens.d.ts +7 -0
- package/api/getTokens.js +14 -0
- package/api/getTokens.mjs +13 -0
- package/api/getTokensBalances.d.ts +8 -0
- package/api/getTokensBalances.js +17 -0
- package/api/getTokensBalances.mjs +16 -0
- package/api/getTransactions.d.ts +7 -0
- package/api/getTransactions.js +14 -0
- package/api/getTransactions.mjs +13 -0
- package/api/index.d.ts +7 -0
- package/api/index.js +17 -0
- package/api/index.mjs +16 -0
- package/api/sendTransactions.d.ts +11 -0
- package/api/sendTransactions.js +29 -0
- package/api/sendTransactions.mjs +28 -0
- package/api/tests/confirmRate.spec.d.ts +1 -0
- package/api/tests/confirmRate.spec.js +124 -0
- package/api/tests/confirmRate.spec.mjs +122 -0
- package/api/tests/getChains.spec.d.ts +1 -0
- package/api/tests/getChains.spec.js +37 -0
- package/api/tests/getChains.spec.mjs +35 -0
- package/api/tests/getRate.spec.d.ts +1 -0
- package/api/tests/getRate.spec.js +83 -0
- package/api/tests/getRate.spec.mjs +81 -0
- package/api/tests/getTokens.spec.d.ts +1 -0
- package/api/tests/getTokens.spec.js +60 -0
- package/api/tests/getTokens.spec.mjs +58 -0
- package/api/tests/getTransactions.spec.d.ts +1 -0
- package/api/tests/getTransactions.spec.js +89 -0
- package/api/tests/getTransactions.spec.mjs +87 -0
- package/api/tests/sendTransactions.spec.d.ts +1 -0
- package/api/tests/sendTransactions.spec.js +83 -0
- package/api/tests/sendTransactions.spec.mjs +81 -0
- package/bignumber-B8vjg9qn.js +1334 -0
- package/bignumber-CKZkoo0g.mjs +1334 -0
- package/constants/index.d.ts +1 -0
- package/constants/index.js +5 -0
- package/constants/index.mjs +4 -0
- package/default-BYtXv70Z.mjs +4 -0
- package/default-H3AbmzFV.js +4 -0
- package/dto/Chain.dto.d.ts +16 -0
- package/dto/Chain.dto.js +2 -0
- package/dto/Chain.dto.mjs +1 -0
- package/dto/ConfirmRate.dto.d.ts +11 -0
- package/dto/ConfirmRate.dto.js +2 -0
- package/dto/ConfirmRate.dto.mjs +1 -0
- package/dto/Token.dto.d.ts +14 -0
- package/dto/Token.dto.js +2 -0
- package/dto/Token.dto.mjs +1 -0
- package/dto/TokenBalance.dto.d.ts +4 -0
- package/dto/TokenBalance.dto.js +2 -0
- package/dto/TokenBalance.dto.mjs +1 -0
- package/dto/Transaction.dto.d.ts +14 -0
- package/dto/Transaction.dto.js +2 -0
- package/dto/Transaction.dto.mjs +1 -0
- package/dto/index.d.ts +5 -0
- package/dto/index.js +2 -0
- package/dto/index.mjs +1 -0
- package/helpers/base64Utils.d.ts +3 -0
- package/helpers/base64Utils.js +32 -0
- package/helpers/base64Utils.mjs +31 -0
- package/helpers/decodeLoginToken.d.ts +9 -0
- package/helpers/decodeLoginToken.js +28 -0
- package/helpers/decodeLoginToken.mjs +27 -0
- package/helpers/decodeToken.d.ts +11 -0
- package/helpers/decodeToken.js +40 -0
- package/helpers/decodeToken.mjs +39 -0
- package/helpers/getApiURL.d.ts +1 -0
- package/helpers/getApiURL.js +8 -0
- package/helpers/getApiURL.mjs +7 -0
- package/helpers/getBridgeURL.d.ts +1 -0
- package/helpers/getBridgeURL.js +8 -0
- package/helpers/getBridgeURL.mjs +7 -0
- package/helpers/getMvxApiURL.d.ts +1 -0
- package/helpers/getMvxApiURL.js +8 -0
- package/helpers/getMvxApiURL.mjs +7 -0
- package/helpers/getMvxChainId.d.ts +1 -0
- package/helpers/getMvxChainId.js +8 -0
- package/helpers/getMvxChainId.mjs +7 -0
- package/helpers/getMvxExplorerAddress.d.ts +1 -0
- package/helpers/getMvxExplorerAddress.js +8 -0
- package/helpers/getMvxExplorerAddress.mjs +7 -0
- package/helpers/index.d.ts +9 -0
- package/helpers/index.js +23 -0
- package/helpers/index.mjs +22 -0
- package/helpers/serializeTransaction.d.ts +3 -0
- package/helpers/serializeTransaction.js +9 -0
- package/helpers/serializeTransaction.mjs +8 -0
- package/helpers/tests/base64Utils.spec.d.ts +1 -0
- package/helpers/tests/base64Utils.spec.js +30 -0
- package/helpers/tests/base64Utils.spec.mjs +28 -0
- package/helpers/tests/decodeLoginToken.spec.d.ts +1 -0
- package/helpers/tests/decodeLoginToken.spec.js +35 -0
- package/helpers/tests/decodeLoginToken.spec.mjs +33 -0
- package/helpers/tests/decodeToken.spec.d.ts +1 -0
- package/helpers/tests/decodeToken.spec.js +28 -0
- package/helpers/tests/decodeToken.spec.mjs +26 -0
- package/index-B9WqxUXM.mjs +91 -0
- package/index-BXwpbIDQ.mjs +107 -0
- package/index-CnudU77V.js +329 -0
- package/index-DSnomXRI.mjs +68025 -0
- package/index-DZHiA1sX.js +107 -0
- package/index-cvy2-uZ_.js +67946 -0
- package/index.d.ts +6 -0
- package/index.js +189 -0
- package/index.mjs +185 -0
- package/package.json +107 -0
- package/react-B9sQBOh0.mjs +3040 -0
- package/react-BaXyw3AO.js +3040 -0
- package/react-CNXJSTCv.js +38 -0
- package/react-CSQpf1zk.mjs +38 -0
- package/reactjs/components/AccountAddress/AccountAddress.d.ts +6 -0
- package/reactjs/components/AccountAddress/AccountAddress.js +25 -0
- package/reactjs/components/AccountAddress/AccountAddress.mjs +24 -0
- package/reactjs/components/AccountAddress/index.d.ts +1 -0
- package/reactjs/components/AccountAddress/index.js +5 -0
- package/reactjs/components/AccountAddress/index.mjs +4 -0
- package/reactjs/components/AmountCard/AmountCard.d.ts +6 -0
- package/reactjs/components/AmountCard/AmountCard.js +33 -0
- package/reactjs/components/AmountCard/AmountCard.mjs +32 -0
- package/reactjs/components/AmountCard/index.d.ts +1 -0
- package/reactjs/components/AmountCard/index.js +5 -0
- package/reactjs/components/AmountCard/index.mjs +4 -0
- package/reactjs/components/AmountInput/AmountInput.d.ts +13 -0
- package/reactjs/components/AmountInput/AmountInput.js +61 -0
- package/reactjs/components/AmountInput/AmountInput.mjs +60 -0
- package/reactjs/components/AmountInput/index.d.ts +1 -0
- package/reactjs/components/AmountInput/index.js +5 -0
- package/reactjs/components/AmountInput/index.mjs +4 -0
- package/reactjs/components/BridgeForm/BridgeForm.d.ts +16 -0
- package/reactjs/components/BridgeForm/BridgeForm.js +680 -0
- package/reactjs/components/BridgeForm/BridgeForm.mjs +679 -0
- package/reactjs/components/BridgeForm/index.d.ts +1 -0
- package/reactjs/components/BridgeForm/index.js +5 -0
- package/reactjs/components/BridgeForm/index.mjs +4 -0
- package/reactjs/components/BridgeHistory/BridgeHistory.d.ts +4 -0
- package/reactjs/components/BridgeHistory/BridgeHistory.js +233 -0
- package/reactjs/components/BridgeHistory/BridgeHistory.mjs +232 -0
- package/reactjs/components/BridgeHistory/index.d.ts +1 -0
- package/reactjs/components/BridgeHistory/index.js +5 -0
- package/reactjs/components/BridgeHistory/index.mjs +4 -0
- package/reactjs/components/Connect/BridgeAccountDisplay.d.ts +6 -0
- package/reactjs/components/Connect/BridgeAccountDisplay.js +85 -0
- package/reactjs/components/Connect/BridgeAccountDisplay.mjs +84 -0
- package/reactjs/components/Connect/BridgeConnectButton.d.ts +7 -0
- package/reactjs/components/Connect/BridgeConnectButton.js +26 -0
- package/reactjs/components/Connect/BridgeConnectButton.mjs +25 -0
- package/reactjs/components/Connect/CustomConnectButton.d.ts +7 -0
- package/reactjs/components/Connect/CustomConnectButton.js +42 -0
- package/reactjs/components/Connect/CustomConnectButton.mjs +41 -0
- package/reactjs/components/Connect/MvxAccountDisplay.d.ts +9 -0
- package/reactjs/components/Connect/MvxAccountDisplay.js +75 -0
- package/reactjs/components/Connect/MvxAccountDisplay.mjs +74 -0
- package/reactjs/components/Connect/MvxConnectButton.d.ts +11 -0
- package/reactjs/components/Connect/MvxConnectButton.js +43 -0
- package/reactjs/components/Connect/MvxConnectButton.mjs +42 -0
- package/reactjs/components/Connect/SwitchChainButton.d.ts +7 -0
- package/reactjs/components/Connect/SwitchChainButton.js +33 -0
- package/reactjs/components/Connect/SwitchChainButton.mjs +32 -0
- package/reactjs/components/Connect/index.d.ts +6 -0
- package/reactjs/components/Connect/index.js +15 -0
- package/reactjs/components/Connect/index.mjs +14 -0
- package/reactjs/components/CopyButton/CopyButton.d.ts +6 -0
- package/reactjs/components/CopyButton/CopyButton.js +42 -0
- package/reactjs/components/CopyButton/CopyButton.mjs +41 -0
- package/reactjs/components/CopyButton/index.d.ts +1 -0
- package/reactjs/components/CopyButton/index.js +5 -0
- package/reactjs/components/CopyButton/index.mjs +4 -0
- package/reactjs/components/CopyButton/utils/copyToClipboard.d.ts +1 -0
- package/reactjs/components/CopyButton/utils/copyToClipboard.js +38 -0
- package/reactjs/components/CopyButton/utils/copyToClipboard.mjs +37 -0
- package/reactjs/components/CopyButton/utils/index.d.ts +1 -0
- package/reactjs/components/CopyButton/utils/index.js +5 -0
- package/reactjs/components/CopyButton/utils/index.mjs +4 -0
- package/reactjs/components/DisplayAmount/DisplayAmount.d.ts +21 -0
- package/reactjs/components/DisplayAmount/DisplayAmount.js +91 -0
- package/reactjs/components/DisplayAmount/DisplayAmount.mjs +90 -0
- package/reactjs/components/DisplayAmount/components/AnimateNumber/AnimateNumber.d.ts +7 -0
- package/reactjs/components/DisplayAmount/components/AnimateNumber/AnimateNumber.js +40 -0
- package/reactjs/components/DisplayAmount/components/AnimateNumber/AnimateNumber.mjs +39 -0
- package/reactjs/components/DisplayAmount/components/AnimateNumber/index.d.ts +0 -0
- package/reactjs/components/DisplayAmount/components/AnimateNumber/index.js +2 -0
- package/reactjs/components/DisplayAmount/components/AnimateNumber/index.mjs +1 -0
- package/reactjs/components/DisplayAmount/components/PrecisedAmount/PrecisedAmount.d.ts +14 -0
- package/reactjs/components/DisplayAmount/components/PrecisedAmount/PrecisedAmount.js +62 -0
- package/reactjs/components/DisplayAmount/components/PrecisedAmount/PrecisedAmount.mjs +61 -0
- package/reactjs/components/DisplayAmount/components/index.d.ts +0 -0
- package/reactjs/components/DisplayAmount/components/index.js +2 -0
- package/reactjs/components/DisplayAmount/components/index.mjs +1 -0
- package/reactjs/components/DisplayAmount/index.d.ts +1 -0
- package/reactjs/components/DisplayAmount/index.js +5 -0
- package/reactjs/components/DisplayAmount/index.mjs +4 -0
- package/reactjs/components/DisplayAmount/utils/index.d.ts +1 -0
- package/reactjs/components/DisplayAmount/utils/index.js +5 -0
- package/reactjs/components/DisplayAmount/utils/index.mjs +4 -0
- package/reactjs/components/DisplayAmount/utils/truncateAmount.d.ts +1 -0
- package/reactjs/components/DisplayAmount/utils/truncateAmount.js +22 -0
- package/reactjs/components/DisplayAmount/utils/truncateAmount.mjs +21 -0
- package/reactjs/components/SmallLoader/SmallLoader.d.ts +4 -0
- package/reactjs/components/SmallLoader/SmallLoader.js +22 -0
- package/reactjs/components/SmallLoader/SmallLoader.mjs +21 -0
- package/reactjs/components/SmallLoader/index.d.ts +1 -0
- package/reactjs/components/SmallLoader/index.js +5 -0
- package/reactjs/components/SmallLoader/index.mjs +4 -0
- package/reactjs/components/TokenSelector/TokenSelector.d.ts +16 -0
- package/reactjs/components/TokenSelector/TokenSelector.js +158 -0
- package/reactjs/components/TokenSelector/TokenSelector.mjs +157 -0
- package/reactjs/components/TokenSelector/components/ChainSelect/ChainSelect.d.ts +8 -0
- package/reactjs/components/TokenSelector/components/ChainSelect/ChainSelect.js +86 -0
- package/reactjs/components/TokenSelector/components/ChainSelect/ChainSelect.mjs +85 -0
- package/reactjs/components/TokenSelector/components/ChainSelect/components/ChainOptionLabel.d.ts +11 -0
- package/reactjs/components/TokenSelector/components/ChainSelect/components/ChainOptionLabel.js +45 -0
- package/reactjs/components/TokenSelector/components/ChainSelect/components/ChainOptionLabel.mjs +44 -0
- package/reactjs/components/TokenSelector/components/ChainSelect/components/FormatChainOptionLabel.d.ts +6 -0
- package/reactjs/components/TokenSelector/components/ChainSelect/components/FormatChainOptionLabel.js +19 -0
- package/reactjs/components/TokenSelector/components/ChainSelect/components/FormatChainOptionLabel.mjs +18 -0
- package/reactjs/components/TokenSelector/components/ChainSelect/components/IndicatorSeparator.d.ts +3 -0
- package/reactjs/components/TokenSelector/components/ChainSelect/components/IndicatorSeparator.js +7 -0
- package/reactjs/components/TokenSelector/components/ChainSelect/components/IndicatorSeparator.mjs +6 -0
- package/reactjs/components/TokenSelector/components/ChainSelect/components/SelectedChainOption.d.ts +4 -0
- package/reactjs/components/TokenSelector/components/ChainSelect/components/SelectedChainOption.js +33 -0
- package/reactjs/components/TokenSelector/components/ChainSelect/components/SelectedChainOption.mjs +32 -0
- package/reactjs/components/TokenSelector/components/ChainSelect/types/chainSelectOption.d.ts +10 -0
- package/reactjs/components/TokenSelector/components/ChainSelect/types/chainSelectOption.js +2 -0
- package/reactjs/components/TokenSelector/components/ChainSelect/types/chainSelectOption.mjs +1 -0
- package/reactjs/components/TokenSelector/components/ChainSelect/types/partialChainOption.d.ts +10 -0
- package/reactjs/components/TokenSelector/components/ChainSelect/types/partialChainOption.js +2 -0
- package/reactjs/components/TokenSelector/components/ChainSelect/types/partialChainOption.mjs +1 -0
- package/reactjs/components/TokenSelector/components/SelectContainer.d.ts +7 -0
- package/reactjs/components/TokenSelector/components/SelectContainer.js +41 -0
- package/reactjs/components/TokenSelector/components/SelectContainer.mjs +40 -0
- package/reactjs/components/TokenSelector/components/SelectContent.d.ts +10 -0
- package/reactjs/components/TokenSelector/components/SelectContent.js +93 -0
- package/reactjs/components/TokenSelector/components/SelectContent.mjs +92 -0
- package/reactjs/components/TokenSelector/components/SelectedOption.d.ts +5 -0
- package/reactjs/components/TokenSelector/components/SelectedOption.js +29 -0
- package/reactjs/components/TokenSelector/components/SelectedOption.mjs +28 -0
- package/reactjs/components/TokenSelector/components/TokenIcon.d.ts +8 -0
- package/reactjs/components/TokenSelector/components/TokenIcon.js +82 -0
- package/reactjs/components/TokenSelector/components/TokenIcon.mjs +81 -0
- package/reactjs/components/TokenSelector/components/TokenItem.d.ts +7 -0
- package/reactjs/components/TokenSelector/components/TokenItem.js +69 -0
- package/reactjs/components/TokenSelector/components/TokenItem.mjs +68 -0
- package/reactjs/components/TokenSelector/components/TokenList.d.ts +7 -0
- package/reactjs/components/TokenSelector/components/TokenList.js +21 -0
- package/reactjs/components/TokenSelector/components/TokenList.mjs +20 -0
- package/reactjs/components/TokenSelector/components/TokenSymbol.d.ts +9 -0
- package/reactjs/components/TokenSelector/components/TokenSymbol.js +26 -0
- package/reactjs/components/TokenSelector/components/TokenSymbol.mjs +25 -0
- package/reactjs/components/TokenSelector/index.d.ts +1 -0
- package/reactjs/components/TokenSelector/index.js +5 -0
- package/reactjs/components/TokenSelector/index.mjs +4 -0
- package/reactjs/components/TransactionToast/TransactionToast.d.ts +9 -0
- package/reactjs/components/TransactionToast/TransactionToast.js +54 -0
- package/reactjs/components/TransactionToast/TransactionToast.mjs +53 -0
- package/reactjs/components/TransactionToast/TransactionToastContainer.d.ts +3 -0
- package/reactjs/components/TransactionToast/TransactionToastContainer.js +21 -0
- package/reactjs/components/TransactionToast/TransactionToastContainer.mjs +20 -0
- package/reactjs/components/TransactionToast/index.d.ts +2 -0
- package/reactjs/components/TransactionToast/index.js +7 -0
- package/reactjs/components/TransactionToast/index.mjs +6 -0
- package/reactjs/components/TrimAddress/TrimAddress.d.ts +8 -0
- package/reactjs/components/TrimAddress/TrimAddress.js +26 -0
- package/reactjs/components/TrimAddress/TrimAddress.mjs +25 -0
- package/reactjs/components/TrimAddress/index.d.ts +1 -0
- package/reactjs/components/TrimAddress/index.js +5 -0
- package/reactjs/components/TrimAddress/index.mjs +4 -0
- package/reactjs/components/base/MxButton/MxButton.d.ts +13 -0
- package/reactjs/components/base/MxButton/MxButton.js +72 -0
- package/reactjs/components/base/MxButton/MxButton.mjs +71 -0
- package/reactjs/components/base/MxButton/index.d.ts +1 -0
- package/reactjs/components/base/MxButton/index.js +5 -0
- package/reactjs/components/base/MxButton/index.mjs +4 -0
- package/reactjs/components/base/MxCard/MxCard.d.ts +10 -0
- package/reactjs/components/base/MxCard/MxCard.js +55 -0
- package/reactjs/components/base/MxCard/MxCard.mjs +54 -0
- package/reactjs/components/base/MxCard/index.d.ts +1 -0
- package/reactjs/components/base/MxCard/index.js +5 -0
- package/reactjs/components/base/MxCard/index.mjs +4 -0
- package/reactjs/components/base/MxLink/MxLink.d.ts +10 -0
- package/reactjs/components/base/MxLink/MxLink.js +71 -0
- package/reactjs/components/base/MxLink/MxLink.mjs +70 -0
- package/reactjs/components/base/MxLink/index.d.ts +1 -0
- package/reactjs/components/base/MxLink/index.js +5 -0
- package/reactjs/components/base/MxLink/index.mjs +4 -0
- package/reactjs/components/base/MxSearch/MxSearch.d.ts +10 -0
- package/reactjs/components/base/MxSearch/MxSearch.js +70 -0
- package/reactjs/components/base/MxSearch/MxSearch.mjs +69 -0
- package/reactjs/components/base/MxSearch/index.d.ts +1 -0
- package/reactjs/components/base/MxSearch/index.js +5 -0
- package/reactjs/components/base/MxSearch/index.mjs +4 -0
- package/reactjs/components/base/MxSlideover/MxSlideover.d.ts +10 -0
- package/reactjs/components/base/MxSlideover/MxSlideover.js +79 -0
- package/reactjs/components/base/MxSlideover/MxSlideover.mjs +78 -0
- package/reactjs/components/base/MxSlideover/index.d.ts +1 -0
- package/reactjs/components/base/MxSlideover/index.js +5 -0
- package/reactjs/components/base/MxSlideover/index.mjs +4 -0
- package/reactjs/components/base/MxTooltip/MxTooltip.d.ts +23 -0
- package/reactjs/components/base/MxTooltip/MxTooltip.js +163 -0
- package/reactjs/components/base/MxTooltip/MxTooltip.mjs +162 -0
- package/reactjs/components/base/MxTooltip/components/TooltipContainer/TooltipContainer.d.ts +11 -0
- package/reactjs/components/base/MxTooltip/components/TooltipContainer/TooltipContainer.js +34 -0
- package/reactjs/components/base/MxTooltip/components/TooltipContainer/TooltipContainer.mjs +33 -0
- package/reactjs/components/base/MxTooltip/components/TooltipContainer/index.d.ts +1 -0
- package/reactjs/components/base/MxTooltip/components/TooltipContainer/index.js +5 -0
- package/reactjs/components/base/MxTooltip/components/TooltipContainer/index.mjs +4 -0
- package/reactjs/components/base/MxTooltip/components/TooltipContent/TooltipContent.d.ts +13 -0
- package/reactjs/components/base/MxTooltip/components/TooltipContent/TooltipContent.js +28 -0
- package/reactjs/components/base/MxTooltip/components/TooltipContent/TooltipContent.mjs +27 -0
- package/reactjs/components/base/MxTooltip/components/TooltipContent/index.d.ts +1 -0
- package/reactjs/components/base/MxTooltip/components/TooltipContent/index.js +5 -0
- package/reactjs/components/base/MxTooltip/components/TooltipContent/index.mjs +4 -0
- package/reactjs/components/base/MxTooltip/components/index.d.ts +2 -0
- package/reactjs/components/base/MxTooltip/components/index.js +7 -0
- package/reactjs/components/base/MxTooltip/components/index.mjs +6 -0
- package/reactjs/components/base/MxTooltip/index.d.ts +1 -0
- package/reactjs/components/base/MxTooltip/index.js +5 -0
- package/reactjs/components/base/MxTooltip/index.mjs +4 -0
- package/reactjs/components/base/index.d.ts +6 -0
- package/reactjs/components/base/index.js +15 -0
- package/reactjs/components/base/index.mjs +14 -0
- package/reactjs/components/index.d.ts +13 -0
- package/reactjs/components/index.js +51 -0
- package/reactjs/components/index.mjs +50 -0
- package/reactjs/constants/chains.d.ts +35 -0
- package/reactjs/constants/chains.js +38 -0
- package/reactjs/constants/chains.mjs +37 -0
- package/reactjs/constants/index.d.ts +3 -0
- package/reactjs/constants/index.js +12 -0
- package/reactjs/constants/index.mjs +11 -0
- package/reactjs/context/Web3AppProvider.d.ts +12 -0
- package/reactjs/context/Web3AppProvider.js +29 -0
- package/reactjs/context/Web3AppProvider.mjs +28 -0
- package/reactjs/context/queryClient.d.ts +3 -0
- package/reactjs/context/queryClient.js +12 -0
- package/reactjs/context/queryClient.mjs +11 -0
- package/reactjs/context/useWeb3App.d.ts +1 -0
- package/reactjs/context/useWeb3App.js +13 -0
- package/reactjs/context/useWeb3App.mjs +12 -0
- package/reactjs/hooks/index.d.ts +11 -0
- package/reactjs/hooks/index.js +32 -0
- package/reactjs/hooks/index.mjs +31 -0
- package/reactjs/hooks/useAccount.d.ts +77 -0
- package/reactjs/hooks/useAccount.js +18 -0
- package/reactjs/hooks/useAccount.mjs +17 -0
- package/reactjs/hooks/useBalances.d.ts +10 -0
- package/reactjs/hooks/useBalances.js +7 -0
- package/reactjs/hooks/useBalances.mjs +6 -0
- package/reactjs/hooks/useBridgeFormik.d.ts +98 -0
- package/reactjs/hooks/useBridgeFormik.js +182 -0
- package/reactjs/hooks/useBridgeFormik.mjs +181 -0
- package/reactjs/hooks/useDebounce.d.ts +1 -0
- package/reactjs/hooks/useDebounce.js +14 -0
- package/reactjs/hooks/useDebounce.mjs +13 -0
- package/reactjs/hooks/useFetchBridgeData.d.ts +45 -0
- package/reactjs/hooks/useFetchBridgeData.js +44 -0
- package/reactjs/hooks/useFetchBridgeData.mjs +43 -0
- package/reactjs/hooks/useFetchTokens.d.ts +42 -0
- package/reactjs/hooks/useFetchTokens.js +105 -0
- package/reactjs/hooks/useFetchTokens.mjs +104 -0
- package/reactjs/hooks/useGetChainId.d.ts +1 -0
- package/reactjs/hooks/useGetChainId.js +12 -0
- package/reactjs/hooks/useGetChainId.mjs +11 -0
- package/reactjs/hooks/useResolveTokenChain.d.ts +9 -0
- package/reactjs/hooks/useResolveTokenChain.js +21 -0
- package/reactjs/hooks/useResolveTokenChain.mjs +20 -0
- package/reactjs/hooks/useSendTransactions.d.ts +3 -0
- package/reactjs/hooks/useSendTransactions.js +19 -0
- package/reactjs/hooks/useSendTransactions.mjs +18 -0
- package/reactjs/hooks/useSignTransaction.d.ts +69 -0
- package/reactjs/hooks/useSignTransaction.js +17 -0
- package/reactjs/hooks/useSignTransaction.mjs +16 -0
- package/reactjs/hooks/validation/index.d.ts +4 -0
- package/reactjs/hooks/validation/index.js +11 -0
- package/reactjs/hooks/validation/index.mjs +10 -0
- package/reactjs/hooks/validation/useAmountSchema.d.ts +2 -0
- package/reactjs/hooks/validation/useAmountSchema.js +31 -0
- package/reactjs/hooks/validation/useAmountSchema.mjs +13 -0
- package/reactjs/hooks/validation/useSecondAmountSchema.d.ts +2 -0
- package/reactjs/hooks/validation/useSecondAmountSchema.js +27 -0
- package/reactjs/hooks/validation/useSecondAmountSchema.mjs +9 -0
- package/reactjs/hooks/validation/useTestHasEnoughFunds.d.ts +3 -0
- package/reactjs/hooks/validation/useTestHasEnoughFunds.js +38 -0
- package/reactjs/hooks/validation/useTestHasEnoughFunds.mjs +37 -0
- package/reactjs/hooks/validation/useTestIsConnected.d.ts +3 -0
- package/reactjs/hooks/validation/useTestIsConnected.js +21 -0
- package/reactjs/hooks/validation/useTestIsConnected.mjs +20 -0
- package/reactjs/index.d.ts +10 -0
- package/reactjs/index.js +153 -0
- package/reactjs/index.mjs +149 -0
- package/reactjs/init/index.d.ts +1 -0
- package/reactjs/init/index.js +5 -0
- package/reactjs/init/index.mjs +4 -0
- package/reactjs/init/init.d.ts +48 -0
- package/reactjs/init/init.js +53 -0
- package/reactjs/init/init.mjs +35 -0
- package/reactjs/init/tests/init.spec.d.ts +1 -0
- package/reactjs/init/tests/init.spec.js +108 -0
- package/reactjs/init/tests/init.spec.mjs +106 -0
- package/reactjs/queries/index.d.ts +7 -0
- package/reactjs/queries/index.js +20 -0
- package/reactjs/queries/index.mjs +19 -0
- package/reactjs/queries/useGetAllTokens.query.d.ts +3 -0
- package/reactjs/queries/useGetAllTokens.query.js +31 -0
- package/reactjs/queries/useGetAllTokens.query.mjs +30 -0
- package/reactjs/queries/useGetChains.query.d.ts +3 -0
- package/reactjs/queries/useGetChains.query.js +31 -0
- package/reactjs/queries/useGetChains.query.mjs +30 -0
- package/reactjs/queries/useGetEvmTokensBalances.query.d.ts +22 -0
- package/reactjs/queries/useGetEvmTokensBalances.query.js +78 -0
- package/reactjs/queries/useGetEvmTokensBalances.query.mjs +77 -0
- package/reactjs/queries/useGetHistory.query.d.ts +4 -0
- package/reactjs/queries/useGetHistory.query.js +47 -0
- package/reactjs/queries/useGetHistory.query.mjs +46 -0
- package/reactjs/queries/useGetMvxTokensBalances.query.d.ts +23 -0
- package/reactjs/queries/useGetMvxTokensBalances.query.js +60 -0
- package/reactjs/queries/useGetMvxTokensBalances.query.mjs +59 -0
- package/reactjs/queries/useGetRate.mutation.d.ts +6 -0
- package/reactjs/queries/useGetRate.mutation.js +19 -0
- package/reactjs/queries/useGetRate.mutation.mjs +18 -0
- package/reactjs/queries/useGetTokens.query.d.ts +3 -0
- package/reactjs/queries/useGetTokens.query.js +34 -0
- package/reactjs/queries/useGetTokens.query.mjs +33 -0
- package/reactjs/reexports.d.ts +6 -0
- package/reactjs/reexports.js +21 -0
- package/reactjs/reexports.mjs +17 -0
- package/reactjs/utils/delay.d.ts +1 -0
- package/reactjs/utils/delay.js +7 -0
- package/reactjs/utils/delay.mjs +6 -0
- package/reactjs/utils/formatAmount.d.ts +7 -0
- package/reactjs/utils/formatAmount.js +24 -0
- package/reactjs/utils/formatAmount.mjs +23 -0
- package/reactjs/utils/getCleanStringAmount.d.ts +4 -0
- package/reactjs/utils/getCleanStringAmount.js +12 -0
- package/reactjs/utils/getCleanStringAmount.mjs +11 -0
- package/reactjs/utils/getCompletePathname.d.ts +1 -0
- package/reactjs/utils/getCompletePathname.js +6 -0
- package/reactjs/utils/getCompletePathname.mjs +5 -0
- package/reactjs/utils/getInitialTokens.d.ts +8 -0
- package/reactjs/utils/getInitialTokens.js +13 -0
- package/reactjs/utils/getInitialTokens.mjs +12 -0
- package/reactjs/utils/hasEnoughFunds.d.ts +5 -0
- package/reactjs/utils/hasEnoughFunds.js +20 -0
- package/reactjs/utils/hasEnoughFunds.mjs +19 -0
- package/reactjs/utils/index.d.ts +12 -0
- package/reactjs/utils/index.js +27 -0
- package/reactjs/utils/index.mjs +26 -0
- package/reactjs/utils/isStringFloat.d.ts +1 -0
- package/reactjs/utils/isStringFloat.js +22 -0
- package/reactjs/utils/isStringFloat.mjs +21 -0
- package/reactjs/utils/mxClsx.d.ts +3 -0
- package/reactjs/utils/mxClsx.js +21 -0
- package/reactjs/utils/mxClsx.mjs +20 -0
- package/reactjs/utils/pipe.d.ts +7 -0
- package/reactjs/utils/pipe.js +26 -0
- package/reactjs/utils/pipe.mjs +25 -0
- package/reactjs/utils/removeCommas.d.ts +1 -0
- package/reactjs/utils/removeCommas.js +7 -0
- package/reactjs/utils/removeCommas.mjs +6 -0
- package/reactjs/utils/roundAmount.d.ts +1 -0
- package/reactjs/utils/roundAmount.js +41 -0
- package/reactjs/utils/roundAmount.mjs +40 -0
- package/reactjs/utils/testNumber.d.ts +1 -0
- package/reactjs/utils/testNumber.js +5 -0
- package/reactjs/utils/testNumber.mjs +4 -0
- package/store/inMemoryStore.d.ts +12 -0
- package/store/inMemoryStore.js +40 -0
- package/store/inMemoryStore.mjs +39 -0
- package/types/batchTransactions.d.ts +6 -0
- package/types/batchTransactions.js +2 -0
- package/types/batchTransactions.mjs +1 -0
- package/types/index.d.ts +4 -0
- package/types/index.js +2 -0
- package/types/index.mjs +1 -0
- package/types/rate.d.ts +11 -0
- package/types/rate.js +2 -0
- package/types/rate.mjs +1 -0
- package/types/token.d.ts +12 -0
- package/types/token.js +2 -0
- package/types/token.mjs +1 -0
- package/types/transaction.d.ts +14 -0
- package/types/transaction.js +2 -0
- package/types/transaction.mjs +1 -0
- package/useBalances-Bxtc4GNK.js +199 -0
- package/useBalances-DA3zEruz.mjs +199 -0
- package/w3m-modal-DCcF1qEB.js +356 -0
- package/w3m-modal-DK3G5GJp.mjs +356 -0
|
@@ -0,0 +1,3040 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
const index = require("./index-cvy2-uZ_.js");
|
|
4
|
+
const react = require("./react-CNXJSTCv.js");
|
|
5
|
+
const viem = require("viem");
|
|
6
|
+
require("viem/chains");
|
|
7
|
+
const index$1 = require("./index-DZHiA1sX.js");
|
|
8
|
+
const ParseUtil = {
|
|
9
|
+
validateCaipAddress(address) {
|
|
10
|
+
var _a;
|
|
11
|
+
if (((_a = address.split(":")) == null ? void 0 : _a.length) !== 3) {
|
|
12
|
+
throw new Error("Invalid CAIP Address");
|
|
13
|
+
}
|
|
14
|
+
return address;
|
|
15
|
+
},
|
|
16
|
+
parseCaipAddress(caipAddress) {
|
|
17
|
+
const parts = caipAddress.split(":");
|
|
18
|
+
if (parts.length !== 3) {
|
|
19
|
+
throw new Error(`Invalid CAIP-10 address: ${caipAddress}`);
|
|
20
|
+
}
|
|
21
|
+
const [chainNamespace, chainId, address] = parts;
|
|
22
|
+
if (!chainNamespace || !chainId || !address) {
|
|
23
|
+
throw new Error(`Invalid CAIP-10 address: ${caipAddress}`);
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
chainNamespace,
|
|
27
|
+
chainId,
|
|
28
|
+
address
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
parseCaipNetworkId(caipNetworkId) {
|
|
32
|
+
const parts = caipNetworkId.split(":");
|
|
33
|
+
if (parts.length !== 2) {
|
|
34
|
+
throw new Error(`Invalid CAIP-2 network id: ${caipNetworkId}`);
|
|
35
|
+
}
|
|
36
|
+
const [chainNamespace, chainId] = parts;
|
|
37
|
+
if (!chainNamespace || !chainId) {
|
|
38
|
+
throw new Error(`Invalid CAIP-2 network id: ${caipNetworkId}`);
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
chainNamespace,
|
|
42
|
+
chainId
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
function shouldHandleEvent(eventKey, data = {}) {
|
|
47
|
+
var _a;
|
|
48
|
+
return typeof (data == null ? void 0 : data.type) === "string" && ((_a = data == null ? void 0 : data.type) == null ? void 0 : _a.includes(eventKey));
|
|
49
|
+
}
|
|
50
|
+
class W3mFrame {
|
|
51
|
+
constructor({ projectId, isAppClient = false, chainId = "eip155:1", enableLogger = true }) {
|
|
52
|
+
this.iframe = null;
|
|
53
|
+
this.rpcUrl = index.ConstantsUtil.BLOCKCHAIN_API_RPC_URL;
|
|
54
|
+
this.initFrame = () => {
|
|
55
|
+
const isFrameInitialized = document.getElementById("w3m-iframe");
|
|
56
|
+
if (this.iframe && !isFrameInitialized) {
|
|
57
|
+
document.body.appendChild(this.iframe);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
this.events = {
|
|
61
|
+
registerFrameEventHandler: (id, callback, signal) => {
|
|
62
|
+
function eventHandler({ data }) {
|
|
63
|
+
if (!shouldHandleEvent(index.W3mFrameConstants.FRAME_EVENT_KEY, data)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const frameEvent = index.W3mFrameSchema.frameEvent.parse(data);
|
|
67
|
+
if (frameEvent.id === id) {
|
|
68
|
+
callback(frameEvent);
|
|
69
|
+
window.removeEventListener("message", eventHandler);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (index.W3mFrameHelpers.isClient) {
|
|
73
|
+
window.addEventListener("message", eventHandler);
|
|
74
|
+
signal.addEventListener("abort", () => {
|
|
75
|
+
window.removeEventListener("message", eventHandler);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
onFrameEvent: (callback) => {
|
|
80
|
+
if (index.W3mFrameHelpers.isClient) {
|
|
81
|
+
window.addEventListener("message", ({ data }) => {
|
|
82
|
+
if (!shouldHandleEvent(index.W3mFrameConstants.FRAME_EVENT_KEY, data)) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const frameEvent = index.W3mFrameSchema.frameEvent.parse(data);
|
|
86
|
+
callback(frameEvent);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
onAppEvent: (callback) => {
|
|
91
|
+
if (index.W3mFrameHelpers.isClient) {
|
|
92
|
+
window.addEventListener("message", ({ data }) => {
|
|
93
|
+
if (!shouldHandleEvent(index.W3mFrameConstants.APP_EVENT_KEY, data)) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const appEvent = index.W3mFrameSchema.appEvent.parse(data);
|
|
97
|
+
callback(appEvent);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
postAppEvent: (event) => {
|
|
102
|
+
var _a;
|
|
103
|
+
if (index.W3mFrameHelpers.isClient) {
|
|
104
|
+
if (!((_a = this.iframe) == null ? void 0 : _a.contentWindow)) {
|
|
105
|
+
throw new Error("W3mFrame: iframe is not set");
|
|
106
|
+
}
|
|
107
|
+
index.W3mFrameSchema.appEvent.parse(event);
|
|
108
|
+
this.iframe.contentWindow.postMessage(event, "*");
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
postFrameEvent: (event) => {
|
|
112
|
+
if (index.W3mFrameHelpers.isClient) {
|
|
113
|
+
if (!parent) {
|
|
114
|
+
throw new Error("W3mFrame: parent is not set");
|
|
115
|
+
}
|
|
116
|
+
index.W3mFrameSchema.frameEvent.parse(event);
|
|
117
|
+
parent.postMessage(event, "*");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
this.projectId = projectId;
|
|
122
|
+
this.frameLoadPromise = new Promise((resolve, reject) => {
|
|
123
|
+
this.frameLoadPromiseResolver = { resolve, reject };
|
|
124
|
+
});
|
|
125
|
+
if (isAppClient) {
|
|
126
|
+
this.frameLoadPromise = new Promise((resolve, reject) => {
|
|
127
|
+
this.frameLoadPromiseResolver = { resolve, reject };
|
|
128
|
+
});
|
|
129
|
+
if (index.W3mFrameHelpers.isClient) {
|
|
130
|
+
const iframe = document.createElement("iframe");
|
|
131
|
+
iframe.id = "w3m-iframe";
|
|
132
|
+
iframe.src = `${index.SECURE_SITE_SDK}?projectId=${projectId}&chainId=${chainId}&version=${index.SECURE_SITE_SDK_VERSION}&enableLogger=${enableLogger}`;
|
|
133
|
+
iframe.name = "w3m-secure-iframe";
|
|
134
|
+
iframe.style.position = "fixed";
|
|
135
|
+
iframe.style.zIndex = "999999";
|
|
136
|
+
iframe.style.display = "none";
|
|
137
|
+
iframe.style.animationDelay = "0s, 50ms";
|
|
138
|
+
iframe.style.borderBottomLeftRadius = `clamp(0px, var(--wui-border-radius-l), 44px)`;
|
|
139
|
+
iframe.style.borderBottomRightRadius = `clamp(0px, var(--wui-border-radius-l), 44px)`;
|
|
140
|
+
this.iframe = iframe;
|
|
141
|
+
this.iframe.onerror = () => {
|
|
142
|
+
var _a;
|
|
143
|
+
(_a = this.frameLoadPromiseResolver) == null ? void 0 : _a.reject("Unable to load email login dependency");
|
|
144
|
+
};
|
|
145
|
+
this.events.onFrameEvent((event) => {
|
|
146
|
+
var _a;
|
|
147
|
+
if (event.type === "@w3m-frame/READY") {
|
|
148
|
+
(_a = this.frameLoadPromiseResolver) == null ? void 0 : _a.resolve(void 0);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
get networks() {
|
|
155
|
+
const data = [
|
|
156
|
+
"eip155:1",
|
|
157
|
+
"eip155:5",
|
|
158
|
+
"eip155:11155111",
|
|
159
|
+
"eip155:10",
|
|
160
|
+
"eip155:420",
|
|
161
|
+
"eip155:42161",
|
|
162
|
+
"eip155:421613",
|
|
163
|
+
"eip155:137",
|
|
164
|
+
"eip155:80001",
|
|
165
|
+
"eip155:42220",
|
|
166
|
+
"eip155:1313161554",
|
|
167
|
+
"eip155:1313161555",
|
|
168
|
+
"eip155:56",
|
|
169
|
+
"eip155:97",
|
|
170
|
+
"eip155:43114",
|
|
171
|
+
"eip155:43113",
|
|
172
|
+
"eip155:324",
|
|
173
|
+
"eip155:280",
|
|
174
|
+
"eip155:100",
|
|
175
|
+
"eip155:8453",
|
|
176
|
+
"eip155:84531",
|
|
177
|
+
"eip155:84532",
|
|
178
|
+
"eip155:7777777",
|
|
179
|
+
"eip155:999",
|
|
180
|
+
"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
|
|
181
|
+
"solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z",
|
|
182
|
+
"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"
|
|
183
|
+
].map((id) => ({
|
|
184
|
+
[id]: {
|
|
185
|
+
rpcUrl: `${this.rpcUrl}/v1/?chainId=${id}&projectId=${this.projectId}`,
|
|
186
|
+
chainId: id
|
|
187
|
+
}
|
|
188
|
+
}));
|
|
189
|
+
return Object.assign({}, ...data);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
class W3mFrameLogger {
|
|
193
|
+
constructor(projectId) {
|
|
194
|
+
var _a;
|
|
195
|
+
const loggerOptions = index.k({
|
|
196
|
+
level: index.DEFAULT_LOG_LEVEL
|
|
197
|
+
});
|
|
198
|
+
const { logger, chunkLoggerController } = index.A({
|
|
199
|
+
opts: loggerOptions
|
|
200
|
+
});
|
|
201
|
+
this.logger = index.E(logger, this.constructor.name);
|
|
202
|
+
this.chunkLoggerController = chunkLoggerController;
|
|
203
|
+
if (typeof window !== "undefined" && ((_a = this.chunkLoggerController) == null ? void 0 : _a.downloadLogsBlobInBrowser)) {
|
|
204
|
+
if (!window.downloadAppKitLogsBlob) {
|
|
205
|
+
window.downloadAppKitLogsBlob = {};
|
|
206
|
+
}
|
|
207
|
+
window.downloadAppKitLogsBlob["sdk"] = () => {
|
|
208
|
+
var _a2;
|
|
209
|
+
if ((_a2 = this.chunkLoggerController) == null ? void 0 : _a2.downloadLogsBlobInBrowser) {
|
|
210
|
+
this.chunkLoggerController.downloadLogsBlobInBrowser({
|
|
211
|
+
projectId
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
class W3mFrameProvider {
|
|
219
|
+
constructor({ projectId, chainId, enableLogger = true, onTimeout }) {
|
|
220
|
+
this.openRpcRequests = [];
|
|
221
|
+
if (enableLogger) {
|
|
222
|
+
this.w3mLogger = new W3mFrameLogger(projectId);
|
|
223
|
+
}
|
|
224
|
+
this.w3mFrame = new W3mFrame({ projectId, isAppClient: true, chainId, enableLogger });
|
|
225
|
+
this.onTimeout = onTimeout;
|
|
226
|
+
if (this.getLoginEmailUsed()) {
|
|
227
|
+
this.w3mFrame.initFrame();
|
|
228
|
+
}
|
|
229
|
+
this.w3mFrame.events.onFrameEvent((event) => {
|
|
230
|
+
if (event.type === index.W3mFrameConstants.FRAME_GET_USER_SUCCESS) {
|
|
231
|
+
this.user = event.payload;
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
getLoginEmailUsed() {
|
|
236
|
+
return Boolean(index.W3mFrameStorage.get(index.W3mFrameConstants.EMAIL_LOGIN_USED_KEY));
|
|
237
|
+
}
|
|
238
|
+
getEmail() {
|
|
239
|
+
return index.W3mFrameStorage.get(index.W3mFrameConstants.EMAIL);
|
|
240
|
+
}
|
|
241
|
+
getUsername() {
|
|
242
|
+
return index.W3mFrameStorage.get(index.W3mFrameConstants.SOCIAL_USERNAME);
|
|
243
|
+
}
|
|
244
|
+
async reload() {
|
|
245
|
+
var _a;
|
|
246
|
+
try {
|
|
247
|
+
this.w3mFrame.initFrame();
|
|
248
|
+
await this.appEvent({
|
|
249
|
+
type: index.W3mFrameConstants.APP_RELOAD
|
|
250
|
+
});
|
|
251
|
+
} catch (error) {
|
|
252
|
+
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error reloading iframe");
|
|
253
|
+
throw error;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
async connectEmail(payload) {
|
|
257
|
+
var _a;
|
|
258
|
+
try {
|
|
259
|
+
index.W3mFrameHelpers.checkIfAllowedToTriggerEmail();
|
|
260
|
+
this.w3mFrame.initFrame();
|
|
261
|
+
const response = await this.appEvent({
|
|
262
|
+
type: index.W3mFrameConstants.APP_CONNECT_EMAIL,
|
|
263
|
+
payload
|
|
264
|
+
});
|
|
265
|
+
this.setNewLastEmailLoginTime();
|
|
266
|
+
return response;
|
|
267
|
+
} catch (error) {
|
|
268
|
+
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error connecting email");
|
|
269
|
+
throw error;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
async connectDevice() {
|
|
273
|
+
var _a;
|
|
274
|
+
try {
|
|
275
|
+
return this.appEvent({
|
|
276
|
+
type: index.W3mFrameConstants.APP_CONNECT_DEVICE
|
|
277
|
+
});
|
|
278
|
+
} catch (error) {
|
|
279
|
+
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error connecting device");
|
|
280
|
+
throw error;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
async connectOtp(payload) {
|
|
284
|
+
var _a;
|
|
285
|
+
try {
|
|
286
|
+
return this.appEvent({
|
|
287
|
+
type: index.W3mFrameConstants.APP_CONNECT_OTP,
|
|
288
|
+
payload
|
|
289
|
+
});
|
|
290
|
+
} catch (error) {
|
|
291
|
+
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error connecting otp");
|
|
292
|
+
throw error;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
async isConnected() {
|
|
296
|
+
var _a;
|
|
297
|
+
try {
|
|
298
|
+
if (!this.getLoginEmailUsed()) {
|
|
299
|
+
return { isConnected: false };
|
|
300
|
+
}
|
|
301
|
+
const response = await this.appEvent({
|
|
302
|
+
type: index.W3mFrameConstants.APP_IS_CONNECTED
|
|
303
|
+
});
|
|
304
|
+
if (!response.isConnected) {
|
|
305
|
+
this.deleteAuthLoginCache();
|
|
306
|
+
}
|
|
307
|
+
return response;
|
|
308
|
+
} catch (error) {
|
|
309
|
+
this.deleteAuthLoginCache();
|
|
310
|
+
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error checking connection");
|
|
311
|
+
throw error;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
async getChainId() {
|
|
315
|
+
var _a;
|
|
316
|
+
try {
|
|
317
|
+
const response = await this.appEvent({
|
|
318
|
+
type: index.W3mFrameConstants.APP_GET_CHAIN_ID
|
|
319
|
+
});
|
|
320
|
+
this.setLastUsedChainId(response.chainId);
|
|
321
|
+
return response;
|
|
322
|
+
} catch (error) {
|
|
323
|
+
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error getting chain id");
|
|
324
|
+
throw error;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
async getSocialRedirectUri(payload) {
|
|
328
|
+
var _a;
|
|
329
|
+
try {
|
|
330
|
+
this.w3mFrame.initFrame();
|
|
331
|
+
return this.appEvent({
|
|
332
|
+
type: index.W3mFrameConstants.APP_GET_SOCIAL_REDIRECT_URI,
|
|
333
|
+
payload
|
|
334
|
+
});
|
|
335
|
+
} catch (error) {
|
|
336
|
+
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error getting social redirect uri");
|
|
337
|
+
throw error;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
async updateEmail(payload) {
|
|
341
|
+
var _a;
|
|
342
|
+
try {
|
|
343
|
+
const response = await this.appEvent({
|
|
344
|
+
type: index.W3mFrameConstants.APP_UPDATE_EMAIL,
|
|
345
|
+
payload
|
|
346
|
+
});
|
|
347
|
+
this.setNewLastEmailLoginTime();
|
|
348
|
+
return response;
|
|
349
|
+
} catch (error) {
|
|
350
|
+
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error updating email");
|
|
351
|
+
throw error;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
async updateEmailPrimaryOtp(payload) {
|
|
355
|
+
var _a;
|
|
356
|
+
try {
|
|
357
|
+
return this.appEvent({
|
|
358
|
+
type: index.W3mFrameConstants.APP_UPDATE_EMAIL_PRIMARY_OTP,
|
|
359
|
+
payload
|
|
360
|
+
});
|
|
361
|
+
} catch (error) {
|
|
362
|
+
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error updating email primary otp");
|
|
363
|
+
throw error;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
async updateEmailSecondaryOtp(payload) {
|
|
367
|
+
var _a;
|
|
368
|
+
try {
|
|
369
|
+
const response = await this.appEvent({
|
|
370
|
+
type: index.W3mFrameConstants.APP_UPDATE_EMAIL_SECONDARY_OTP,
|
|
371
|
+
payload
|
|
372
|
+
});
|
|
373
|
+
this.setLoginSuccess(response.newEmail);
|
|
374
|
+
return response;
|
|
375
|
+
} catch (error) {
|
|
376
|
+
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error updating email secondary otp");
|
|
377
|
+
throw error;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
async syncTheme(payload) {
|
|
381
|
+
var _a;
|
|
382
|
+
try {
|
|
383
|
+
return this.appEvent({
|
|
384
|
+
type: index.W3mFrameConstants.APP_SYNC_THEME,
|
|
385
|
+
payload
|
|
386
|
+
});
|
|
387
|
+
} catch (error) {
|
|
388
|
+
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error syncing theme");
|
|
389
|
+
throw error;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
async syncDappData(payload) {
|
|
393
|
+
var _a;
|
|
394
|
+
try {
|
|
395
|
+
return this.appEvent({
|
|
396
|
+
type: index.W3mFrameConstants.APP_SYNC_DAPP_DATA,
|
|
397
|
+
payload
|
|
398
|
+
});
|
|
399
|
+
} catch (error) {
|
|
400
|
+
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error syncing dapp data");
|
|
401
|
+
throw error;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
async getSmartAccountEnabledNetworks() {
|
|
405
|
+
var _a;
|
|
406
|
+
try {
|
|
407
|
+
const response = await this.appEvent({
|
|
408
|
+
type: index.W3mFrameConstants.APP_GET_SMART_ACCOUNT_ENABLED_NETWORKS
|
|
409
|
+
});
|
|
410
|
+
this.persistSmartAccountEnabledNetworks(response.smartAccountEnabledNetworks);
|
|
411
|
+
return response;
|
|
412
|
+
} catch (error) {
|
|
413
|
+
this.persistSmartAccountEnabledNetworks([]);
|
|
414
|
+
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error getting smart account enabled networks");
|
|
415
|
+
throw error;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
async setPreferredAccount(type) {
|
|
419
|
+
var _a;
|
|
420
|
+
try {
|
|
421
|
+
return this.appEvent({
|
|
422
|
+
type: index.W3mFrameConstants.APP_SET_PREFERRED_ACCOUNT,
|
|
423
|
+
payload: { type }
|
|
424
|
+
});
|
|
425
|
+
} catch (error) {
|
|
426
|
+
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error setting preferred account");
|
|
427
|
+
throw error;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
async connect(payload) {
|
|
431
|
+
var _a;
|
|
432
|
+
try {
|
|
433
|
+
const chainId = (payload == null ? void 0 : payload.chainId) || this.getLastUsedChainId() || 1;
|
|
434
|
+
const response = await this.appEvent({
|
|
435
|
+
type: index.W3mFrameConstants.APP_GET_USER,
|
|
436
|
+
payload: { ...payload, chainId }
|
|
437
|
+
});
|
|
438
|
+
this.setLoginSuccess(response.email);
|
|
439
|
+
this.setLastUsedChainId(response.chainId);
|
|
440
|
+
return response;
|
|
441
|
+
} catch (error) {
|
|
442
|
+
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error connecting");
|
|
443
|
+
throw error;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
async getUser(payload) {
|
|
447
|
+
var _a;
|
|
448
|
+
try {
|
|
449
|
+
const chainId = (payload == null ? void 0 : payload.chainId) || this.getLastUsedChainId() || 1;
|
|
450
|
+
const response = await this.appEvent({
|
|
451
|
+
type: index.W3mFrameConstants.APP_GET_USER,
|
|
452
|
+
payload: { ...payload, chainId }
|
|
453
|
+
});
|
|
454
|
+
return response;
|
|
455
|
+
} catch (error) {
|
|
456
|
+
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error connecting");
|
|
457
|
+
throw error;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
async connectSocial(uri) {
|
|
461
|
+
var _a;
|
|
462
|
+
try {
|
|
463
|
+
const response = await this.appEvent({
|
|
464
|
+
type: index.W3mFrameConstants.APP_CONNECT_SOCIAL,
|
|
465
|
+
payload: { uri }
|
|
466
|
+
});
|
|
467
|
+
if (response.userName) {
|
|
468
|
+
this.setSocialLoginSuccess(response.userName);
|
|
469
|
+
}
|
|
470
|
+
return response;
|
|
471
|
+
} catch (error) {
|
|
472
|
+
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error connecting social");
|
|
473
|
+
throw error;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
async getFarcasterUri() {
|
|
477
|
+
var _a;
|
|
478
|
+
try {
|
|
479
|
+
this.w3mFrame.initFrame();
|
|
480
|
+
const response = await this.appEvent({
|
|
481
|
+
type: index.W3mFrameConstants.APP_GET_FARCASTER_URI
|
|
482
|
+
});
|
|
483
|
+
return response;
|
|
484
|
+
} catch (error) {
|
|
485
|
+
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error getting farcaster uri");
|
|
486
|
+
throw error;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
async connectFarcaster() {
|
|
490
|
+
var _a;
|
|
491
|
+
try {
|
|
492
|
+
const response = await this.appEvent({
|
|
493
|
+
type: index.W3mFrameConstants.APP_CONNECT_FARCASTER
|
|
494
|
+
});
|
|
495
|
+
if (response.userName) {
|
|
496
|
+
this.setSocialLoginSuccess(response.userName);
|
|
497
|
+
}
|
|
498
|
+
return response;
|
|
499
|
+
} catch (error) {
|
|
500
|
+
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error connecting farcaster");
|
|
501
|
+
throw error;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
async switchNetwork(chainId) {
|
|
505
|
+
var _a;
|
|
506
|
+
try {
|
|
507
|
+
const response = await this.appEvent({
|
|
508
|
+
type: index.W3mFrameConstants.APP_SWITCH_NETWORK,
|
|
509
|
+
payload: { chainId }
|
|
510
|
+
});
|
|
511
|
+
this.setLastUsedChainId(response.chainId);
|
|
512
|
+
return response;
|
|
513
|
+
} catch (error) {
|
|
514
|
+
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error switching network");
|
|
515
|
+
throw error;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
async disconnect() {
|
|
519
|
+
var _a;
|
|
520
|
+
try {
|
|
521
|
+
const response = await this.appEvent({
|
|
522
|
+
type: index.W3mFrameConstants.APP_SIGN_OUT
|
|
523
|
+
});
|
|
524
|
+
this.deleteAuthLoginCache();
|
|
525
|
+
return response;
|
|
526
|
+
} catch (error) {
|
|
527
|
+
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error disconnecting");
|
|
528
|
+
throw error;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
async request(req) {
|
|
532
|
+
var _a, _b, _c, _d;
|
|
533
|
+
try {
|
|
534
|
+
if (index.W3mFrameRpcConstants.GET_CHAIN_ID === req.method) {
|
|
535
|
+
return this.getLastUsedChainId();
|
|
536
|
+
}
|
|
537
|
+
(_a = this.rpcRequestHandler) == null ? void 0 : _a.call(this, req);
|
|
538
|
+
const response = await this.appEvent({
|
|
539
|
+
type: index.W3mFrameConstants.APP_RPC_REQUEST,
|
|
540
|
+
payload: req
|
|
541
|
+
});
|
|
542
|
+
(_b = this.rpcSuccessHandler) == null ? void 0 : _b.call(this, response, req);
|
|
543
|
+
return response;
|
|
544
|
+
} catch (error) {
|
|
545
|
+
(_c = this.rpcErrorHandler) == null ? void 0 : _c.call(this, error, req);
|
|
546
|
+
(_d = this.w3mLogger) == null ? void 0 : _d.logger.error({ error }, "Error requesting");
|
|
547
|
+
throw error;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
onRpcRequest(callback) {
|
|
551
|
+
this.rpcRequestHandler = callback;
|
|
552
|
+
}
|
|
553
|
+
onRpcSuccess(callback) {
|
|
554
|
+
this.rpcSuccessHandler = callback;
|
|
555
|
+
}
|
|
556
|
+
onRpcError(callback) {
|
|
557
|
+
this.rpcErrorHandler = callback;
|
|
558
|
+
}
|
|
559
|
+
onIsConnected(callback) {
|
|
560
|
+
this.w3mFrame.events.onFrameEvent((event) => {
|
|
561
|
+
if (event.type === index.W3mFrameConstants.FRAME_IS_CONNECTED_SUCCESS && event.payload.isConnected) {
|
|
562
|
+
callback();
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
onNotConnected(callback) {
|
|
567
|
+
this.w3mFrame.events.onFrameEvent((event) => {
|
|
568
|
+
if (event.type === index.W3mFrameConstants.FRAME_IS_CONNECTED_ERROR) {
|
|
569
|
+
callback();
|
|
570
|
+
}
|
|
571
|
+
if (event.type === index.W3mFrameConstants.FRAME_IS_CONNECTED_SUCCESS && !event.payload.isConnected) {
|
|
572
|
+
callback();
|
|
573
|
+
}
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
onConnect(callback) {
|
|
577
|
+
this.w3mFrame.events.onFrameEvent((event) => {
|
|
578
|
+
if (event.type === index.W3mFrameConstants.FRAME_GET_USER_SUCCESS) {
|
|
579
|
+
callback(event.payload);
|
|
580
|
+
}
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
onSocialConnected(callback) {
|
|
584
|
+
this.w3mFrame.events.onFrameEvent((event) => {
|
|
585
|
+
if (event.type === index.W3mFrameConstants.FRAME_CONNECT_SOCIAL_SUCCESS) {
|
|
586
|
+
callback(event.payload);
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
async getCapabilities() {
|
|
591
|
+
try {
|
|
592
|
+
const capabilities = await this.request({
|
|
593
|
+
method: "wallet_getCapabilities"
|
|
594
|
+
});
|
|
595
|
+
return capabilities || {};
|
|
596
|
+
} catch {
|
|
597
|
+
return {};
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
onSetPreferredAccount(callback) {
|
|
601
|
+
this.w3mFrame.events.onFrameEvent((event) => {
|
|
602
|
+
if (event.type === index.W3mFrameConstants.FRAME_SET_PREFERRED_ACCOUNT_SUCCESS) {
|
|
603
|
+
callback(event.payload);
|
|
604
|
+
} else if (event.type === index.W3mFrameConstants.FRAME_SET_PREFERRED_ACCOUNT_ERROR) {
|
|
605
|
+
callback({ type: index.W3mFrameRpcConstants.ACCOUNT_TYPES.EOA });
|
|
606
|
+
}
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
onGetSmartAccountEnabledNetworks(callback) {
|
|
610
|
+
this.w3mFrame.events.onFrameEvent((event) => {
|
|
611
|
+
if (event.type === index.W3mFrameConstants.FRAME_GET_SMART_ACCOUNT_ENABLED_NETWORKS_SUCCESS) {
|
|
612
|
+
callback(event.payload.smartAccountEnabledNetworks);
|
|
613
|
+
} else if (event.type === index.W3mFrameConstants.FRAME_GET_SMART_ACCOUNT_ENABLED_NETWORKS_ERROR) {
|
|
614
|
+
callback([]);
|
|
615
|
+
}
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
getAvailableChainIds() {
|
|
619
|
+
return Object.keys(this.w3mFrame.networks);
|
|
620
|
+
}
|
|
621
|
+
rejectRpcRequests() {
|
|
622
|
+
var _a;
|
|
623
|
+
try {
|
|
624
|
+
this.openRpcRequests.forEach(({ abortController, method }) => {
|
|
625
|
+
if (!index.W3mFrameRpcConstants.SAFE_RPC_METHODS.includes(method)) {
|
|
626
|
+
abortController.abort();
|
|
627
|
+
}
|
|
628
|
+
});
|
|
629
|
+
this.openRpcRequests = [];
|
|
630
|
+
} catch (e) {
|
|
631
|
+
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error: e }, "Error aborting RPC request");
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
async appEvent(event) {
|
|
635
|
+
await this.w3mFrame.frameLoadPromise;
|
|
636
|
+
let timer = void 0;
|
|
637
|
+
function replaceEventType(type2) {
|
|
638
|
+
return type2.replace("@w3m-app/", "");
|
|
639
|
+
}
|
|
640
|
+
const abortController = new AbortController();
|
|
641
|
+
const type = replaceEventType(event.type);
|
|
642
|
+
const shouldCheckForTimeout = [
|
|
643
|
+
index.W3mFrameConstants.APP_CONNECT_EMAIL,
|
|
644
|
+
index.W3mFrameConstants.APP_CONNECT_DEVICE,
|
|
645
|
+
index.W3mFrameConstants.APP_CONNECT_OTP,
|
|
646
|
+
index.W3mFrameConstants.APP_CONNECT_SOCIAL,
|
|
647
|
+
index.W3mFrameConstants.APP_GET_SOCIAL_REDIRECT_URI
|
|
648
|
+
].map(replaceEventType).includes(type);
|
|
649
|
+
if (shouldCheckForTimeout) {
|
|
650
|
+
timer = setTimeout(() => {
|
|
651
|
+
var _a;
|
|
652
|
+
(_a = this.onTimeout) == null ? void 0 : _a.call(this);
|
|
653
|
+
abortController.abort();
|
|
654
|
+
}, 3e4);
|
|
655
|
+
}
|
|
656
|
+
return new Promise((resolve, reject) => {
|
|
657
|
+
var _a, _b, _c;
|
|
658
|
+
const id = Math.random().toString(36).substring(7);
|
|
659
|
+
(_c = (_a = this.w3mLogger) == null ? void 0 : (_b = _a.logger).info) == null ? void 0 : _c.call(_b, { event, id }, "Sending app event");
|
|
660
|
+
this.w3mFrame.events.postAppEvent({ ...event, id });
|
|
661
|
+
if (type === "RPC_REQUEST") {
|
|
662
|
+
const rpcEvent = event;
|
|
663
|
+
this.openRpcRequests = [...this.openRpcRequests, { ...rpcEvent.payload, abortController }];
|
|
664
|
+
}
|
|
665
|
+
abortController.signal.addEventListener("abort", () => {
|
|
666
|
+
if (type === "RPC_REQUEST") {
|
|
667
|
+
reject(new Error("Request was aborted"));
|
|
668
|
+
} else if (type !== "GET_FARCASTER_URI") {
|
|
669
|
+
reject(new Error("Something went wrong"));
|
|
670
|
+
}
|
|
671
|
+
});
|
|
672
|
+
function handler(framEvent, logger) {
|
|
673
|
+
var _a2, _b2, _c2;
|
|
674
|
+
if (framEvent.id !== id) {
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
(_b2 = logger == null ? void 0 : (_a2 = logger.logger).info) == null ? void 0 : _b2.call(_a2, { framEvent, id }, "Received frame response");
|
|
678
|
+
if (framEvent.type === `@w3m-frame/${type}_SUCCESS`) {
|
|
679
|
+
if (timer) {
|
|
680
|
+
clearTimeout(timer);
|
|
681
|
+
}
|
|
682
|
+
if ("payload" in framEvent) {
|
|
683
|
+
resolve(framEvent.payload);
|
|
684
|
+
}
|
|
685
|
+
resolve(void 0);
|
|
686
|
+
} else if (framEvent.type === `@w3m-frame/${type}_ERROR`) {
|
|
687
|
+
if (timer) {
|
|
688
|
+
clearTimeout(timer);
|
|
689
|
+
}
|
|
690
|
+
if ("payload" in framEvent) {
|
|
691
|
+
reject(new Error(((_c2 = framEvent.payload) == null ? void 0 : _c2.message) || "An error occurred"));
|
|
692
|
+
}
|
|
693
|
+
reject(new Error("An error occurred"));
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
this.w3mFrame.events.registerFrameEventHandler(id, (frameEvent) => handler(frameEvent, this.w3mLogger), abortController.signal);
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
setNewLastEmailLoginTime() {
|
|
700
|
+
index.W3mFrameStorage.set(index.W3mFrameConstants.LAST_EMAIL_LOGIN_TIME, Date.now().toString());
|
|
701
|
+
}
|
|
702
|
+
setSocialLoginSuccess(username) {
|
|
703
|
+
index.W3mFrameStorage.set(index.W3mFrameConstants.SOCIAL_USERNAME, username);
|
|
704
|
+
}
|
|
705
|
+
setLoginSuccess(email) {
|
|
706
|
+
if (email) {
|
|
707
|
+
index.W3mFrameStorage.set(index.W3mFrameConstants.EMAIL, email);
|
|
708
|
+
}
|
|
709
|
+
index.W3mFrameStorage.set(index.W3mFrameConstants.EMAIL_LOGIN_USED_KEY, "true");
|
|
710
|
+
index.W3mFrameStorage.delete(index.W3mFrameConstants.LAST_EMAIL_LOGIN_TIME);
|
|
711
|
+
}
|
|
712
|
+
deleteAuthLoginCache() {
|
|
713
|
+
index.W3mFrameStorage.delete(index.W3mFrameConstants.EMAIL_LOGIN_USED_KEY);
|
|
714
|
+
index.W3mFrameStorage.delete(index.W3mFrameConstants.EMAIL);
|
|
715
|
+
index.W3mFrameStorage.delete(index.W3mFrameConstants.LAST_USED_CHAIN_KEY);
|
|
716
|
+
index.W3mFrameStorage.delete(index.W3mFrameConstants.SOCIAL_USERNAME);
|
|
717
|
+
}
|
|
718
|
+
setLastUsedChainId(chainId) {
|
|
719
|
+
if (chainId) {
|
|
720
|
+
index.W3mFrameStorage.set(index.W3mFrameConstants.LAST_USED_CHAIN_KEY, String(chainId));
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
getLastUsedChainId() {
|
|
724
|
+
const chainId = index.W3mFrameStorage.get(index.W3mFrameConstants.LAST_USED_CHAIN_KEY) ?? void 0;
|
|
725
|
+
const numberChainId = Number(chainId);
|
|
726
|
+
return isNaN(numberChainId) ? chainId : numberChainId;
|
|
727
|
+
}
|
|
728
|
+
persistSmartAccountEnabledNetworks(networks) {
|
|
729
|
+
index.W3mFrameStorage.set(index.W3mFrameConstants.SMART_ACCOUNT_ENABLED_NETWORKS, networks.join(","));
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
const PresetsUtil = {
|
|
733
|
+
NetworkImageIds: {
|
|
734
|
+
1: "ba0ba0cd-17c6-4806-ad93-f9d174f17900",
|
|
735
|
+
42161: "3bff954d-5cb0-47a0-9a23-d20192e74600",
|
|
736
|
+
43114: "30c46e53-e989-45fb-4549-be3bd4eb3b00",
|
|
737
|
+
56: "93564157-2e8e-4ce7-81df-b264dbee9b00",
|
|
738
|
+
250: "06b26297-fe0c-4733-5d6b-ffa5498aac00",
|
|
739
|
+
10: "ab9c186a-c52f-464b-2906-ca59d760a400",
|
|
740
|
+
137: "41d04d42-da3b-4453-8506-668cc0727900",
|
|
741
|
+
100: "02b53f6a-e3d4-479e-1cb4-21178987d100",
|
|
742
|
+
9001: "f926ff41-260d-4028-635e-91913fc28e00",
|
|
743
|
+
324: "b310f07f-4ef7-49f3-7073-2a0a39685800",
|
|
744
|
+
314: "5a73b3dd-af74-424e-cae0-0de859ee9400",
|
|
745
|
+
4689: "34e68754-e536-40da-c153-6ef2e7188a00",
|
|
746
|
+
1088: "3897a66d-40b9-4833-162f-a2c90531c900",
|
|
747
|
+
1284: "161038da-44ae-4ec7-1208-0ea569454b00",
|
|
748
|
+
1285: "f1d73bb6-5450-4e18-38f7-fb6484264a00",
|
|
749
|
+
7777777: "845c60df-d429-4991-e687-91ae45791600",
|
|
750
|
+
42220: "ab781bbc-ccc6-418d-d32d-789b15da1f00",
|
|
751
|
+
8453: "7289c336-3981-4081-c5f4-efc26ac64a00",
|
|
752
|
+
1313161554: "3ff73439-a619-4894-9262-4470c773a100",
|
|
753
|
+
2020: "b8101fc0-9c19-4b6f-ec65-f6dfff106e00",
|
|
754
|
+
2021: "b8101fc0-9c19-4b6f-ec65-f6dfff106e00",
|
|
755
|
+
"5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp": "a1b58899-f671-4276-6a5e-56ca5bd59700",
|
|
756
|
+
"4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z": "a1b58899-f671-4276-6a5e-56ca5bd59700",
|
|
757
|
+
EtWTRABZaYq6iMfeYKouRu166VU2xqa1: "a1b58899-f671-4276-6a5e-56ca5bd59700",
|
|
758
|
+
"000000000019d6689c085ae165831e93": "21c895fa-e105-4829-9434-378bb54fa600",
|
|
759
|
+
"000000000933ea01ad0ee984209779ba": "220bcb01-ba47-41d3-fe5b-e29bbc4a4b00"
|
|
760
|
+
},
|
|
761
|
+
ConnectorImageIds: {
|
|
762
|
+
[index.ConstantsUtil.CONNECTOR_ID.COINBASE]: "0c2840c3-5b04-4c44-9661-fbd4b49e1800",
|
|
763
|
+
[index.ConstantsUtil.CONNECTOR_ID.COINBASE_SDK]: "0c2840c3-5b04-4c44-9661-fbd4b49e1800",
|
|
764
|
+
[index.ConstantsUtil.CONNECTOR_ID.SAFE]: "461db637-8616-43ce-035a-d89b8a1d5800",
|
|
765
|
+
[index.ConstantsUtil.CONNECTOR_ID.LEDGER]: "54a1aa77-d202-4f8d-0fb2-5d2bb6db0300",
|
|
766
|
+
[index.ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT]: "ef1a1fcf-7fe8-4d69-bd6d-fda1345b4400",
|
|
767
|
+
[index.ConstantsUtil.CONNECTOR_ID.INJECTED]: "07ba87ed-43aa-4adf-4540-9e6a2b9cae00"
|
|
768
|
+
},
|
|
769
|
+
ConnectorNamesMap: {
|
|
770
|
+
[index.ConstantsUtil.CONNECTOR_ID.INJECTED]: "Browser Wallet",
|
|
771
|
+
[index.ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT]: "WalletConnect",
|
|
772
|
+
[index.ConstantsUtil.CONNECTOR_ID.COINBASE]: "Coinbase",
|
|
773
|
+
[index.ConstantsUtil.CONNECTOR_ID.COINBASE_SDK]: "Coinbase",
|
|
774
|
+
[index.ConstantsUtil.CONNECTOR_ID.LEDGER]: "Ledger",
|
|
775
|
+
[index.ConstantsUtil.CONNECTOR_ID.SAFE]: "Safe"
|
|
776
|
+
}
|
|
777
|
+
};
|
|
778
|
+
const HelpersUtil = {
|
|
779
|
+
getCaipTokens(tokens) {
|
|
780
|
+
if (!tokens) {
|
|
781
|
+
return void 0;
|
|
782
|
+
}
|
|
783
|
+
const caipTokens = {};
|
|
784
|
+
Object.entries(tokens).forEach(([id, token]) => {
|
|
785
|
+
caipTokens[`${index.ConstantsUtil$1.EIP155}:${id}`] = token;
|
|
786
|
+
});
|
|
787
|
+
return caipTokens;
|
|
788
|
+
},
|
|
789
|
+
isLowerCaseMatch(str1, str2) {
|
|
790
|
+
return (str1 == null ? void 0 : str1.toLowerCase()) === (str2 == null ? void 0 : str2.toLowerCase());
|
|
791
|
+
}
|
|
792
|
+
};
|
|
793
|
+
const ErrorUtil = {
|
|
794
|
+
UniversalProviderErrors: {
|
|
795
|
+
UNAUTHORIZED_DOMAIN_NOT_ALLOWED: {
|
|
796
|
+
message: "Unauthorized: origin not allowed",
|
|
797
|
+
alertErrorKey: "INVALID_APP_CONFIGURATION"
|
|
798
|
+
},
|
|
799
|
+
JWT_VALIDATION_ERROR: {
|
|
800
|
+
message: "JWT validation error: JWT Token is not yet valid",
|
|
801
|
+
alertErrorKey: "JWT_TOKEN_NOT_VALID"
|
|
802
|
+
},
|
|
803
|
+
INVALID_KEY: {
|
|
804
|
+
message: "Unauthorized: invalid key",
|
|
805
|
+
alertErrorKey: "INVALID_PROJECT_ID"
|
|
806
|
+
}
|
|
807
|
+
},
|
|
808
|
+
ALERT_ERRORS: {
|
|
809
|
+
SWITCH_NETWORK_NOT_FOUND: {
|
|
810
|
+
shortMessage: "Network Not Found",
|
|
811
|
+
longMessage: "Network not found - please make sure it is included in 'networks' array in createAppKit function"
|
|
812
|
+
},
|
|
813
|
+
INVALID_APP_CONFIGURATION: {
|
|
814
|
+
shortMessage: "Invalid App Configuration",
|
|
815
|
+
longMessage: () => `Origin ${isSafe() ? window.origin : "unknown"} not found on Allowlist - update configuration on cloud.reown.com`
|
|
816
|
+
},
|
|
817
|
+
SOCIALS_TIMEOUT: {
|
|
818
|
+
shortMessage: "Invalid App Configuration",
|
|
819
|
+
longMessage: () => "There was an issue loading the embedded wallet. Please verify that your domain is allowed at cloud.reown.com"
|
|
820
|
+
},
|
|
821
|
+
JWT_TOKEN_NOT_VALID: {
|
|
822
|
+
shortMessage: "Session Expired",
|
|
823
|
+
longMessage: "Invalid session found on UniversalProvider - please check your time settings and connect again"
|
|
824
|
+
},
|
|
825
|
+
INVALID_PROJECT_ID: {
|
|
826
|
+
shortMessage: "Invalid App Configuration",
|
|
827
|
+
longMessage: "Invalid Project ID - update configuration"
|
|
828
|
+
},
|
|
829
|
+
PROJECT_ID_NOT_CONFIGURED: {
|
|
830
|
+
shortMessage: "Project ID Not Configured",
|
|
831
|
+
longMessage: "Project ID Not Configured - update configuration on cloud.reown.com"
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
};
|
|
835
|
+
function isSafe() {
|
|
836
|
+
return typeof window !== "undefined";
|
|
837
|
+
}
|
|
838
|
+
const LoggerUtil = {
|
|
839
|
+
createLogger(onError, level = "error") {
|
|
840
|
+
const loggerOptions = index.k({
|
|
841
|
+
level
|
|
842
|
+
});
|
|
843
|
+
const { logger } = index.A({
|
|
844
|
+
opts: loggerOptions
|
|
845
|
+
});
|
|
846
|
+
logger.error = (...args) => {
|
|
847
|
+
for (const arg of args) {
|
|
848
|
+
if (arg instanceof Error) {
|
|
849
|
+
onError(arg, ...args);
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
onError(void 0, ...args);
|
|
854
|
+
};
|
|
855
|
+
return logger;
|
|
856
|
+
}
|
|
857
|
+
};
|
|
858
|
+
const RPC_URL_HOST = "rpc.walletconnect.org";
|
|
859
|
+
function getBlockchainApiRpcUrl(caipNetworkId, projectId) {
|
|
860
|
+
const url = new URL("https://rpc.walletconnect.org/v1/");
|
|
861
|
+
url.searchParams.set("chainId", caipNetworkId);
|
|
862
|
+
url.searchParams.set("projectId", projectId);
|
|
863
|
+
return url.toString();
|
|
864
|
+
}
|
|
865
|
+
const WC_HTTP_RPC_SUPPORTED_CHAINS = [
|
|
866
|
+
"near:mainnet",
|
|
867
|
+
"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
|
|
868
|
+
"eip155:1101",
|
|
869
|
+
"eip155:56",
|
|
870
|
+
"eip155:42161",
|
|
871
|
+
"eip155:7777777",
|
|
872
|
+
"eip155:59144",
|
|
873
|
+
"eip155:324",
|
|
874
|
+
"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",
|
|
875
|
+
"eip155:5000",
|
|
876
|
+
"solana:4sgjmw1sunhzsxgspuhpqldx6wiyjntz",
|
|
877
|
+
"eip155:80084",
|
|
878
|
+
"eip155:5003",
|
|
879
|
+
"eip155:100",
|
|
880
|
+
"eip155:8453",
|
|
881
|
+
"eip155:42220",
|
|
882
|
+
"eip155:1313161555",
|
|
883
|
+
"eip155:17000",
|
|
884
|
+
"eip155:1",
|
|
885
|
+
"eip155:300",
|
|
886
|
+
"eip155:1313161554",
|
|
887
|
+
"eip155:1329",
|
|
888
|
+
"eip155:84532",
|
|
889
|
+
"eip155:421614",
|
|
890
|
+
"eip155:11155111",
|
|
891
|
+
"eip155:8217",
|
|
892
|
+
"eip155:43114",
|
|
893
|
+
"solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z",
|
|
894
|
+
"eip155:999999999",
|
|
895
|
+
"eip155:11155420",
|
|
896
|
+
"eip155:80002",
|
|
897
|
+
"eip155:97",
|
|
898
|
+
"eip155:43113",
|
|
899
|
+
"eip155:137",
|
|
900
|
+
"eip155:10",
|
|
901
|
+
"eip155:1301",
|
|
902
|
+
"bip122:000000000019d6689c085ae165831e93",
|
|
903
|
+
"bip122:000000000933ea01ad0ee984209779ba"
|
|
904
|
+
];
|
|
905
|
+
const CaipNetworksUtil = {
|
|
906
|
+
extendRpcUrlWithProjectId(rpcUrl, projectId) {
|
|
907
|
+
let isReownUrl = false;
|
|
908
|
+
try {
|
|
909
|
+
const url = new URL(rpcUrl);
|
|
910
|
+
isReownUrl = url.host === RPC_URL_HOST;
|
|
911
|
+
} catch (e) {
|
|
912
|
+
isReownUrl = false;
|
|
913
|
+
}
|
|
914
|
+
if (isReownUrl) {
|
|
915
|
+
const url = new URL(rpcUrl);
|
|
916
|
+
if (!url.searchParams.has("projectId")) {
|
|
917
|
+
url.searchParams.set("projectId", projectId);
|
|
918
|
+
}
|
|
919
|
+
return url.toString();
|
|
920
|
+
}
|
|
921
|
+
return rpcUrl;
|
|
922
|
+
},
|
|
923
|
+
isCaipNetwork(network) {
|
|
924
|
+
return "chainNamespace" in network && "caipNetworkId" in network;
|
|
925
|
+
},
|
|
926
|
+
getChainNamespace(network) {
|
|
927
|
+
if (this.isCaipNetwork(network)) {
|
|
928
|
+
return network.chainNamespace;
|
|
929
|
+
}
|
|
930
|
+
return index.ConstantsUtil.CHAIN.EVM;
|
|
931
|
+
},
|
|
932
|
+
getCaipNetworkId(network) {
|
|
933
|
+
if (this.isCaipNetwork(network)) {
|
|
934
|
+
return network.caipNetworkId;
|
|
935
|
+
}
|
|
936
|
+
return `${index.ConstantsUtil.CHAIN.EVM}:${network.id}`;
|
|
937
|
+
},
|
|
938
|
+
getDefaultRpcUrl(caipNetwork, caipNetworkId, projectId) {
|
|
939
|
+
var _a, _b, _c;
|
|
940
|
+
const defaultRpcUrl = (_c = (_b = (_a = caipNetwork.rpcUrls) == null ? void 0 : _a.default) == null ? void 0 : _b.http) == null ? void 0 : _c[0];
|
|
941
|
+
if (WC_HTTP_RPC_SUPPORTED_CHAINS.includes(caipNetworkId)) {
|
|
942
|
+
return getBlockchainApiRpcUrl(caipNetworkId, projectId);
|
|
943
|
+
}
|
|
944
|
+
return defaultRpcUrl || "";
|
|
945
|
+
},
|
|
946
|
+
extendCaipNetwork(caipNetwork, { customNetworkImageUrls, projectId, customRpc }) {
|
|
947
|
+
var _a, _b, _c, _d;
|
|
948
|
+
const caipNetworkId = this.getCaipNetworkId(caipNetwork);
|
|
949
|
+
const chainNamespace = this.getChainNamespace(caipNetwork);
|
|
950
|
+
const chainDefaultUrl = (_c = (_b = (_a = caipNetwork == null ? void 0 : caipNetwork.rpcUrls) == null ? void 0 : _a["chainDefault"]) == null ? void 0 : _b.http) == null ? void 0 : _c[0];
|
|
951
|
+
let rpcUrl = "";
|
|
952
|
+
if (customRpc) {
|
|
953
|
+
rpcUrl = ((_d = caipNetwork.rpcUrls.default.http) == null ? void 0 : _d[0]) || "";
|
|
954
|
+
} else {
|
|
955
|
+
rpcUrl = this.getDefaultRpcUrl(caipNetwork, caipNetworkId, projectId);
|
|
956
|
+
}
|
|
957
|
+
return {
|
|
958
|
+
...caipNetwork,
|
|
959
|
+
chainNamespace,
|
|
960
|
+
caipNetworkId,
|
|
961
|
+
assets: {
|
|
962
|
+
imageId: PresetsUtil.NetworkImageIds[caipNetwork.id],
|
|
963
|
+
imageUrl: customNetworkImageUrls == null ? void 0 : customNetworkImageUrls[caipNetwork.id]
|
|
964
|
+
},
|
|
965
|
+
rpcUrls: {
|
|
966
|
+
...caipNetwork.rpcUrls,
|
|
967
|
+
default: {
|
|
968
|
+
http: [rpcUrl]
|
|
969
|
+
},
|
|
970
|
+
chainDefault: {
|
|
971
|
+
http: [chainDefaultUrl || caipNetwork.rpcUrls.default.http[0] || ""]
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
};
|
|
975
|
+
},
|
|
976
|
+
extendCaipNetworks(caipNetworks, { customNetworkImageUrls, projectId, customRpcChainIds }) {
|
|
977
|
+
return caipNetworks.map((caipNetwork) => CaipNetworksUtil.extendCaipNetwork(caipNetwork, {
|
|
978
|
+
customNetworkImageUrls,
|
|
979
|
+
projectId,
|
|
980
|
+
customRpc: customRpcChainIds == null ? void 0 : customRpcChainIds.includes(caipNetwork.id)
|
|
981
|
+
}));
|
|
982
|
+
},
|
|
983
|
+
getViemTransport(caipNetwork) {
|
|
984
|
+
var _a;
|
|
985
|
+
const defaultRpcUrl = (_a = caipNetwork.rpcUrls.default.http) == null ? void 0 : _a[0];
|
|
986
|
+
if (!WC_HTTP_RPC_SUPPORTED_CHAINS.includes(caipNetwork.caipNetworkId)) {
|
|
987
|
+
return viem.http(defaultRpcUrl);
|
|
988
|
+
}
|
|
989
|
+
return viem.fallback([
|
|
990
|
+
viem.http(defaultRpcUrl, {
|
|
991
|
+
fetchOptions: {
|
|
992
|
+
headers: {
|
|
993
|
+
"Content-Type": "text/plain"
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
}),
|
|
997
|
+
viem.http(defaultRpcUrl)
|
|
998
|
+
]);
|
|
999
|
+
}
|
|
1000
|
+
};
|
|
1001
|
+
class W3mFrameProviderSingleton {
|
|
1002
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function -- This is a singleton
|
|
1003
|
+
constructor() {
|
|
1004
|
+
}
|
|
1005
|
+
static getInstance({ projectId, chainId, enableLogger, onTimeout }) {
|
|
1006
|
+
if (!W3mFrameProviderSingleton.instance) {
|
|
1007
|
+
W3mFrameProviderSingleton.instance = new W3mFrameProvider({
|
|
1008
|
+
projectId,
|
|
1009
|
+
chainId,
|
|
1010
|
+
enableLogger,
|
|
1011
|
+
onTimeout
|
|
1012
|
+
});
|
|
1013
|
+
}
|
|
1014
|
+
return W3mFrameProviderSingleton.instance;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
const WcConstantsUtil = {
|
|
1018
|
+
ERROR_CODE_UNRECOGNIZED_CHAIN_ID: 4902,
|
|
1019
|
+
ERROR_CODE_DEFAULT: 5e3
|
|
1020
|
+
};
|
|
1021
|
+
const WcHelpersUtil = {
|
|
1022
|
+
getMethodsByChainNamespace(chainNamespace) {
|
|
1023
|
+
switch (chainNamespace) {
|
|
1024
|
+
case "solana":
|
|
1025
|
+
return [
|
|
1026
|
+
"solana_signMessage",
|
|
1027
|
+
"solana_signTransaction",
|
|
1028
|
+
"solana_requestAccounts",
|
|
1029
|
+
"solana_getAccounts",
|
|
1030
|
+
"solana_signAllTransactions",
|
|
1031
|
+
"solana_signAndSendTransaction"
|
|
1032
|
+
];
|
|
1033
|
+
case "eip155":
|
|
1034
|
+
return [
|
|
1035
|
+
"personal_sign",
|
|
1036
|
+
"eth_sign",
|
|
1037
|
+
"eth_signTransaction",
|
|
1038
|
+
"eth_signTypedData",
|
|
1039
|
+
"eth_signTypedData_v3",
|
|
1040
|
+
"eth_signTypedData_v4",
|
|
1041
|
+
"eth_sendRawTransaction",
|
|
1042
|
+
"eth_sendTransaction",
|
|
1043
|
+
"wallet_getCapabilities",
|
|
1044
|
+
"wallet_sendCalls",
|
|
1045
|
+
"wallet_showCallsStatus",
|
|
1046
|
+
"wallet_getCallsStatus",
|
|
1047
|
+
"wallet_grantPermissions",
|
|
1048
|
+
"wallet_revokePermissions",
|
|
1049
|
+
"wallet_switchEthereumChain",
|
|
1050
|
+
//EIP-7811
|
|
1051
|
+
"wallet_getAssets"
|
|
1052
|
+
];
|
|
1053
|
+
case "bip122":
|
|
1054
|
+
return ["sendTransfer", "signMessage", "signPsbt", "getAccountAddresses"];
|
|
1055
|
+
default:
|
|
1056
|
+
return [];
|
|
1057
|
+
}
|
|
1058
|
+
},
|
|
1059
|
+
createNamespaces(caipNetworks) {
|
|
1060
|
+
return caipNetworks.reduce((acc, chain) => {
|
|
1061
|
+
const { id, chainNamespace, rpcUrls } = chain;
|
|
1062
|
+
const rpcUrl = rpcUrls.default.http[0];
|
|
1063
|
+
const methods = this.getMethodsByChainNamespace(chainNamespace);
|
|
1064
|
+
if (!acc[chainNamespace]) {
|
|
1065
|
+
acc[chainNamespace] = {
|
|
1066
|
+
methods,
|
|
1067
|
+
events: ["accountsChanged", "chainChanged"],
|
|
1068
|
+
chains: [],
|
|
1069
|
+
rpcMap: {}
|
|
1070
|
+
};
|
|
1071
|
+
}
|
|
1072
|
+
const caipNetworkId = `${chainNamespace}:${id}`;
|
|
1073
|
+
const namespace = acc[chainNamespace];
|
|
1074
|
+
namespace.chains.push(caipNetworkId);
|
|
1075
|
+
switch (caipNetworkId) {
|
|
1076
|
+
case index.solana.caipNetworkId:
|
|
1077
|
+
namespace.chains.push(index.solana.deprecatedCaipNetworkId);
|
|
1078
|
+
break;
|
|
1079
|
+
case index.solanaDevnet.caipNetworkId:
|
|
1080
|
+
namespace.chains.push(index.solanaDevnet.deprecatedCaipNetworkId);
|
|
1081
|
+
break;
|
|
1082
|
+
}
|
|
1083
|
+
if ((namespace == null ? void 0 : namespace.rpcMap) && rpcUrl) {
|
|
1084
|
+
namespace.rpcMap[id] = rpcUrl;
|
|
1085
|
+
}
|
|
1086
|
+
return acc;
|
|
1087
|
+
}, {});
|
|
1088
|
+
},
|
|
1089
|
+
resolveReownName: async (name) => {
|
|
1090
|
+
var _a;
|
|
1091
|
+
const wcNameAddress = await index.EnsController.resolveName(name);
|
|
1092
|
+
const networkNameAddresses = Object.values(wcNameAddress == null ? void 0 : wcNameAddress.addresses) || [];
|
|
1093
|
+
return ((_a = networkNameAddresses[0]) == null ? void 0 : _a.address) || false;
|
|
1094
|
+
},
|
|
1095
|
+
getChainsFromNamespaces(namespaces = {}) {
|
|
1096
|
+
return Object.values(namespaces).flatMap((namespace) => {
|
|
1097
|
+
const chains = namespace.chains || [];
|
|
1098
|
+
const accountsChains = namespace.accounts.map((account) => {
|
|
1099
|
+
const [chainNamespace, chainId] = account.split(":");
|
|
1100
|
+
return `${chainNamespace}:${chainId}`;
|
|
1101
|
+
});
|
|
1102
|
+
return Array.from(/* @__PURE__ */ new Set([...chains, ...accountsChains]));
|
|
1103
|
+
});
|
|
1104
|
+
},
|
|
1105
|
+
isSessionEventData(data) {
|
|
1106
|
+
return typeof data === "object" && data !== null && "id" in data && "topic" in data && "params" in data && typeof data.params === "object" && data.params !== null && "chainId" in data.params && "event" in data.params && typeof data.params.event === "object" && data.params.event !== null;
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
1109
|
+
class WalletConnectConnector {
|
|
1110
|
+
constructor({ provider, caipNetworks, namespace }) {
|
|
1111
|
+
this.id = index.ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT;
|
|
1112
|
+
this.name = PresetsUtil.ConnectorNamesMap[index.ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT];
|
|
1113
|
+
this.type = "WALLET_CONNECT";
|
|
1114
|
+
this.imageId = PresetsUtil.ConnectorImageIds[index.ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT];
|
|
1115
|
+
this.caipNetworks = caipNetworks;
|
|
1116
|
+
this.provider = provider;
|
|
1117
|
+
this.chain = namespace;
|
|
1118
|
+
}
|
|
1119
|
+
get chains() {
|
|
1120
|
+
return this.caipNetworks;
|
|
1121
|
+
}
|
|
1122
|
+
async connectWalletConnect() {
|
|
1123
|
+
const isAuthenticated = await this.authenticate();
|
|
1124
|
+
if (!isAuthenticated) {
|
|
1125
|
+
await this.provider.connect({
|
|
1126
|
+
optionalNamespaces: WcHelpersUtil.createNamespaces(this.caipNetworks)
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
return {
|
|
1130
|
+
clientId: await this.provider.client.core.crypto.getClientId(),
|
|
1131
|
+
session: this.provider.session
|
|
1132
|
+
};
|
|
1133
|
+
}
|
|
1134
|
+
async disconnect() {
|
|
1135
|
+
await this.provider.disconnect();
|
|
1136
|
+
}
|
|
1137
|
+
async authenticate() {
|
|
1138
|
+
const chains = this.chains.map((network) => network.caipNetworkId);
|
|
1139
|
+
return index.SIWXUtil.universalProviderAuthenticate({
|
|
1140
|
+
universalProvider: this.provider,
|
|
1141
|
+
chains,
|
|
1142
|
+
methods: OPTIONAL_METHODS
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
const OPTIONAL_METHODS = [
|
|
1147
|
+
"eth_accounts",
|
|
1148
|
+
"eth_requestAccounts",
|
|
1149
|
+
"eth_sendRawTransaction",
|
|
1150
|
+
"eth_sign",
|
|
1151
|
+
"eth_signTransaction",
|
|
1152
|
+
"eth_signTypedData",
|
|
1153
|
+
"eth_signTypedData_v3",
|
|
1154
|
+
"eth_signTypedData_v4",
|
|
1155
|
+
"eth_sendTransaction",
|
|
1156
|
+
"personal_sign",
|
|
1157
|
+
"wallet_switchEthereumChain",
|
|
1158
|
+
"wallet_addEthereumChain",
|
|
1159
|
+
"wallet_getPermissions",
|
|
1160
|
+
"wallet_requestPermissions",
|
|
1161
|
+
"wallet_registerOnboarding",
|
|
1162
|
+
"wallet_watchAsset",
|
|
1163
|
+
"wallet_scanQRCode",
|
|
1164
|
+
// EIP-5792
|
|
1165
|
+
"wallet_getCallsStatus",
|
|
1166
|
+
"wallet_sendCalls",
|
|
1167
|
+
"wallet_getCapabilities",
|
|
1168
|
+
// EIP-7715
|
|
1169
|
+
"wallet_grantPermissions",
|
|
1170
|
+
"wallet_revokePermissions",
|
|
1171
|
+
//EIP-7811
|
|
1172
|
+
"wallet_getAssets"
|
|
1173
|
+
];
|
|
1174
|
+
class AdapterBlueprint {
|
|
1175
|
+
/**
|
|
1176
|
+
* Creates an instance of AdapterBlueprint.
|
|
1177
|
+
* @param {AdapterBlueprint.Params} params - The parameters for initializing the adapter
|
|
1178
|
+
*/
|
|
1179
|
+
constructor(params) {
|
|
1180
|
+
this.availableConnectors = [];
|
|
1181
|
+
this.eventListeners = /* @__PURE__ */ new Map();
|
|
1182
|
+
if (params) {
|
|
1183
|
+
this.construct(params);
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
/**
|
|
1187
|
+
* Initializes the adapter with the given parameters.
|
|
1188
|
+
* @param {AdapterBlueprint.Params} params - The parameters for initializing the adapter
|
|
1189
|
+
*/
|
|
1190
|
+
construct(params) {
|
|
1191
|
+
this.caipNetworks = params.networks;
|
|
1192
|
+
this.projectId = params.projectId;
|
|
1193
|
+
this.namespace = params.namespace;
|
|
1194
|
+
}
|
|
1195
|
+
/**
|
|
1196
|
+
* Gets the available connectors.
|
|
1197
|
+
* @returns {Connector[]} An array of available connectors
|
|
1198
|
+
*/
|
|
1199
|
+
get connectors() {
|
|
1200
|
+
return this.availableConnectors;
|
|
1201
|
+
}
|
|
1202
|
+
/**
|
|
1203
|
+
* Gets the supported networks.
|
|
1204
|
+
* @returns {CaipNetwork[]} An array of supported networks
|
|
1205
|
+
*/
|
|
1206
|
+
get networks() {
|
|
1207
|
+
return this.caipNetworks || [];
|
|
1208
|
+
}
|
|
1209
|
+
/**
|
|
1210
|
+
* Sets the auth provider.
|
|
1211
|
+
* @param {W3mFrameProvider} authProvider - The auth provider instance
|
|
1212
|
+
*/
|
|
1213
|
+
setAuthProvider(authProvider) {
|
|
1214
|
+
this.addConnector({
|
|
1215
|
+
id: index.ConstantsUtil.CONNECTOR_ID.AUTH,
|
|
1216
|
+
type: "AUTH",
|
|
1217
|
+
name: index.ConstantsUtil.CONNECTOR_NAMES.AUTH,
|
|
1218
|
+
provider: authProvider,
|
|
1219
|
+
imageId: PresetsUtil.ConnectorImageIds[index.ConstantsUtil.CONNECTOR_ID.AUTH],
|
|
1220
|
+
chain: this.namespace,
|
|
1221
|
+
chains: []
|
|
1222
|
+
});
|
|
1223
|
+
}
|
|
1224
|
+
/**
|
|
1225
|
+
* Adds one or more connectors to the available connectors list.
|
|
1226
|
+
* @param {...Connector} connectors - The connectors to add
|
|
1227
|
+
*/
|
|
1228
|
+
addConnector(...connectors) {
|
|
1229
|
+
const connectorsAdded = /* @__PURE__ */ new Set();
|
|
1230
|
+
this.availableConnectors = [...connectors, ...this.availableConnectors].filter((connector) => {
|
|
1231
|
+
if (connectorsAdded.has(connector.id)) {
|
|
1232
|
+
return false;
|
|
1233
|
+
}
|
|
1234
|
+
connectorsAdded.add(connector.id);
|
|
1235
|
+
return true;
|
|
1236
|
+
});
|
|
1237
|
+
this.emit("connectors", this.availableConnectors);
|
|
1238
|
+
}
|
|
1239
|
+
setStatus(status, chainNamespace) {
|
|
1240
|
+
index.AccountController.setStatus(status, chainNamespace);
|
|
1241
|
+
}
|
|
1242
|
+
/**
|
|
1243
|
+
* Adds an event listener for a specific event.
|
|
1244
|
+
* @template T
|
|
1245
|
+
* @param {T} eventName - The name of the event
|
|
1246
|
+
* @param {EventCallback<T>} callback - The callback function to be called when the event is emitted
|
|
1247
|
+
*/
|
|
1248
|
+
on(eventName, callback) {
|
|
1249
|
+
var _a;
|
|
1250
|
+
if (!this.eventListeners.has(eventName)) {
|
|
1251
|
+
this.eventListeners.set(eventName, /* @__PURE__ */ new Set());
|
|
1252
|
+
}
|
|
1253
|
+
(_a = this.eventListeners.get(eventName)) == null ? void 0 : _a.add(callback);
|
|
1254
|
+
}
|
|
1255
|
+
/**
|
|
1256
|
+
* Removes an event listener for a specific event.
|
|
1257
|
+
* @template T
|
|
1258
|
+
* @param {T} eventName - The name of the event
|
|
1259
|
+
* @param {EventCallback<T>} callback - The callback function to be removed
|
|
1260
|
+
*/
|
|
1261
|
+
off(eventName, callback) {
|
|
1262
|
+
const listeners = this.eventListeners.get(eventName);
|
|
1263
|
+
if (listeners) {
|
|
1264
|
+
listeners.delete(callback);
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
/**
|
|
1268
|
+
* Removes all event listeners.
|
|
1269
|
+
*/
|
|
1270
|
+
removeAllEventListeners() {
|
|
1271
|
+
this.eventListeners.forEach((listeners) => {
|
|
1272
|
+
listeners.clear();
|
|
1273
|
+
});
|
|
1274
|
+
}
|
|
1275
|
+
/**
|
|
1276
|
+
* Emits an event with the given name and optional data.
|
|
1277
|
+
* @template T
|
|
1278
|
+
* @param {T} eventName - The name of the event to emit
|
|
1279
|
+
* @param {EventData[T]} [data] - The optional data to be passed to the event listeners
|
|
1280
|
+
*/
|
|
1281
|
+
emit(eventName, data) {
|
|
1282
|
+
const listeners = this.eventListeners.get(eventName);
|
|
1283
|
+
if (listeners) {
|
|
1284
|
+
listeners.forEach((callback) => callback(data));
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
/**
|
|
1288
|
+
* Connects to WalletConnect.
|
|
1289
|
+
* @param {number | string} [_chainId] - Optional chain ID to connect to
|
|
1290
|
+
*/
|
|
1291
|
+
async connectWalletConnect(_chainId) {
|
|
1292
|
+
const connector = this.getWalletConnectConnector();
|
|
1293
|
+
const result = await connector.connectWalletConnect();
|
|
1294
|
+
return { clientId: result.clientId };
|
|
1295
|
+
}
|
|
1296
|
+
/**
|
|
1297
|
+
* Switches the network.
|
|
1298
|
+
* @param {AdapterBlueprint.SwitchNetworkParams} params - Network switching parameters
|
|
1299
|
+
*/
|
|
1300
|
+
async switchNetwork(params) {
|
|
1301
|
+
const { caipNetwork, providerType } = params;
|
|
1302
|
+
if (!params.provider) {
|
|
1303
|
+
return;
|
|
1304
|
+
}
|
|
1305
|
+
const provider = "provider" in params.provider ? params.provider.provider : params.provider;
|
|
1306
|
+
if (providerType === "WALLET_CONNECT") {
|
|
1307
|
+
provider.setDefaultChain(caipNetwork.caipNetworkId);
|
|
1308
|
+
return;
|
|
1309
|
+
}
|
|
1310
|
+
if (provider && providerType === "AUTH") {
|
|
1311
|
+
const authProvider = provider;
|
|
1312
|
+
await authProvider.switchNetwork(caipNetwork.caipNetworkId);
|
|
1313
|
+
const user = await authProvider.getUser({
|
|
1314
|
+
chainId: caipNetwork.caipNetworkId,
|
|
1315
|
+
preferredAccountType: index.OptionsController.state.defaultAccountTypes[caipNetwork.chainNamespace]
|
|
1316
|
+
});
|
|
1317
|
+
this.emit("switchNetwork", user);
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
getWalletConnectConnector() {
|
|
1321
|
+
const connector = this.connectors.find((c) => c instanceof WalletConnectConnector);
|
|
1322
|
+
if (!connector) {
|
|
1323
|
+
throw new Error("WalletConnectConnector not found");
|
|
1324
|
+
}
|
|
1325
|
+
return connector;
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
class UniversalAdapter extends AdapterBlueprint {
|
|
1329
|
+
setUniversalProvider(universalProvider) {
|
|
1330
|
+
this.addConnector(new WalletConnectConnector({
|
|
1331
|
+
provider: universalProvider,
|
|
1332
|
+
caipNetworks: this.caipNetworks || [],
|
|
1333
|
+
namespace: this.namespace
|
|
1334
|
+
}));
|
|
1335
|
+
}
|
|
1336
|
+
async connect(params) {
|
|
1337
|
+
return Promise.resolve({
|
|
1338
|
+
id: "WALLET_CONNECT",
|
|
1339
|
+
type: "WALLET_CONNECT",
|
|
1340
|
+
chainId: Number(params.chainId),
|
|
1341
|
+
provider: this.provider,
|
|
1342
|
+
address: ""
|
|
1343
|
+
});
|
|
1344
|
+
}
|
|
1345
|
+
async disconnect() {
|
|
1346
|
+
try {
|
|
1347
|
+
const connector = this.getWalletConnectConnector();
|
|
1348
|
+
await connector.disconnect();
|
|
1349
|
+
} catch (error) {
|
|
1350
|
+
console.warn("UniversalAdapter:disconnect - error", error);
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
async getAccounts({ namespace }) {
|
|
1354
|
+
var _a, _b, _c, _d;
|
|
1355
|
+
const provider = this.provider;
|
|
1356
|
+
const addresses = ((_d = (_c = (_b = (_a = provider == null ? void 0 : provider.session) == null ? void 0 : _a.namespaces) == null ? void 0 : _b[namespace]) == null ? void 0 : _c.accounts) == null ? void 0 : _d.map((account) => {
|
|
1357
|
+
const [, , address] = account.split(":");
|
|
1358
|
+
return address;
|
|
1359
|
+
}).filter((address, index2, self) => self.indexOf(address) === index2)) || [];
|
|
1360
|
+
return Promise.resolve({
|
|
1361
|
+
accounts: addresses.map((address) => index.CoreHelperUtil.createAccount(namespace, address, namespace === "bip122" ? "payment" : "eoa"))
|
|
1362
|
+
});
|
|
1363
|
+
}
|
|
1364
|
+
async syncConnectors() {
|
|
1365
|
+
return Promise.resolve();
|
|
1366
|
+
}
|
|
1367
|
+
async getBalance(params) {
|
|
1368
|
+
var _a, _b, _c, _d, _e;
|
|
1369
|
+
const isBalanceSupported = params.caipNetwork && index.ConstantsUtil$2.BALANCE_SUPPORTED_CHAINS.includes((_a = params.caipNetwork) == null ? void 0 : _a.chainNamespace);
|
|
1370
|
+
if (!isBalanceSupported || ((_b = params.caipNetwork) == null ? void 0 : _b.testnet)) {
|
|
1371
|
+
return {
|
|
1372
|
+
balance: "0.00",
|
|
1373
|
+
symbol: ((_c = params.caipNetwork) == null ? void 0 : _c.nativeCurrency.symbol) || ""
|
|
1374
|
+
};
|
|
1375
|
+
}
|
|
1376
|
+
if (index.AccountController.state.balanceLoading && params.chainId === ((_d = index.ChainController.state.activeCaipNetwork) == null ? void 0 : _d.id)) {
|
|
1377
|
+
return {
|
|
1378
|
+
balance: index.AccountController.state.balance || "0.00",
|
|
1379
|
+
symbol: index.AccountController.state.balanceSymbol || ""
|
|
1380
|
+
};
|
|
1381
|
+
}
|
|
1382
|
+
const balances = await index.AccountController.fetchTokenBalance();
|
|
1383
|
+
const balance = balances.find((b) => {
|
|
1384
|
+
var _a2, _b2;
|
|
1385
|
+
return b.chainId === `${(_a2 = params.caipNetwork) == null ? void 0 : _a2.chainNamespace}:${params.chainId}` && b.symbol === ((_b2 = params.caipNetwork) == null ? void 0 : _b2.nativeCurrency.symbol);
|
|
1386
|
+
});
|
|
1387
|
+
return {
|
|
1388
|
+
balance: (balance == null ? void 0 : balance.quantity.numeric) || "0.00",
|
|
1389
|
+
symbol: (balance == null ? void 0 : balance.symbol) || ((_e = params.caipNetwork) == null ? void 0 : _e.nativeCurrency.symbol) || ""
|
|
1390
|
+
};
|
|
1391
|
+
}
|
|
1392
|
+
async signMessage(params) {
|
|
1393
|
+
var _a, _b, _c;
|
|
1394
|
+
const { provider, message, address } = params;
|
|
1395
|
+
if (!provider) {
|
|
1396
|
+
throw new Error("UniversalAdapter:signMessage - provider is undefined");
|
|
1397
|
+
}
|
|
1398
|
+
let signature = "";
|
|
1399
|
+
if (((_a = index.ChainController.state.activeCaipNetwork) == null ? void 0 : _a.chainNamespace) === index.ConstantsUtil.CHAIN.SOLANA) {
|
|
1400
|
+
const response = await provider.request({
|
|
1401
|
+
method: "solana_signMessage",
|
|
1402
|
+
params: {
|
|
1403
|
+
message: index.bs58.encode(new TextEncoder().encode(message)),
|
|
1404
|
+
pubkey: address
|
|
1405
|
+
}
|
|
1406
|
+
}, (_b = index.ChainController.state.activeCaipNetwork) == null ? void 0 : _b.caipNetworkId);
|
|
1407
|
+
signature = response.signature;
|
|
1408
|
+
} else {
|
|
1409
|
+
signature = await provider.request({
|
|
1410
|
+
method: "personal_sign",
|
|
1411
|
+
params: [message, address]
|
|
1412
|
+
}, (_c = index.ChainController.state.activeCaipNetwork) == null ? void 0 : _c.caipNetworkId);
|
|
1413
|
+
}
|
|
1414
|
+
return { signature };
|
|
1415
|
+
}
|
|
1416
|
+
// -- Transaction methods ---------------------------------------------------
|
|
1417
|
+
/**
|
|
1418
|
+
*
|
|
1419
|
+
* These methods are supported only on `wagmi` and `ethers` since the Solana SDK does not support them in the same way.
|
|
1420
|
+
* These function definition is to have a type parity between the clients. Currently not in use.
|
|
1421
|
+
*/
|
|
1422
|
+
async estimateGas() {
|
|
1423
|
+
return Promise.resolve({
|
|
1424
|
+
gas: BigInt(0)
|
|
1425
|
+
});
|
|
1426
|
+
}
|
|
1427
|
+
async getProfile() {
|
|
1428
|
+
return Promise.resolve({
|
|
1429
|
+
profileImage: "",
|
|
1430
|
+
profileName: ""
|
|
1431
|
+
});
|
|
1432
|
+
}
|
|
1433
|
+
async sendTransaction() {
|
|
1434
|
+
return Promise.resolve({
|
|
1435
|
+
hash: ""
|
|
1436
|
+
});
|
|
1437
|
+
}
|
|
1438
|
+
async writeContract() {
|
|
1439
|
+
return Promise.resolve({
|
|
1440
|
+
hash: ""
|
|
1441
|
+
});
|
|
1442
|
+
}
|
|
1443
|
+
async getEnsAddress() {
|
|
1444
|
+
return Promise.resolve({
|
|
1445
|
+
address: false
|
|
1446
|
+
});
|
|
1447
|
+
}
|
|
1448
|
+
parseUnits() {
|
|
1449
|
+
return 0n;
|
|
1450
|
+
}
|
|
1451
|
+
formatUnits() {
|
|
1452
|
+
return "0";
|
|
1453
|
+
}
|
|
1454
|
+
async getCapabilities() {
|
|
1455
|
+
return Promise.resolve({});
|
|
1456
|
+
}
|
|
1457
|
+
async grantPermissions() {
|
|
1458
|
+
return Promise.resolve({});
|
|
1459
|
+
}
|
|
1460
|
+
async revokePermissions() {
|
|
1461
|
+
return Promise.resolve("0x");
|
|
1462
|
+
}
|
|
1463
|
+
async syncConnection() {
|
|
1464
|
+
return Promise.resolve({
|
|
1465
|
+
id: "WALLET_CONNECT",
|
|
1466
|
+
type: "WALLET_CONNECT",
|
|
1467
|
+
chainId: 1,
|
|
1468
|
+
provider: this.provider,
|
|
1469
|
+
address: ""
|
|
1470
|
+
});
|
|
1471
|
+
}
|
|
1472
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
1473
|
+
async switchNetwork(params) {
|
|
1474
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1475
|
+
const { caipNetwork } = params;
|
|
1476
|
+
const connector = this.getWalletConnectConnector();
|
|
1477
|
+
if (caipNetwork.chainNamespace === index.ConstantsUtil.CHAIN.EVM) {
|
|
1478
|
+
try {
|
|
1479
|
+
await ((_a = connector.provider) == null ? void 0 : _a.request({
|
|
1480
|
+
method: "wallet_switchEthereumChain",
|
|
1481
|
+
params: [{ chainId: viem.toHex(caipNetwork.id) }]
|
|
1482
|
+
}));
|
|
1483
|
+
} catch (switchError) {
|
|
1484
|
+
if (switchError.code === WcConstantsUtil.ERROR_CODE_UNRECOGNIZED_CHAIN_ID || switchError.code === WcConstantsUtil.ERROR_CODE_DEFAULT || ((_c = (_b = switchError == null ? void 0 : switchError.data) == null ? void 0 : _b.originalError) == null ? void 0 : _c.code) === WcConstantsUtil.ERROR_CODE_UNRECOGNIZED_CHAIN_ID) {
|
|
1485
|
+
try {
|
|
1486
|
+
await ((_f = connector.provider) == null ? void 0 : _f.request({
|
|
1487
|
+
method: "wallet_addEthereumChain",
|
|
1488
|
+
params: [
|
|
1489
|
+
{
|
|
1490
|
+
chainId: viem.toHex(caipNetwork.id),
|
|
1491
|
+
rpcUrls: [(_d = caipNetwork == null ? void 0 : caipNetwork.rpcUrls["chainDefault"]) == null ? void 0 : _d.http],
|
|
1492
|
+
chainName: caipNetwork.name,
|
|
1493
|
+
nativeCurrency: caipNetwork.nativeCurrency,
|
|
1494
|
+
blockExplorerUrls: [(_e = caipNetwork.blockExplorers) == null ? void 0 : _e.default.url]
|
|
1495
|
+
}
|
|
1496
|
+
]
|
|
1497
|
+
}));
|
|
1498
|
+
} catch (error) {
|
|
1499
|
+
throw new Error("Chain is not supported");
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
connector.provider.setDefaultChain(caipNetwork.caipNetworkId);
|
|
1505
|
+
}
|
|
1506
|
+
getWalletConnectProvider() {
|
|
1507
|
+
const connector = this.connectors.find((c) => c.type === "WALLET_CONNECT");
|
|
1508
|
+
const provider = connector == null ? void 0 : connector.provider;
|
|
1509
|
+
return provider;
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
let isInitialized = false;
|
|
1513
|
+
class AppKit {
|
|
1514
|
+
constructor(options) {
|
|
1515
|
+
var _a;
|
|
1516
|
+
this.chainNamespaces = [];
|
|
1517
|
+
this.initPromise = void 0;
|
|
1518
|
+
this.reportedAlertErrors = {};
|
|
1519
|
+
this.setStatus = (status, chain) => {
|
|
1520
|
+
index.StorageUtil.setConnectionStatus(status);
|
|
1521
|
+
index.AccountController.setStatus(status, chain);
|
|
1522
|
+
};
|
|
1523
|
+
this.getIsConnectedState = () => Boolean(index.ChainController.state.activeCaipAddress);
|
|
1524
|
+
this.setAllAccounts = (addresses, chain) => {
|
|
1525
|
+
index.AccountController.setAllAccounts(addresses, chain);
|
|
1526
|
+
index.OptionsController.setHasMultipleAddresses((addresses == null ? void 0 : addresses.length) > 1);
|
|
1527
|
+
};
|
|
1528
|
+
this.addAddressLabel = (address, label, chain) => {
|
|
1529
|
+
index.AccountController.addAddressLabel(address, label, chain);
|
|
1530
|
+
};
|
|
1531
|
+
this.removeAddressLabel = (address, chain) => {
|
|
1532
|
+
index.AccountController.removeAddressLabel(address, chain);
|
|
1533
|
+
};
|
|
1534
|
+
this.getCaipAddress = (chainNamespace) => {
|
|
1535
|
+
if (index.ChainController.state.activeChain === chainNamespace || !chainNamespace) {
|
|
1536
|
+
return index.ChainController.state.activeCaipAddress;
|
|
1537
|
+
}
|
|
1538
|
+
return index.ChainController.getAccountProp("caipAddress", chainNamespace);
|
|
1539
|
+
};
|
|
1540
|
+
this.getAddressByChainNamespace = (chainNamespace) => index.ChainController.getAccountProp("address", chainNamespace);
|
|
1541
|
+
this.getAddress = (chainNamespace) => {
|
|
1542
|
+
if (index.ChainController.state.activeChain === chainNamespace || !chainNamespace) {
|
|
1543
|
+
return index.AccountController.state.address;
|
|
1544
|
+
}
|
|
1545
|
+
return index.ChainController.getAccountProp("address", chainNamespace);
|
|
1546
|
+
};
|
|
1547
|
+
this.getProvider = (namespace) => index.ProviderUtil.getProvider(namespace);
|
|
1548
|
+
this.getProviderType = (namespace) => index.ProviderUtil.state.providerIds[namespace];
|
|
1549
|
+
this.getPreferredAccountType = () => index.AccountController.state.preferredAccountType;
|
|
1550
|
+
this.setCaipAddress = (caipAddress, chain) => {
|
|
1551
|
+
index.AccountController.setCaipAddress(caipAddress, chain);
|
|
1552
|
+
};
|
|
1553
|
+
this.setBalance = (balance, balanceSymbol, chain) => {
|
|
1554
|
+
index.AccountController.setBalance(balance, balanceSymbol, chain);
|
|
1555
|
+
};
|
|
1556
|
+
this.setProfileName = (profileName, chain) => {
|
|
1557
|
+
index.AccountController.setProfileName(profileName, chain);
|
|
1558
|
+
};
|
|
1559
|
+
this.setProfileImage = (profileImage, chain) => {
|
|
1560
|
+
index.AccountController.setProfileImage(profileImage, chain);
|
|
1561
|
+
};
|
|
1562
|
+
this.setUser = (user) => {
|
|
1563
|
+
index.AccountController.setUser(user);
|
|
1564
|
+
if (index.OptionsController.state.enableEmbedded) {
|
|
1565
|
+
index.ModalController.close();
|
|
1566
|
+
}
|
|
1567
|
+
};
|
|
1568
|
+
this.resetAccount = (chain) => {
|
|
1569
|
+
index.AccountController.resetAccount(chain);
|
|
1570
|
+
};
|
|
1571
|
+
this.setCaipNetwork = (caipNetwork) => {
|
|
1572
|
+
index.ChainController.setActiveCaipNetwork(caipNetwork);
|
|
1573
|
+
};
|
|
1574
|
+
this.getCaipNetwork = (chainNamespace) => {
|
|
1575
|
+
var _a2;
|
|
1576
|
+
if (chainNamespace) {
|
|
1577
|
+
return (_a2 = index.ChainController.getRequestedCaipNetworks(chainNamespace).filter((c) => c.chainNamespace === chainNamespace)) == null ? void 0 : _a2[0];
|
|
1578
|
+
}
|
|
1579
|
+
return index.ChainController.state.activeCaipNetwork || this.defaultCaipNetwork;
|
|
1580
|
+
};
|
|
1581
|
+
this.getCaipNetworkId = () => {
|
|
1582
|
+
const network = this.getCaipNetwork();
|
|
1583
|
+
if (network) {
|
|
1584
|
+
return network.id;
|
|
1585
|
+
}
|
|
1586
|
+
return void 0;
|
|
1587
|
+
};
|
|
1588
|
+
this.getCaipNetworks = (namespace) => index.ChainController.getRequestedCaipNetworks(namespace);
|
|
1589
|
+
this.getActiveChainNamespace = () => index.ChainController.state.activeChain;
|
|
1590
|
+
this.setRequestedCaipNetworks = (requestedCaipNetworks, chain) => {
|
|
1591
|
+
index.ChainController.setRequestedCaipNetworks(requestedCaipNetworks, chain);
|
|
1592
|
+
};
|
|
1593
|
+
this.getApprovedCaipNetworkIds = () => index.ChainController.getAllApprovedCaipNetworkIds();
|
|
1594
|
+
this.setApprovedCaipNetworksData = (namespace) => index.ChainController.setApprovedCaipNetworksData(namespace);
|
|
1595
|
+
this.resetNetwork = (namespace) => {
|
|
1596
|
+
index.ChainController.resetNetwork(namespace);
|
|
1597
|
+
};
|
|
1598
|
+
this.setConnectors = (connectors) => {
|
|
1599
|
+
const allConnectors = [...index.ConnectorController.getConnectors(), ...connectors];
|
|
1600
|
+
index.ConnectorController.setConnectors(allConnectors);
|
|
1601
|
+
};
|
|
1602
|
+
this.addConnector = (connector) => {
|
|
1603
|
+
index.ConnectorController.addConnector(connector);
|
|
1604
|
+
};
|
|
1605
|
+
this.getConnectors = () => index.ConnectorController.getConnectors();
|
|
1606
|
+
this.resetWcConnection = () => {
|
|
1607
|
+
index.ConnectionController.resetWcConnection();
|
|
1608
|
+
};
|
|
1609
|
+
this.fetchIdentity = (request) => index.BlockchainApiController.fetchIdentity(request);
|
|
1610
|
+
this.setAddressExplorerUrl = (addressExplorerUrl, chain) => {
|
|
1611
|
+
index.AccountController.setAddressExplorerUrl(addressExplorerUrl, chain);
|
|
1612
|
+
};
|
|
1613
|
+
this.setSmartAccountDeployed = (isDeployed, chain) => {
|
|
1614
|
+
index.AccountController.setSmartAccountDeployed(isDeployed, chain);
|
|
1615
|
+
};
|
|
1616
|
+
this.setConnectedWalletInfo = (connectedWalletInfo, chain) => {
|
|
1617
|
+
index.AccountController.setConnectedWalletInfo(connectedWalletInfo, chain);
|
|
1618
|
+
};
|
|
1619
|
+
this.setSmartAccountEnabledNetworks = (smartAccountEnabledNetworks, chain) => {
|
|
1620
|
+
index.ChainController.setSmartAccountEnabledNetworks(smartAccountEnabledNetworks, chain);
|
|
1621
|
+
};
|
|
1622
|
+
this.setPreferredAccountType = (preferredAccountType, chain) => {
|
|
1623
|
+
index.AccountController.setPreferredAccountType(preferredAccountType, chain);
|
|
1624
|
+
};
|
|
1625
|
+
this.getReownName = (address) => index.EnsController.getNamesForAddress(address);
|
|
1626
|
+
this.setEIP6963Enabled = (enabled) => {
|
|
1627
|
+
index.OptionsController.setEIP6963Enabled(enabled);
|
|
1628
|
+
};
|
|
1629
|
+
this.setClientId = (clientId) => {
|
|
1630
|
+
index.BlockchainApiController.setClientId(clientId);
|
|
1631
|
+
};
|
|
1632
|
+
this.getConnectorImage = (connector) => index.AssetUtil.getConnectorImage(connector);
|
|
1633
|
+
this.handleUnsafeRPCRequest = () => {
|
|
1634
|
+
if (this.isOpen()) {
|
|
1635
|
+
if (this.isTransactionStackEmpty()) {
|
|
1636
|
+
return;
|
|
1637
|
+
}
|
|
1638
|
+
this.redirect("ApproveTransaction");
|
|
1639
|
+
} else {
|
|
1640
|
+
this.open({ view: "ApproveTransaction" });
|
|
1641
|
+
}
|
|
1642
|
+
};
|
|
1643
|
+
this.options = options;
|
|
1644
|
+
this.version = options.sdkVersion;
|
|
1645
|
+
this.caipNetworks = this.extendCaipNetworks(options);
|
|
1646
|
+
this.chainNamespaces = [
|
|
1647
|
+
...new Set((_a = this.caipNetworks) == null ? void 0 : _a.map((caipNetwork) => caipNetwork.chainNamespace))
|
|
1648
|
+
];
|
|
1649
|
+
this.defaultCaipNetwork = this.extendDefaultCaipNetwork(options);
|
|
1650
|
+
this.chainAdapters = this.createAdapters(options.adapters);
|
|
1651
|
+
this.initialize(options);
|
|
1652
|
+
this.sendInitializeEvent(options);
|
|
1653
|
+
}
|
|
1654
|
+
static getInstance() {
|
|
1655
|
+
return this.instance;
|
|
1656
|
+
}
|
|
1657
|
+
async initialize(options) {
|
|
1658
|
+
this.initControllers(options);
|
|
1659
|
+
await this.initChainAdapters();
|
|
1660
|
+
await this.injectModalUi();
|
|
1661
|
+
await this.syncExistingConnection();
|
|
1662
|
+
index.PublicStateController.set({ initialized: true });
|
|
1663
|
+
}
|
|
1664
|
+
sendInitializeEvent(options) {
|
|
1665
|
+
var _a;
|
|
1666
|
+
const { ...optionsCopy } = options;
|
|
1667
|
+
delete optionsCopy.adapters;
|
|
1668
|
+
index.EventsController.sendEvent({
|
|
1669
|
+
type: "track",
|
|
1670
|
+
event: "INITIALIZE",
|
|
1671
|
+
properties: {
|
|
1672
|
+
...optionsCopy,
|
|
1673
|
+
networks: options.networks.map((n) => n.id),
|
|
1674
|
+
siweConfig: {
|
|
1675
|
+
options: ((_a = options.siweConfig) == null ? void 0 : _a.options) || {}
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
});
|
|
1679
|
+
}
|
|
1680
|
+
// -- Public -------------------------------------------------------------------
|
|
1681
|
+
async open(options) {
|
|
1682
|
+
await this.injectModalUi();
|
|
1683
|
+
if ((options == null ? void 0 : options.uri) && this.universalProvider) {
|
|
1684
|
+
index.ConnectionController.setUri(options.uri);
|
|
1685
|
+
}
|
|
1686
|
+
if (options == null ? void 0 : options.namespace) {
|
|
1687
|
+
index.ConnectorController.setFilterByNamespace(options.namespace);
|
|
1688
|
+
}
|
|
1689
|
+
await index.ModalController.open(options);
|
|
1690
|
+
}
|
|
1691
|
+
async close() {
|
|
1692
|
+
await this.injectModalUi();
|
|
1693
|
+
index.ModalController.close();
|
|
1694
|
+
}
|
|
1695
|
+
setLoading(loading) {
|
|
1696
|
+
index.ModalController.setLoading(loading);
|
|
1697
|
+
}
|
|
1698
|
+
// -- Adapter Methods ----------------------------------------------------------
|
|
1699
|
+
getError() {
|
|
1700
|
+
return "";
|
|
1701
|
+
}
|
|
1702
|
+
getChainId() {
|
|
1703
|
+
var _a;
|
|
1704
|
+
return (_a = index.ChainController.state.activeCaipNetwork) == null ? void 0 : _a.id;
|
|
1705
|
+
}
|
|
1706
|
+
switchNetwork(appKitNetwork) {
|
|
1707
|
+
var _a;
|
|
1708
|
+
const network = (_a = this.caipNetworks) == null ? void 0 : _a.find((n) => n.id === appKitNetwork.id);
|
|
1709
|
+
if (!network) {
|
|
1710
|
+
index.AlertController.open(ErrorUtil.ALERT_ERRORS.SWITCH_NETWORK_NOT_FOUND, "error");
|
|
1711
|
+
return;
|
|
1712
|
+
}
|
|
1713
|
+
index.ChainController.switchActiveNetwork(network);
|
|
1714
|
+
}
|
|
1715
|
+
getWalletProvider() {
|
|
1716
|
+
return index.ChainController.state.activeChain ? index.ProviderUtil.state.providers[index.ChainController.state.activeChain] : null;
|
|
1717
|
+
}
|
|
1718
|
+
getWalletProviderType() {
|
|
1719
|
+
return index.ChainController.state.activeChain ? index.ProviderUtil.state.providerIds[index.ChainController.state.activeChain] : null;
|
|
1720
|
+
}
|
|
1721
|
+
subscribeProviders(callback) {
|
|
1722
|
+
return index.ProviderUtil.subscribeProviders(callback);
|
|
1723
|
+
}
|
|
1724
|
+
getThemeMode() {
|
|
1725
|
+
return index.ThemeController.state.themeMode;
|
|
1726
|
+
}
|
|
1727
|
+
getThemeVariables() {
|
|
1728
|
+
return index.ThemeController.state.themeVariables;
|
|
1729
|
+
}
|
|
1730
|
+
setThemeMode(themeMode) {
|
|
1731
|
+
index.ThemeController.setThemeMode(themeMode);
|
|
1732
|
+
index.setColorTheme(index.ThemeController.state.themeMode);
|
|
1733
|
+
}
|
|
1734
|
+
setTermsConditionsUrl(termsConditionsUrl) {
|
|
1735
|
+
index.OptionsController.setTermsConditionsUrl(termsConditionsUrl);
|
|
1736
|
+
}
|
|
1737
|
+
setPrivacyPolicyUrl(privacyPolicyUrl) {
|
|
1738
|
+
index.OptionsController.setPrivacyPolicyUrl(privacyPolicyUrl);
|
|
1739
|
+
}
|
|
1740
|
+
setThemeVariables(themeVariables) {
|
|
1741
|
+
index.ThemeController.setThemeVariables(themeVariables);
|
|
1742
|
+
index.setThemeVariables(index.ThemeController.state.themeVariables);
|
|
1743
|
+
}
|
|
1744
|
+
subscribeTheme(callback) {
|
|
1745
|
+
return index.ThemeController.subscribe(callback);
|
|
1746
|
+
}
|
|
1747
|
+
getWalletInfo() {
|
|
1748
|
+
return index.AccountController.state.connectedWalletInfo;
|
|
1749
|
+
}
|
|
1750
|
+
subscribeAccount(callback) {
|
|
1751
|
+
function updateVal() {
|
|
1752
|
+
const authConnector = index.ConnectorController.getAuthConnector();
|
|
1753
|
+
callback({
|
|
1754
|
+
allAccounts: index.AccountController.state.allAccounts,
|
|
1755
|
+
caipAddress: index.ChainController.state.activeCaipAddress,
|
|
1756
|
+
address: index.CoreHelperUtil.getPlainAddress(index.ChainController.state.activeCaipAddress),
|
|
1757
|
+
isConnected: Boolean(index.ChainController.state.activeCaipAddress),
|
|
1758
|
+
status: index.AccountController.state.status,
|
|
1759
|
+
embeddedWalletInfo: authConnector ? {
|
|
1760
|
+
user: index.AccountController.state.user,
|
|
1761
|
+
authProvider: index.AccountController.state.socialProvider || "email",
|
|
1762
|
+
accountType: index.AccountController.state.preferredAccountType,
|
|
1763
|
+
isSmartAccountDeployed: Boolean(index.AccountController.state.smartAccountDeployed)
|
|
1764
|
+
} : void 0
|
|
1765
|
+
});
|
|
1766
|
+
}
|
|
1767
|
+
index.ChainController.subscribe(updateVal);
|
|
1768
|
+
index.AccountController.subscribe(updateVal);
|
|
1769
|
+
index.ConnectorController.subscribe(updateVal);
|
|
1770
|
+
}
|
|
1771
|
+
subscribeNetwork(callback) {
|
|
1772
|
+
return index.ChainController.subscribe(({ activeCaipNetwork }) => {
|
|
1773
|
+
callback({
|
|
1774
|
+
caipNetwork: activeCaipNetwork,
|
|
1775
|
+
chainId: activeCaipNetwork == null ? void 0 : activeCaipNetwork.id,
|
|
1776
|
+
caipNetworkId: activeCaipNetwork == null ? void 0 : activeCaipNetwork.caipNetworkId
|
|
1777
|
+
});
|
|
1778
|
+
});
|
|
1779
|
+
}
|
|
1780
|
+
subscribeWalletInfo(callback) {
|
|
1781
|
+
return index.AccountController.subscribeKey("connectedWalletInfo", callback);
|
|
1782
|
+
}
|
|
1783
|
+
subscribeShouldUpdateToAddress(callback) {
|
|
1784
|
+
index.AccountController.subscribeKey("shouldUpdateToAddress", callback);
|
|
1785
|
+
}
|
|
1786
|
+
subscribeCaipNetworkChange(callback) {
|
|
1787
|
+
index.ChainController.subscribeKey("activeCaipNetwork", callback);
|
|
1788
|
+
}
|
|
1789
|
+
getState() {
|
|
1790
|
+
return index.PublicStateController.state;
|
|
1791
|
+
}
|
|
1792
|
+
subscribeState(callback) {
|
|
1793
|
+
return index.PublicStateController.subscribe(callback);
|
|
1794
|
+
}
|
|
1795
|
+
showErrorMessage(message) {
|
|
1796
|
+
index.SnackController.showError(message);
|
|
1797
|
+
}
|
|
1798
|
+
showSuccessMessage(message) {
|
|
1799
|
+
index.SnackController.showSuccess(message);
|
|
1800
|
+
}
|
|
1801
|
+
getEvent() {
|
|
1802
|
+
return { ...index.EventsController.state };
|
|
1803
|
+
}
|
|
1804
|
+
subscribeEvents(callback) {
|
|
1805
|
+
return index.EventsController.subscribe(callback);
|
|
1806
|
+
}
|
|
1807
|
+
replace(route) {
|
|
1808
|
+
index.RouterController.replace(route);
|
|
1809
|
+
}
|
|
1810
|
+
redirect(route) {
|
|
1811
|
+
index.RouterController.push(route);
|
|
1812
|
+
}
|
|
1813
|
+
popTransactionStack(cancel) {
|
|
1814
|
+
index.RouterController.popTransactionStack(cancel);
|
|
1815
|
+
}
|
|
1816
|
+
isOpen() {
|
|
1817
|
+
return index.ModalController.state.open;
|
|
1818
|
+
}
|
|
1819
|
+
isTransactionStackEmpty() {
|
|
1820
|
+
return index.RouterController.state.transactionStack.length === 0;
|
|
1821
|
+
}
|
|
1822
|
+
updateFeatures(newFeatures) {
|
|
1823
|
+
index.OptionsController.setFeatures(newFeatures);
|
|
1824
|
+
}
|
|
1825
|
+
updateOptions(newOptions) {
|
|
1826
|
+
const currentOptions = index.OptionsController.state || {};
|
|
1827
|
+
const updatedOptions = { ...currentOptions, ...newOptions };
|
|
1828
|
+
index.OptionsController.setOptions(updatedOptions);
|
|
1829
|
+
}
|
|
1830
|
+
setConnectMethodsOrder(connectMethodsOrder) {
|
|
1831
|
+
index.OptionsController.setConnectMethodsOrder(connectMethodsOrder);
|
|
1832
|
+
}
|
|
1833
|
+
setWalletFeaturesOrder(walletFeaturesOrder) {
|
|
1834
|
+
index.OptionsController.setWalletFeaturesOrder(walletFeaturesOrder);
|
|
1835
|
+
}
|
|
1836
|
+
setCollapseWallets(collapseWallets) {
|
|
1837
|
+
index.OptionsController.setCollapseWallets(collapseWallets);
|
|
1838
|
+
}
|
|
1839
|
+
setSocialsOrder(socialsOrder) {
|
|
1840
|
+
index.OptionsController.setSocialsOrder(socialsOrder);
|
|
1841
|
+
}
|
|
1842
|
+
async disconnect() {
|
|
1843
|
+
await index.ConnectionController.disconnect();
|
|
1844
|
+
}
|
|
1845
|
+
getConnectMethodsOrder() {
|
|
1846
|
+
return index.WalletUtil.getConnectOrderMethod(index.OptionsController.state.features, index.ConnectorController.getConnectors());
|
|
1847
|
+
}
|
|
1848
|
+
/**
|
|
1849
|
+
* Removes an adapter from the AppKit.
|
|
1850
|
+
* @param namespace - The namespace of the adapter to remove.
|
|
1851
|
+
*/
|
|
1852
|
+
removeAdapter(namespace) {
|
|
1853
|
+
var _a;
|
|
1854
|
+
const isConnected = this.getIsConnectedState();
|
|
1855
|
+
const adapter = this.getAdapter(namespace);
|
|
1856
|
+
if (!adapter || !this.chainAdapters || isConnected) {
|
|
1857
|
+
return;
|
|
1858
|
+
}
|
|
1859
|
+
const newCaipNetworks = (_a = this.caipNetworks) == null ? void 0 : _a.filter((network) => network.chainNamespace !== namespace);
|
|
1860
|
+
index.ChainController.removeAdapter(namespace);
|
|
1861
|
+
index.ConnectorController.removeAdapter(namespace);
|
|
1862
|
+
this.chainNamespaces = this.chainNamespaces.filter((n) => n !== namespace);
|
|
1863
|
+
this.caipNetworks = newCaipNetworks;
|
|
1864
|
+
adapter.removeAllEventListeners();
|
|
1865
|
+
Reflect.deleteProperty(this.chainAdapters, namespace);
|
|
1866
|
+
}
|
|
1867
|
+
/**
|
|
1868
|
+
* Adds an adapter to the AppKit.
|
|
1869
|
+
* @param adapter - The adapter instance.
|
|
1870
|
+
* @param networks - The list of networks that this adapter supports / uses.
|
|
1871
|
+
*/
|
|
1872
|
+
addAdapter(adapter, networks) {
|
|
1873
|
+
const namespace = adapter.namespace;
|
|
1874
|
+
if (!this.connectionControllerClient || !this.networkControllerClient) {
|
|
1875
|
+
return;
|
|
1876
|
+
}
|
|
1877
|
+
if (!this.chainAdapters || !namespace) {
|
|
1878
|
+
return;
|
|
1879
|
+
}
|
|
1880
|
+
const extendedAdapterNetworks = this.extendCaipNetworks({ ...this.options, networks });
|
|
1881
|
+
this.caipNetworks = [...this.caipNetworks || [], ...extendedAdapterNetworks];
|
|
1882
|
+
this.createAdapter(adapter);
|
|
1883
|
+
this.initChainAdapter(namespace);
|
|
1884
|
+
index.ChainController.addAdapter(adapter, {
|
|
1885
|
+
connectionControllerClient: this.connectionControllerClient,
|
|
1886
|
+
networkControllerClient: this.networkControllerClient
|
|
1887
|
+
}, extendedAdapterNetworks);
|
|
1888
|
+
}
|
|
1889
|
+
/**
|
|
1890
|
+
* Adds a network to an existing adapter in AppKit.
|
|
1891
|
+
* @param namespace - The chain namespace to add the network to (e.g. 'eip155', 'solana')
|
|
1892
|
+
* @param network - The network configuration to add
|
|
1893
|
+
* @throws Error if adapter for namespace doesn't exist
|
|
1894
|
+
*/
|
|
1895
|
+
addNetwork(namespace, network) {
|
|
1896
|
+
var _a;
|
|
1897
|
+
if (this.chainAdapters && !this.chainAdapters[namespace]) {
|
|
1898
|
+
throw new Error(`Adapter for namespace ${namespace} doesn't exist`);
|
|
1899
|
+
}
|
|
1900
|
+
const extendedNetwork = this.extendCaipNetwork(network, this.options);
|
|
1901
|
+
if (this.caipNetworks && !((_a = this.caipNetworks) == null ? void 0 : _a.find((n) => n.id === extendedNetwork.id))) {
|
|
1902
|
+
this.caipNetworks.push(extendedNetwork);
|
|
1903
|
+
index.ChainController.addNetwork(extendedNetwork);
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
/**
|
|
1907
|
+
* Removes a network from an existing adapter in AppKit.
|
|
1908
|
+
* @param namespace - The chain namespace the network belongs to
|
|
1909
|
+
* @param networkId - The network ID to remove
|
|
1910
|
+
* @throws Error if adapter for namespace doesn't exist or if removing last network
|
|
1911
|
+
*/
|
|
1912
|
+
removeNetwork(namespace, networkId) {
|
|
1913
|
+
var _a;
|
|
1914
|
+
if (this.chainAdapters && !this.chainAdapters[namespace]) {
|
|
1915
|
+
throw new Error(`Adapter for namespace ${namespace} doesn't exist`);
|
|
1916
|
+
}
|
|
1917
|
+
const networkToRemove = (_a = this.caipNetworks) == null ? void 0 : _a.find((n) => n.id === networkId);
|
|
1918
|
+
if (!networkToRemove) {
|
|
1919
|
+
throw new Error(`Network with ID ${networkId} not found`);
|
|
1920
|
+
}
|
|
1921
|
+
if (!this.caipNetworks) {
|
|
1922
|
+
return;
|
|
1923
|
+
}
|
|
1924
|
+
const remainingAllNetworks = this.caipNetworks.filter((n) => n.id !== networkId);
|
|
1925
|
+
const remainingNamespaceNetworks = this.caipNetworks.filter((n) => n.id !== networkId && n.chainNamespace === namespace);
|
|
1926
|
+
if (!(remainingNamespaceNetworks == null ? void 0 : remainingNamespaceNetworks.length)) {
|
|
1927
|
+
throw new Error("Cannot remove last network for a namespace");
|
|
1928
|
+
}
|
|
1929
|
+
index.ChainController.removeNetwork(namespace, networkId);
|
|
1930
|
+
this.caipNetworks = [...remainingAllNetworks];
|
|
1931
|
+
}
|
|
1932
|
+
// -- Private ------------------------------------------------------------------
|
|
1933
|
+
initializeOptionsController(options) {
|
|
1934
|
+
var _a;
|
|
1935
|
+
index.OptionsController.setDebug(options.debug !== false);
|
|
1936
|
+
if (!options.projectId) {
|
|
1937
|
+
index.AlertController.open(ErrorUtil.ALERT_ERRORS.PROJECT_ID_NOT_CONFIGURED, "error");
|
|
1938
|
+
return;
|
|
1939
|
+
}
|
|
1940
|
+
index.OptionsController.setEnableWalletConnect(options.enableWalletConnect !== false);
|
|
1941
|
+
index.OptionsController.setEnableWalletGuide(options.enableWalletGuide !== false);
|
|
1942
|
+
index.OptionsController.setEnableWallets(options.enableWallets !== false);
|
|
1943
|
+
index.OptionsController.setEIP6963Enabled(options.enableEIP6963 !== false);
|
|
1944
|
+
index.OptionsController.setEnableAuthLogger(options.enableAuthLogger !== false);
|
|
1945
|
+
index.OptionsController.setSdkVersion(options.sdkVersion);
|
|
1946
|
+
index.OptionsController.setProjectId(options.projectId);
|
|
1947
|
+
index.OptionsController.setEnableEmbedded(options.enableEmbedded);
|
|
1948
|
+
index.OptionsController.setAllWallets(options.allWallets);
|
|
1949
|
+
index.OptionsController.setIncludeWalletIds(options.includeWalletIds);
|
|
1950
|
+
index.OptionsController.setExcludeWalletIds(options.excludeWalletIds);
|
|
1951
|
+
index.OptionsController.setFeaturedWalletIds(options.featuredWalletIds);
|
|
1952
|
+
index.OptionsController.setTokens(options.tokens);
|
|
1953
|
+
index.OptionsController.setTermsConditionsUrl(options.termsConditionsUrl);
|
|
1954
|
+
index.OptionsController.setPrivacyPolicyUrl(options.privacyPolicyUrl);
|
|
1955
|
+
index.OptionsController.setCustomWallets(options.customWallets);
|
|
1956
|
+
index.OptionsController.setFeatures(options.features);
|
|
1957
|
+
index.OptionsController.setAllowUnsupportedChain(options.allowUnsupportedChain);
|
|
1958
|
+
index.OptionsController.setDefaultAccountTypes(options.defaultAccountTypes);
|
|
1959
|
+
const defaultMetaData = this.getDefaultMetaData();
|
|
1960
|
+
if (!options.metadata && defaultMetaData) {
|
|
1961
|
+
options.metadata = defaultMetaData;
|
|
1962
|
+
}
|
|
1963
|
+
index.OptionsController.setMetadata(options.metadata);
|
|
1964
|
+
index.OptionsController.setDisableAppend(options.disableAppend);
|
|
1965
|
+
index.OptionsController.setEnableEmbedded(options.enableEmbedded);
|
|
1966
|
+
index.OptionsController.setSIWX(options.siwx);
|
|
1967
|
+
const evmAdapter = (_a = options.adapters) == null ? void 0 : _a.find((adapter) => adapter.namespace === index.ConstantsUtil.CHAIN.EVM);
|
|
1968
|
+
if (evmAdapter) {
|
|
1969
|
+
if (options.siweConfig) {
|
|
1970
|
+
if (options.siwx) {
|
|
1971
|
+
throw new Error("Cannot set both `siweConfig` and `siwx` options");
|
|
1972
|
+
}
|
|
1973
|
+
index.OptionsController.setSIWX(options.siweConfig.mapToSIWX());
|
|
1974
|
+
}
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
initializeThemeController(options) {
|
|
1978
|
+
if (options.themeMode) {
|
|
1979
|
+
index.ThemeController.setThemeMode(options.themeMode);
|
|
1980
|
+
}
|
|
1981
|
+
if (options.themeVariables) {
|
|
1982
|
+
index.ThemeController.setThemeVariables(options.themeVariables);
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
initializeChainController(options) {
|
|
1986
|
+
if (!this.connectionControllerClient || !this.networkControllerClient) {
|
|
1987
|
+
throw new Error("ConnectionControllerClient and NetworkControllerClient must be set");
|
|
1988
|
+
}
|
|
1989
|
+
index.ChainController.initialize(options.adapters ?? [], this.caipNetworks, {
|
|
1990
|
+
connectionControllerClient: this.connectionControllerClient,
|
|
1991
|
+
networkControllerClient: this.networkControllerClient
|
|
1992
|
+
});
|
|
1993
|
+
const network = this.getDefaultNetwork();
|
|
1994
|
+
if (network) {
|
|
1995
|
+
index.ChainController.setActiveCaipNetwork(network);
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
async initializeBlockchainApiController(options) {
|
|
1999
|
+
await index.BlockchainApiController.getSupportedNetworks({
|
|
2000
|
+
projectId: options.projectId
|
|
2001
|
+
});
|
|
2002
|
+
}
|
|
2003
|
+
initControllers(options) {
|
|
2004
|
+
this.initializeOptionsController(options);
|
|
2005
|
+
this.initializeChainController(options);
|
|
2006
|
+
this.initializeThemeController(options);
|
|
2007
|
+
this.initializeBlockchainApiController(options);
|
|
2008
|
+
if (options.excludeWalletIds) {
|
|
2009
|
+
index.ApiController.initializeExcludedWalletRdns({ ids: options.excludeWalletIds });
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
getDefaultMetaData() {
|
|
2013
|
+
var _a, _b, _c, _d;
|
|
2014
|
+
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
2015
|
+
return {
|
|
2016
|
+
name: ((_b = (_a = document.getElementsByTagName("title")) == null ? void 0 : _a[0]) == null ? void 0 : _b.textContent) || "",
|
|
2017
|
+
description: ((_c = document.querySelector('meta[property="og:description"]')) == null ? void 0 : _c.content) || "",
|
|
2018
|
+
url: window.location.origin,
|
|
2019
|
+
icons: [((_d = document.querySelector('link[rel~="icon"]')) == null ? void 0 : _d.href) || ""]
|
|
2020
|
+
};
|
|
2021
|
+
}
|
|
2022
|
+
return null;
|
|
2023
|
+
}
|
|
2024
|
+
setUnsupportedNetwork(chainId) {
|
|
2025
|
+
const namespace = this.getActiveChainNamespace();
|
|
2026
|
+
if (namespace) {
|
|
2027
|
+
const unsupportedNetwork = this.getUnsupportedNetwork(`${namespace}:${chainId}`);
|
|
2028
|
+
index.ChainController.setActiveCaipNetwork(unsupportedNetwork);
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
extendCaipNetwork(network, options) {
|
|
2032
|
+
const extendedNetwork = CaipNetworksUtil.extendCaipNetwork(network, {
|
|
2033
|
+
customNetworkImageUrls: options.chainImages,
|
|
2034
|
+
projectId: options.projectId
|
|
2035
|
+
});
|
|
2036
|
+
return extendedNetwork;
|
|
2037
|
+
}
|
|
2038
|
+
extendCaipNetworks(options) {
|
|
2039
|
+
const extendedNetworks = CaipNetworksUtil.extendCaipNetworks(options.networks, {
|
|
2040
|
+
customNetworkImageUrls: options.chainImages,
|
|
2041
|
+
projectId: options.projectId
|
|
2042
|
+
});
|
|
2043
|
+
return extendedNetworks;
|
|
2044
|
+
}
|
|
2045
|
+
extendDefaultCaipNetwork(options) {
|
|
2046
|
+
const defaultNetwork = options.networks.find((n) => {
|
|
2047
|
+
var _a;
|
|
2048
|
+
return n.id === ((_a = options.defaultNetwork) == null ? void 0 : _a.id);
|
|
2049
|
+
});
|
|
2050
|
+
const extendedNetwork = defaultNetwork ? CaipNetworksUtil.extendCaipNetwork(defaultNetwork, {
|
|
2051
|
+
customNetworkImageUrls: options.chainImages,
|
|
2052
|
+
projectId: options.projectId
|
|
2053
|
+
}) : void 0;
|
|
2054
|
+
return extendedNetwork;
|
|
2055
|
+
}
|
|
2056
|
+
createClients() {
|
|
2057
|
+
this.connectionControllerClient = {
|
|
2058
|
+
connectWalletConnect: async () => {
|
|
2059
|
+
var _a;
|
|
2060
|
+
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2061
|
+
if (!adapter) {
|
|
2062
|
+
throw new Error("Adapter not found");
|
|
2063
|
+
}
|
|
2064
|
+
const result = await adapter.connectWalletConnect((_a = this.getCaipNetwork()) == null ? void 0 : _a.id);
|
|
2065
|
+
this.close();
|
|
2066
|
+
this.setClientId((result == null ? void 0 : result.clientId) || null);
|
|
2067
|
+
index.StorageUtil.setConnectedNamespaces([...index.ChainController.state.chains.keys()]);
|
|
2068
|
+
await this.syncWalletConnectAccount();
|
|
2069
|
+
},
|
|
2070
|
+
connectExternal: async ({ id, info, type, provider, chain, caipNetwork }) => {
|
|
2071
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2072
|
+
const activeChain = index.ChainController.state.activeChain;
|
|
2073
|
+
const chainToUse = chain || activeChain;
|
|
2074
|
+
const adapter = this.getAdapter(chainToUse);
|
|
2075
|
+
if (chain && chain !== activeChain && !caipNetwork) {
|
|
2076
|
+
const toConnectNetwork = (_a = this.caipNetworks) == null ? void 0 : _a.find((network) => network.chainNamespace === chain);
|
|
2077
|
+
if (toConnectNetwork) {
|
|
2078
|
+
this.setCaipNetwork(toConnectNetwork);
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
if (!adapter) {
|
|
2082
|
+
throw new Error("Adapter not found");
|
|
2083
|
+
}
|
|
2084
|
+
const res = await adapter.connect({
|
|
2085
|
+
id,
|
|
2086
|
+
info,
|
|
2087
|
+
type,
|
|
2088
|
+
provider,
|
|
2089
|
+
chainId: (caipNetwork == null ? void 0 : caipNetwork.id) || ((_b = this.getCaipNetwork()) == null ? void 0 : _b.id),
|
|
2090
|
+
rpcUrl: ((_e = (_d = (_c = caipNetwork == null ? void 0 : caipNetwork.rpcUrls) == null ? void 0 : _c.default) == null ? void 0 : _d.http) == null ? void 0 : _e[0]) || ((_i = (_h = (_g = (_f = this.getCaipNetwork()) == null ? void 0 : _f.rpcUrls) == null ? void 0 : _g.default) == null ? void 0 : _h.http) == null ? void 0 : _i[0])
|
|
2091
|
+
});
|
|
2092
|
+
if (!res) {
|
|
2093
|
+
return;
|
|
2094
|
+
}
|
|
2095
|
+
index.StorageUtil.addConnectedNamespace(chainToUse);
|
|
2096
|
+
this.syncProvider({ ...res, chainNamespace: chainToUse });
|
|
2097
|
+
await this.syncAccount({ ...res, chainNamespace: chainToUse });
|
|
2098
|
+
const { accounts } = await adapter.getAccounts({ namespace: chainToUse, id });
|
|
2099
|
+
this.setAllAccounts(accounts, chainToUse);
|
|
2100
|
+
},
|
|
2101
|
+
reconnectExternal: async ({ id, info, type, provider }) => {
|
|
2102
|
+
var _a;
|
|
2103
|
+
const namespace = index.ChainController.state.activeChain;
|
|
2104
|
+
const adapter = this.getAdapter(namespace);
|
|
2105
|
+
if (adapter == null ? void 0 : adapter.reconnect) {
|
|
2106
|
+
await (adapter == null ? void 0 : adapter.reconnect({ id, info, type, provider, chainId: (_a = this.getCaipNetwork()) == null ? void 0 : _a.id }));
|
|
2107
|
+
index.StorageUtil.addConnectedNamespace(namespace);
|
|
2108
|
+
}
|
|
2109
|
+
},
|
|
2110
|
+
disconnect: async () => {
|
|
2111
|
+
const namespace = index.ChainController.state.activeChain;
|
|
2112
|
+
const adapter = this.getAdapter(namespace);
|
|
2113
|
+
const provider = index.ProviderUtil.getProvider(namespace);
|
|
2114
|
+
const providerType = index.ProviderUtil.state.providerIds[namespace];
|
|
2115
|
+
await (adapter == null ? void 0 : adapter.disconnect({ provider, providerType }));
|
|
2116
|
+
index.StorageUtil.removeConnectedNamespace(namespace);
|
|
2117
|
+
index.ProviderUtil.resetChain(namespace);
|
|
2118
|
+
this.setUser(void 0);
|
|
2119
|
+
this.setStatus("disconnected", namespace);
|
|
2120
|
+
},
|
|
2121
|
+
checkInstalled: (ids) => {
|
|
2122
|
+
if (!ids) {
|
|
2123
|
+
return Boolean(window.ethereum);
|
|
2124
|
+
}
|
|
2125
|
+
return ids.some((id) => {
|
|
2126
|
+
var _a;
|
|
2127
|
+
return Boolean((_a = window.ethereum) == null ? void 0 : _a[String(id)]);
|
|
2128
|
+
});
|
|
2129
|
+
},
|
|
2130
|
+
signMessage: async (message) => {
|
|
2131
|
+
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2132
|
+
const result = await (adapter == null ? void 0 : adapter.signMessage({
|
|
2133
|
+
message,
|
|
2134
|
+
address: index.AccountController.state.address,
|
|
2135
|
+
provider: index.ProviderUtil.getProvider(index.ChainController.state.activeChain)
|
|
2136
|
+
}));
|
|
2137
|
+
return (result == null ? void 0 : result.signature) || "";
|
|
2138
|
+
},
|
|
2139
|
+
sendTransaction: async (args) => {
|
|
2140
|
+
if (args.chainNamespace === index.ConstantsUtil.CHAIN.EVM) {
|
|
2141
|
+
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2142
|
+
const provider = index.ProviderUtil.getProvider(index.ChainController.state.activeChain);
|
|
2143
|
+
const result = await (adapter == null ? void 0 : adapter.sendTransaction({ ...args, provider }));
|
|
2144
|
+
return (result == null ? void 0 : result.hash) || "";
|
|
2145
|
+
}
|
|
2146
|
+
return "";
|
|
2147
|
+
},
|
|
2148
|
+
estimateGas: async (args) => {
|
|
2149
|
+
if (args.chainNamespace === index.ConstantsUtil.CHAIN.EVM) {
|
|
2150
|
+
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2151
|
+
const provider = index.ProviderUtil.getProvider(index.ChainController.state.activeChain);
|
|
2152
|
+
const caipNetwork = this.getCaipNetwork();
|
|
2153
|
+
if (!caipNetwork) {
|
|
2154
|
+
throw new Error("CaipNetwork is undefined");
|
|
2155
|
+
}
|
|
2156
|
+
const result = await (adapter == null ? void 0 : adapter.estimateGas({
|
|
2157
|
+
...args,
|
|
2158
|
+
provider,
|
|
2159
|
+
caipNetwork
|
|
2160
|
+
}));
|
|
2161
|
+
return (result == null ? void 0 : result.gas) || 0n;
|
|
2162
|
+
}
|
|
2163
|
+
return 0n;
|
|
2164
|
+
},
|
|
2165
|
+
getEnsAvatar: async () => {
|
|
2166
|
+
var _a;
|
|
2167
|
+
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2168
|
+
const result = await (adapter == null ? void 0 : adapter.getProfile({
|
|
2169
|
+
address: index.AccountController.state.address,
|
|
2170
|
+
chainId: Number((_a = this.getCaipNetwork()) == null ? void 0 : _a.id)
|
|
2171
|
+
}));
|
|
2172
|
+
return (result == null ? void 0 : result.profileImage) || false;
|
|
2173
|
+
},
|
|
2174
|
+
getEnsAddress: async (name) => {
|
|
2175
|
+
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2176
|
+
const caipNetwork = this.getCaipNetwork();
|
|
2177
|
+
if (!caipNetwork) {
|
|
2178
|
+
return false;
|
|
2179
|
+
}
|
|
2180
|
+
const result = await (adapter == null ? void 0 : adapter.getEnsAddress({
|
|
2181
|
+
name,
|
|
2182
|
+
caipNetwork
|
|
2183
|
+
}));
|
|
2184
|
+
return (result == null ? void 0 : result.address) || false;
|
|
2185
|
+
},
|
|
2186
|
+
writeContract: async (args) => {
|
|
2187
|
+
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2188
|
+
const caipNetwork = this.getCaipNetwork();
|
|
2189
|
+
const caipAddress = this.getCaipAddress();
|
|
2190
|
+
const provider = index.ProviderUtil.getProvider(index.ChainController.state.activeChain);
|
|
2191
|
+
if (!caipNetwork || !caipAddress) {
|
|
2192
|
+
throw new Error("CaipNetwork or CaipAddress is undefined");
|
|
2193
|
+
}
|
|
2194
|
+
const result = await (adapter == null ? void 0 : adapter.writeContract({ ...args, caipNetwork, provider, caipAddress }));
|
|
2195
|
+
return result == null ? void 0 : result.hash;
|
|
2196
|
+
},
|
|
2197
|
+
parseUnits: (value, decimals) => {
|
|
2198
|
+
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2199
|
+
return (adapter == null ? void 0 : adapter.parseUnits({ value, decimals })) ?? 0n;
|
|
2200
|
+
},
|
|
2201
|
+
formatUnits: (value, decimals) => {
|
|
2202
|
+
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2203
|
+
return (adapter == null ? void 0 : adapter.formatUnits({ value, decimals })) ?? "0";
|
|
2204
|
+
},
|
|
2205
|
+
getCapabilities: async (params) => {
|
|
2206
|
+
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2207
|
+
await (adapter == null ? void 0 : adapter.getCapabilities(params));
|
|
2208
|
+
},
|
|
2209
|
+
grantPermissions: async (params) => {
|
|
2210
|
+
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2211
|
+
return await (adapter == null ? void 0 : adapter.grantPermissions(params));
|
|
2212
|
+
},
|
|
2213
|
+
revokePermissions: async (params) => {
|
|
2214
|
+
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2215
|
+
if (adapter == null ? void 0 : adapter.revokePermissions) {
|
|
2216
|
+
return await adapter.revokePermissions(params);
|
|
2217
|
+
}
|
|
2218
|
+
return "0x";
|
|
2219
|
+
}
|
|
2220
|
+
};
|
|
2221
|
+
this.networkControllerClient = {
|
|
2222
|
+
switchCaipNetwork: async (caipNetwork) => {
|
|
2223
|
+
var _a, _b;
|
|
2224
|
+
if (!caipNetwork) {
|
|
2225
|
+
return;
|
|
2226
|
+
}
|
|
2227
|
+
if (index.AccountController.state.address && caipNetwork.chainNamespace === index.ChainController.state.activeChain) {
|
|
2228
|
+
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2229
|
+
const provider = index.ProviderUtil.getProvider(index.ChainController.state.activeChain);
|
|
2230
|
+
const providerType = index.ProviderUtil.state.providerIds[index.ChainController.state.activeChain];
|
|
2231
|
+
await (adapter == null ? void 0 : adapter.switchNetwork({ caipNetwork, provider, providerType }));
|
|
2232
|
+
this.setCaipNetwork(caipNetwork);
|
|
2233
|
+
await this.syncAccount({
|
|
2234
|
+
address: index.AccountController.state.address,
|
|
2235
|
+
chainId: caipNetwork.id,
|
|
2236
|
+
chainNamespace: caipNetwork.chainNamespace
|
|
2237
|
+
});
|
|
2238
|
+
} else if (index.AccountController.state.address) {
|
|
2239
|
+
const providerType = index.ProviderUtil.state.providerIds[index.ChainController.state.activeChain];
|
|
2240
|
+
if (providerType === index.ConstantsUtil$1.CONNECTOR_TYPE_AUTH) {
|
|
2241
|
+
try {
|
|
2242
|
+
index.ChainController.state.activeChain = caipNetwork.chainNamespace;
|
|
2243
|
+
await ((_b = (_a = this.connectionControllerClient) == null ? void 0 : _a.connectExternal) == null ? void 0 : _b.call(_a, {
|
|
2244
|
+
id: index.ConstantsUtil.CONNECTOR_ID.AUTH,
|
|
2245
|
+
provider: this.authProvider,
|
|
2246
|
+
chain: caipNetwork.chainNamespace,
|
|
2247
|
+
chainId: caipNetwork.id,
|
|
2248
|
+
type: index.ConstantsUtil$1.CONNECTOR_TYPE_AUTH,
|
|
2249
|
+
caipNetwork
|
|
2250
|
+
}));
|
|
2251
|
+
this.setCaipNetwork(caipNetwork);
|
|
2252
|
+
} catch (error) {
|
|
2253
|
+
const adapter = this.getAdapter(caipNetwork.chainNamespace);
|
|
2254
|
+
await (adapter == null ? void 0 : adapter.switchNetwork({
|
|
2255
|
+
caipNetwork,
|
|
2256
|
+
provider: this.authProvider,
|
|
2257
|
+
providerType
|
|
2258
|
+
}));
|
|
2259
|
+
}
|
|
2260
|
+
} else if (providerType === "WALLET_CONNECT") {
|
|
2261
|
+
this.setCaipNetwork(caipNetwork);
|
|
2262
|
+
this.syncWalletConnectAccount();
|
|
2263
|
+
} else {
|
|
2264
|
+
this.setCaipNetwork(caipNetwork);
|
|
2265
|
+
const address = this.getAddressByChainNamespace(caipNetwork.chainNamespace);
|
|
2266
|
+
if (address) {
|
|
2267
|
+
this.syncAccount({
|
|
2268
|
+
address,
|
|
2269
|
+
chainId: caipNetwork.id,
|
|
2270
|
+
chainNamespace: caipNetwork.chainNamespace
|
|
2271
|
+
});
|
|
2272
|
+
}
|
|
2273
|
+
}
|
|
2274
|
+
} else {
|
|
2275
|
+
this.setCaipNetwork(caipNetwork);
|
|
2276
|
+
}
|
|
2277
|
+
},
|
|
2278
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
2279
|
+
getApprovedCaipNetworksData: async () => {
|
|
2280
|
+
var _a, _b, _c, _d, _e;
|
|
2281
|
+
const providerType = index.ProviderUtil.state.providerIds[index.ChainController.state.activeChain];
|
|
2282
|
+
if (providerType === index.ConstantsUtil$1.CONNECTOR_TYPE_WALLET_CONNECT) {
|
|
2283
|
+
const namespaces = (_b = (_a = this.universalProvider) == null ? void 0 : _a.session) == null ? void 0 : _b.namespaces;
|
|
2284
|
+
return {
|
|
2285
|
+
/*
|
|
2286
|
+
* MetaMask Wallet only returns 1 namespace in the session object. This makes it imposible
|
|
2287
|
+
* to switch to other networks. Setting supportsAllNetworks to true for MetaMask Wallet
|
|
2288
|
+
* will make it possible to switch to other networks.
|
|
2289
|
+
*/
|
|
2290
|
+
supportsAllNetworks: ((_e = (_d = (_c = this.universalProvider) == null ? void 0 : _c.session) == null ? void 0 : _d.peer) == null ? void 0 : _e.metadata.name) === "MetaMask Wallet",
|
|
2291
|
+
approvedCaipNetworkIds: this.getChainsFromNamespaces(namespaces)
|
|
2292
|
+
};
|
|
2293
|
+
}
|
|
2294
|
+
return { supportsAllNetworks: true, approvedCaipNetworkIds: [] };
|
|
2295
|
+
}
|
|
2296
|
+
};
|
|
2297
|
+
index.ConnectionController.setClient(this.connectionControllerClient);
|
|
2298
|
+
}
|
|
2299
|
+
setupAuthConnectorListeners(provider) {
|
|
2300
|
+
provider.onRpcRequest((request) => {
|
|
2301
|
+
if (index.W3mFrameHelpers.checkIfRequestExists(request)) {
|
|
2302
|
+
if (!index.W3mFrameHelpers.checkIfRequestIsSafe(request)) {
|
|
2303
|
+
this.handleUnsafeRPCRequest();
|
|
2304
|
+
}
|
|
2305
|
+
} else {
|
|
2306
|
+
this.open();
|
|
2307
|
+
console.error(index.W3mFrameRpcConstants.RPC_METHOD_NOT_ALLOWED_MESSAGE, {
|
|
2308
|
+
method: request.method
|
|
2309
|
+
});
|
|
2310
|
+
setTimeout(() => {
|
|
2311
|
+
this.showErrorMessage(index.W3mFrameRpcConstants.RPC_METHOD_NOT_ALLOWED_UI_MESSAGE);
|
|
2312
|
+
}, 300);
|
|
2313
|
+
provider.rejectRpcRequests();
|
|
2314
|
+
}
|
|
2315
|
+
});
|
|
2316
|
+
provider.onRpcError(() => {
|
|
2317
|
+
const isModalOpen = this.isOpen();
|
|
2318
|
+
if (isModalOpen) {
|
|
2319
|
+
if (this.isTransactionStackEmpty()) {
|
|
2320
|
+
this.close();
|
|
2321
|
+
} else {
|
|
2322
|
+
this.popTransactionStack(true);
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
});
|
|
2326
|
+
provider.onRpcSuccess((_, request) => {
|
|
2327
|
+
var _a;
|
|
2328
|
+
const isSafeRequest = index.W3mFrameHelpers.checkIfRequestIsSafe(request);
|
|
2329
|
+
if (isSafeRequest) {
|
|
2330
|
+
return;
|
|
2331
|
+
}
|
|
2332
|
+
if (index.AccountController.state.address && ((_a = index.ChainController.state.activeCaipNetwork) == null ? void 0 : _a.id)) {
|
|
2333
|
+
this.updateNativeBalance();
|
|
2334
|
+
}
|
|
2335
|
+
if (this.isTransactionStackEmpty()) {
|
|
2336
|
+
this.close();
|
|
2337
|
+
} else {
|
|
2338
|
+
this.popTransactionStack();
|
|
2339
|
+
}
|
|
2340
|
+
});
|
|
2341
|
+
provider.onNotConnected(() => {
|
|
2342
|
+
const namespace = index.ChainController.state.activeChain;
|
|
2343
|
+
const connectorId = index.StorageUtil.getConnectedConnectorId(namespace);
|
|
2344
|
+
const isConnectedWithAuth = connectorId === index.ConstantsUtil.CONNECTOR_ID.AUTH;
|
|
2345
|
+
if (isConnectedWithAuth) {
|
|
2346
|
+
this.setCaipAddress(void 0, namespace);
|
|
2347
|
+
this.setLoading(false);
|
|
2348
|
+
}
|
|
2349
|
+
});
|
|
2350
|
+
provider.onConnect(async (user) => {
|
|
2351
|
+
var _a;
|
|
2352
|
+
const namespace = index.ChainController.state.activeChain;
|
|
2353
|
+
const caipAddress = namespace === index.ConstantsUtil.CHAIN.EVM ? `eip155:${user.chainId}:${user.address}` : `${user.chainId}:${user.address}`;
|
|
2354
|
+
this.setSmartAccountDeployed(Boolean(user.smartAccountDeployed), namespace);
|
|
2355
|
+
if (!HelpersUtil.isLowerCaseMatch(user.address, index.AccountController.state.address)) {
|
|
2356
|
+
this.syncIdentity({
|
|
2357
|
+
address: user.address,
|
|
2358
|
+
chainId: user.chainId,
|
|
2359
|
+
chainNamespace: namespace
|
|
2360
|
+
});
|
|
2361
|
+
}
|
|
2362
|
+
this.setCaipAddress(caipAddress, namespace);
|
|
2363
|
+
this.setUser({ ...index.AccountController.state.user || {}, email: user.email });
|
|
2364
|
+
const preferredAccountType = user.preferredAccountType || index.OptionsController.state.defaultAccountTypes[namespace];
|
|
2365
|
+
this.setPreferredAccountType(preferredAccountType, namespace);
|
|
2366
|
+
const userAccounts = (_a = user.accounts) == null ? void 0 : _a.map((account) => index.CoreHelperUtil.createAccount(namespace, account.address, account.type || index.OptionsController.state.defaultAccountTypes[namespace]));
|
|
2367
|
+
this.setAllAccounts(userAccounts || [
|
|
2368
|
+
index.CoreHelperUtil.createAccount(namespace, user.address, preferredAccountType)
|
|
2369
|
+
], namespace);
|
|
2370
|
+
await provider.getSmartAccountEnabledNetworks();
|
|
2371
|
+
this.setLoading(false);
|
|
2372
|
+
});
|
|
2373
|
+
provider.onSocialConnected(({ userName }) => {
|
|
2374
|
+
this.setUser({ ...index.AccountController.state.user || {}, username: userName });
|
|
2375
|
+
});
|
|
2376
|
+
provider.onGetSmartAccountEnabledNetworks((networks) => {
|
|
2377
|
+
this.setSmartAccountEnabledNetworks(networks, index.ChainController.state.activeChain);
|
|
2378
|
+
});
|
|
2379
|
+
provider.onSetPreferredAccount(({ address, type }) => {
|
|
2380
|
+
if (!address) {
|
|
2381
|
+
return;
|
|
2382
|
+
}
|
|
2383
|
+
this.setPreferredAccountType(type, index.ChainController.state.activeChain);
|
|
2384
|
+
});
|
|
2385
|
+
}
|
|
2386
|
+
async syncAuthConnector(provider) {
|
|
2387
|
+
var _a, _b, _c, _d;
|
|
2388
|
+
this.setLoading(true);
|
|
2389
|
+
const isLoginEmailUsed = provider.getLoginEmailUsed();
|
|
2390
|
+
this.setLoading(isLoginEmailUsed);
|
|
2391
|
+
if (isLoginEmailUsed) {
|
|
2392
|
+
this.setStatus("connecting", index.ChainController.state.activeChain);
|
|
2393
|
+
}
|
|
2394
|
+
const email = provider.getEmail();
|
|
2395
|
+
const username = provider.getUsername();
|
|
2396
|
+
this.setUser({ ...((_a = index.AccountController.state) == null ? void 0 : _a.user) || {}, username, email });
|
|
2397
|
+
this.setupAuthConnectorListeners(provider);
|
|
2398
|
+
const { isConnected } = await provider.isConnected();
|
|
2399
|
+
const theme = index.ThemeController.getSnapshot();
|
|
2400
|
+
const options = index.OptionsController.getSnapshot();
|
|
2401
|
+
provider.syncDappData({
|
|
2402
|
+
metadata: options.metadata,
|
|
2403
|
+
sdkVersion: options.sdkVersion,
|
|
2404
|
+
projectId: options.projectId,
|
|
2405
|
+
sdkType: options.sdkType
|
|
2406
|
+
});
|
|
2407
|
+
provider.syncTheme({
|
|
2408
|
+
themeMode: theme.themeMode,
|
|
2409
|
+
themeVariables: theme.themeVariables,
|
|
2410
|
+
w3mThemeVariables: index.getW3mThemeVariables(theme.themeVariables, theme.themeMode)
|
|
2411
|
+
});
|
|
2412
|
+
const namespace = index.StorageUtil.getActiveNamespace();
|
|
2413
|
+
if (namespace) {
|
|
2414
|
+
if (isConnected && ((_b = this.connectionControllerClient) == null ? void 0 : _b.connectExternal)) {
|
|
2415
|
+
await ((_d = this.connectionControllerClient) == null ? void 0 : _d.connectExternal({
|
|
2416
|
+
id: index.ConstantsUtil.CONNECTOR_ID.AUTH,
|
|
2417
|
+
info: { name: index.ConstantsUtil.CONNECTOR_ID.AUTH },
|
|
2418
|
+
type: index.ConstantsUtil$1.CONNECTOR_TYPE_AUTH,
|
|
2419
|
+
provider,
|
|
2420
|
+
chainId: (_c = index.ChainController.state.activeCaipNetwork) == null ? void 0 : _c.id,
|
|
2421
|
+
chain: namespace
|
|
2422
|
+
}));
|
|
2423
|
+
this.setStatus("connected", namespace);
|
|
2424
|
+
} else if (index.StorageUtil.getConnectedConnectorId(namespace) === index.ConstantsUtil.CONNECTOR_ID.AUTH) {
|
|
2425
|
+
this.setStatus("disconnected", namespace);
|
|
2426
|
+
index.StorageUtil.removeConnectedNamespace(namespace);
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2429
|
+
this.setLoading(false);
|
|
2430
|
+
}
|
|
2431
|
+
listenWalletConnect() {
|
|
2432
|
+
if (this.universalProvider) {
|
|
2433
|
+
this.universalProvider.on("display_uri", (uri) => {
|
|
2434
|
+
index.ConnectionController.setUri(uri);
|
|
2435
|
+
});
|
|
2436
|
+
this.universalProvider.on("disconnect", () => {
|
|
2437
|
+
this.chainNamespaces.forEach((namespace) => {
|
|
2438
|
+
this.resetAccount(namespace);
|
|
2439
|
+
});
|
|
2440
|
+
index.ConnectionController.resetWcConnection();
|
|
2441
|
+
});
|
|
2442
|
+
this.universalProvider.on("chainChanged", (chainId) => {
|
|
2443
|
+
var _a;
|
|
2444
|
+
const caipNetwork = (_a = this.caipNetworks) == null ? void 0 : _a.find((c) => c.id == chainId);
|
|
2445
|
+
const currentCaipNetwork = this.getCaipNetwork();
|
|
2446
|
+
if (!caipNetwork) {
|
|
2447
|
+
this.setUnsupportedNetwork(chainId);
|
|
2448
|
+
return;
|
|
2449
|
+
}
|
|
2450
|
+
if ((currentCaipNetwork == null ? void 0 : currentCaipNetwork.id) !== (caipNetwork == null ? void 0 : caipNetwork.id)) {
|
|
2451
|
+
this.setCaipNetwork(caipNetwork);
|
|
2452
|
+
}
|
|
2453
|
+
});
|
|
2454
|
+
this.universalProvider.on("session_event", (callbackData) => {
|
|
2455
|
+
if (WcHelpersUtil.isSessionEventData(callbackData)) {
|
|
2456
|
+
const { name, data } = callbackData.params.event;
|
|
2457
|
+
if (name === "accountsChanged" && Array.isArray(data) && index.CoreHelperUtil.isCaipAddress(data[0])) {
|
|
2458
|
+
this.syncAccount(ParseUtil.parseCaipAddress(data[0]));
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
});
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
listenAdapter(chainNamespace) {
|
|
2465
|
+
const adapter = this.getAdapter(chainNamespace);
|
|
2466
|
+
if (!adapter) {
|
|
2467
|
+
return;
|
|
2468
|
+
}
|
|
2469
|
+
const connectionStatus = index.StorageUtil.getConnectionStatus();
|
|
2470
|
+
if (connectionStatus === "connected") {
|
|
2471
|
+
this.setStatus("connecting", chainNamespace);
|
|
2472
|
+
} else {
|
|
2473
|
+
this.setStatus(connectionStatus, chainNamespace);
|
|
2474
|
+
}
|
|
2475
|
+
adapter.on("switchNetwork", ({ address, chainId }) => {
|
|
2476
|
+
var _a;
|
|
2477
|
+
if (chainId && ((_a = this.caipNetworks) == null ? void 0 : _a.find((n) => n.id === chainId || n.caipNetworkId === chainId))) {
|
|
2478
|
+
if (index.ChainController.state.activeChain === chainNamespace && address) {
|
|
2479
|
+
this.syncAccount({ address, chainId, chainNamespace });
|
|
2480
|
+
} else if (index.ChainController.state.activeChain === chainNamespace && index.AccountController.state.address) {
|
|
2481
|
+
this.syncAccount({
|
|
2482
|
+
address: index.AccountController.state.address,
|
|
2483
|
+
chainId,
|
|
2484
|
+
chainNamespace
|
|
2485
|
+
});
|
|
2486
|
+
}
|
|
2487
|
+
} else {
|
|
2488
|
+
this.setUnsupportedNetwork(chainId);
|
|
2489
|
+
}
|
|
2490
|
+
});
|
|
2491
|
+
adapter.on("disconnect", this.disconnect.bind(this));
|
|
2492
|
+
adapter.on("pendingTransactions", () => {
|
|
2493
|
+
const address = index.AccountController.state.address;
|
|
2494
|
+
const activeCaipNetwork = index.ChainController.state.activeCaipNetwork;
|
|
2495
|
+
if (!address || !(activeCaipNetwork == null ? void 0 : activeCaipNetwork.id)) {
|
|
2496
|
+
return;
|
|
2497
|
+
}
|
|
2498
|
+
this.updateNativeBalance();
|
|
2499
|
+
});
|
|
2500
|
+
adapter.on("accountChanged", ({ address, chainId }) => {
|
|
2501
|
+
var _a, _b;
|
|
2502
|
+
if (index.ChainController.state.activeChain === chainNamespace && chainId) {
|
|
2503
|
+
this.syncAccount({
|
|
2504
|
+
address,
|
|
2505
|
+
chainId,
|
|
2506
|
+
chainNamespace
|
|
2507
|
+
});
|
|
2508
|
+
} else if (index.ChainController.state.activeChain === chainNamespace && ((_a = index.ChainController.state.activeCaipNetwork) == null ? void 0 : _a.id)) {
|
|
2509
|
+
this.syncAccount({
|
|
2510
|
+
address,
|
|
2511
|
+
chainId: (_b = index.ChainController.state.activeCaipNetwork) == null ? void 0 : _b.id,
|
|
2512
|
+
chainNamespace
|
|
2513
|
+
});
|
|
2514
|
+
}
|
|
2515
|
+
});
|
|
2516
|
+
}
|
|
2517
|
+
async updateNativeBalance() {
|
|
2518
|
+
var _a;
|
|
2519
|
+
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2520
|
+
if (adapter && index.ChainController.state.activeChain && index.AccountController.state.address) {
|
|
2521
|
+
const balance = await adapter.getBalance({
|
|
2522
|
+
address: index.AccountController.state.address,
|
|
2523
|
+
chainId: (_a = index.ChainController.state.activeCaipNetwork) == null ? void 0 : _a.id,
|
|
2524
|
+
caipNetwork: this.getCaipNetwork(),
|
|
2525
|
+
tokens: this.options.tokens
|
|
2526
|
+
});
|
|
2527
|
+
this.setBalance(balance.balance, balance.symbol, index.ChainController.state.activeChain);
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
2530
|
+
getChainsFromNamespaces(namespaces = {}) {
|
|
2531
|
+
return Object.values(namespaces).flatMap((namespace) => {
|
|
2532
|
+
const chains = namespace.chains || [];
|
|
2533
|
+
const accountsChains = namespace.accounts.map((account) => {
|
|
2534
|
+
const { chainId, chainNamespace } = ParseUtil.parseCaipAddress(account);
|
|
2535
|
+
return `${chainNamespace}:${chainId}`;
|
|
2536
|
+
});
|
|
2537
|
+
return Array.from(/* @__PURE__ */ new Set([...chains, ...accountsChains]));
|
|
2538
|
+
});
|
|
2539
|
+
}
|
|
2540
|
+
async syncWalletConnectAccount() {
|
|
2541
|
+
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2542
|
+
this.chainNamespaces.forEach(async (chainNamespace) => {
|
|
2543
|
+
var _a, _b, _c, _d, _e, _f;
|
|
2544
|
+
const namespaceAccounts = ((_d = (_c = (_b = (_a = this.universalProvider) == null ? void 0 : _a.session) == null ? void 0 : _b.namespaces) == null ? void 0 : _c[chainNamespace]) == null ? void 0 : _d.accounts) || [];
|
|
2545
|
+
const activeChainId = (_e = index.ChainController.state.activeCaipNetwork) == null ? void 0 : _e.id;
|
|
2546
|
+
const sessionAddress = namespaceAccounts.find((account) => {
|
|
2547
|
+
const { chainId } = ParseUtil.parseCaipAddress(account);
|
|
2548
|
+
return chainId === (activeChainId == null ? void 0 : activeChainId.toString());
|
|
2549
|
+
}) || namespaceAccounts[0];
|
|
2550
|
+
if (sessionAddress) {
|
|
2551
|
+
const caipAddress = ParseUtil.validateCaipAddress(sessionAddress);
|
|
2552
|
+
const { chainId, address } = ParseUtil.parseCaipAddress(caipAddress);
|
|
2553
|
+
index.ProviderUtil.setProviderId(chainNamespace, index.ConstantsUtil$1.CONNECTOR_TYPE_WALLET_CONNECT);
|
|
2554
|
+
if (this.caipNetworks && index.ChainController.state.activeCaipNetwork && (adapter == null ? void 0 : adapter.namespace) !== index.ConstantsUtil.CHAIN.EVM) {
|
|
2555
|
+
const provider = adapter == null ? void 0 : adapter.getWalletConnectProvider({
|
|
2556
|
+
caipNetworks: this.caipNetworks,
|
|
2557
|
+
provider: this.universalProvider,
|
|
2558
|
+
activeCaipNetwork: index.ChainController.state.activeCaipNetwork
|
|
2559
|
+
});
|
|
2560
|
+
index.ProviderUtil.setProvider(chainNamespace, provider);
|
|
2561
|
+
} else {
|
|
2562
|
+
index.ProviderUtil.setProvider(chainNamespace, this.universalProvider);
|
|
2563
|
+
}
|
|
2564
|
+
index.StorageUtil.setConnectedConnectorId(chainNamespace, index.ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT);
|
|
2565
|
+
index.StorageUtil.addConnectedNamespace(chainNamespace);
|
|
2566
|
+
if ((adapter == null ? void 0 : adapter.adapterType) === "wagmi") {
|
|
2567
|
+
try {
|
|
2568
|
+
await (adapter == null ? void 0 : adapter.connect({
|
|
2569
|
+
id: "walletConnect",
|
|
2570
|
+
type: "WALLET_CONNECT",
|
|
2571
|
+
chainId: (_f = index.ChainController.state.activeCaipNetwork) == null ? void 0 : _f.id
|
|
2572
|
+
}));
|
|
2573
|
+
} catch (error) {
|
|
2574
|
+
if (adapter == null ? void 0 : adapter.reconnect) {
|
|
2575
|
+
adapter == null ? void 0 : adapter.reconnect({
|
|
2576
|
+
id: "walletConnect",
|
|
2577
|
+
type: "WALLET_CONNECT"
|
|
2578
|
+
});
|
|
2579
|
+
}
|
|
2580
|
+
}
|
|
2581
|
+
}
|
|
2582
|
+
this.syncWalletConnectAccounts(chainNamespace);
|
|
2583
|
+
await this.syncAccount({
|
|
2584
|
+
address,
|
|
2585
|
+
chainId,
|
|
2586
|
+
chainNamespace
|
|
2587
|
+
});
|
|
2588
|
+
}
|
|
2589
|
+
});
|
|
2590
|
+
await index.ChainController.setApprovedCaipNetworksData(index.ChainController.state.activeChain);
|
|
2591
|
+
}
|
|
2592
|
+
syncWalletConnectAccounts(chainNamespace) {
|
|
2593
|
+
var _a, _b, _c, _d, _e;
|
|
2594
|
+
const addresses = (_e = (_d = (_c = (_b = (_a = this.universalProvider) == null ? void 0 : _a.session) == null ? void 0 : _b.namespaces) == null ? void 0 : _c[chainNamespace]) == null ? void 0 : _d.accounts) == null ? void 0 : _e.map((account) => {
|
|
2595
|
+
const { address } = ParseUtil.parseCaipAddress(account);
|
|
2596
|
+
return address;
|
|
2597
|
+
}).filter((address, index2, self) => self.indexOf(address) === index2);
|
|
2598
|
+
if (addresses) {
|
|
2599
|
+
this.setAllAccounts(addresses.map((address) => index.CoreHelperUtil.createAccount(chainNamespace, address, chainNamespace === "bip122" ? "payment" : "eoa")), chainNamespace);
|
|
2600
|
+
}
|
|
2601
|
+
}
|
|
2602
|
+
syncProvider({ type, provider, id, chainNamespace }) {
|
|
2603
|
+
index.ProviderUtil.setProviderId(chainNamespace, type);
|
|
2604
|
+
index.ProviderUtil.setProvider(chainNamespace, provider);
|
|
2605
|
+
index.StorageUtil.setConnectedConnectorId(chainNamespace, id);
|
|
2606
|
+
}
|
|
2607
|
+
async syncAccount(params) {
|
|
2608
|
+
var _a, _b, _c, _d, _e, _f;
|
|
2609
|
+
const { address, chainId, chainNamespace } = params;
|
|
2610
|
+
const { chainId: activeChainId } = index.StorageUtil.getActiveNetworkProps();
|
|
2611
|
+
const chainIdToUse = chainId || activeChainId;
|
|
2612
|
+
const isUnsupportedNetwork = ((_a = index.ChainController.state.activeCaipNetwork) == null ? void 0 : _a.name) === index.ConstantsUtil.UNSUPPORTED_NETWORK_NAME;
|
|
2613
|
+
const shouldSupportAllNetworks = index.ChainController.getNetworkProp("supportsAllNetworks", chainNamespace);
|
|
2614
|
+
this.setStatus("connected", chainNamespace);
|
|
2615
|
+
if (isUnsupportedNetwork && !shouldSupportAllNetworks) {
|
|
2616
|
+
return;
|
|
2617
|
+
}
|
|
2618
|
+
if (chainIdToUse) {
|
|
2619
|
+
let caipNetwork = (_b = this.caipNetworks) == null ? void 0 : _b.find((n) => n.id.toString() === chainIdToUse.toString());
|
|
2620
|
+
let fallbackCaipNetwork = (_c = this.caipNetworks) == null ? void 0 : _c.find((n) => n.chainNamespace === chainNamespace);
|
|
2621
|
+
if (!shouldSupportAllNetworks && !caipNetwork && !fallbackCaipNetwork) {
|
|
2622
|
+
const caipNetworkIds = this.getApprovedCaipNetworkIds() || [];
|
|
2623
|
+
const caipNetworkId = caipNetworkIds.find((id) => {
|
|
2624
|
+
var _a2;
|
|
2625
|
+
return ((_a2 = ParseUtil.parseCaipNetworkId(id)) == null ? void 0 : _a2.chainId) === chainIdToUse.toString();
|
|
2626
|
+
});
|
|
2627
|
+
const fallBackCaipNetworkId = caipNetworkIds.find((id) => {
|
|
2628
|
+
var _a2;
|
|
2629
|
+
return ((_a2 = ParseUtil.parseCaipNetworkId(id)) == null ? void 0 : _a2.chainNamespace) === chainNamespace;
|
|
2630
|
+
});
|
|
2631
|
+
caipNetwork = (_d = this.caipNetworks) == null ? void 0 : _d.find((n) => n.caipNetworkId === caipNetworkId);
|
|
2632
|
+
fallbackCaipNetwork = (_e = this.caipNetworks) == null ? void 0 : _e.find((n) => n.caipNetworkId === fallBackCaipNetworkId || // This is a workaround used in Solana network to support deprecated caipNetworkId
|
|
2633
|
+
"deprecatedCaipNetworkId" in n && n.deprecatedCaipNetworkId === fallBackCaipNetworkId);
|
|
2634
|
+
}
|
|
2635
|
+
const network = caipNetwork || fallbackCaipNetwork;
|
|
2636
|
+
if ((network == null ? void 0 : network.chainNamespace) === index.ChainController.state.activeChain) {
|
|
2637
|
+
if (!index.OptionsController.state.allowUnsupportedChain && ((_f = index.ChainController.state.activeCaipNetwork) == null ? void 0 : _f.name) === index.ConstantsUtil.UNSUPPORTED_NETWORK_NAME) {
|
|
2638
|
+
index.ChainController.showUnsupportedChainUI();
|
|
2639
|
+
} else {
|
|
2640
|
+
this.setCaipNetwork(network);
|
|
2641
|
+
}
|
|
2642
|
+
}
|
|
2643
|
+
this.syncConnectedWalletInfo(chainNamespace);
|
|
2644
|
+
if (!HelpersUtil.isLowerCaseMatch(address, index.AccountController.state.address)) {
|
|
2645
|
+
this.setCaipAddress(`${chainNamespace}:${network == null ? void 0 : network.id}:${address}`, chainNamespace);
|
|
2646
|
+
await this.syncIdentity({
|
|
2647
|
+
address,
|
|
2648
|
+
chainId: network == null ? void 0 : network.id,
|
|
2649
|
+
chainNamespace
|
|
2650
|
+
});
|
|
2651
|
+
}
|
|
2652
|
+
await this.syncBalance({ address, chainId: network == null ? void 0 : network.id, chainNamespace });
|
|
2653
|
+
}
|
|
2654
|
+
}
|
|
2655
|
+
async syncBalance(params) {
|
|
2656
|
+
const caipNetwork = index.NetworkUtil.getNetworksByNamespace(this.caipNetworks, params.chainNamespace).find((n) => {
|
|
2657
|
+
var _a;
|
|
2658
|
+
return n.id.toString() === ((_a = params.chainId) == null ? void 0 : _a.toString());
|
|
2659
|
+
});
|
|
2660
|
+
if (!caipNetwork) {
|
|
2661
|
+
return;
|
|
2662
|
+
}
|
|
2663
|
+
await this.updateNativeBalance();
|
|
2664
|
+
}
|
|
2665
|
+
syncConnectedWalletInfo(chainNamespace) {
|
|
2666
|
+
var _a;
|
|
2667
|
+
const connectorId = index.StorageUtil.getConnectedConnectorId(chainNamespace);
|
|
2668
|
+
const providerType = index.ProviderUtil.getProviderId(chainNamespace);
|
|
2669
|
+
if (providerType === index.ConstantsUtil$1.CONNECTOR_TYPE_ANNOUNCED || providerType === index.ConstantsUtil$1.CONNECTOR_TYPE_INJECTED) {
|
|
2670
|
+
if (connectorId) {
|
|
2671
|
+
const connector = this.getConnectors().find((c) => c.id === connectorId);
|
|
2672
|
+
if (connector) {
|
|
2673
|
+
const { info, name, imageUrl } = connector;
|
|
2674
|
+
const icon = imageUrl || this.getConnectorImage(connector);
|
|
2675
|
+
this.setConnectedWalletInfo({ name, icon, ...info }, chainNamespace);
|
|
2676
|
+
}
|
|
2677
|
+
}
|
|
2678
|
+
} else if (providerType === index.ConstantsUtil$1.CONNECTOR_TYPE_WALLET_CONNECT) {
|
|
2679
|
+
const provider = index.ProviderUtil.getProvider(chainNamespace);
|
|
2680
|
+
if (provider == null ? void 0 : provider.session) {
|
|
2681
|
+
this.setConnectedWalletInfo({
|
|
2682
|
+
...provider.session.peer.metadata,
|
|
2683
|
+
name: provider.session.peer.metadata.name,
|
|
2684
|
+
icon: (_a = provider.session.peer.metadata.icons) == null ? void 0 : _a[0]
|
|
2685
|
+
}, chainNamespace);
|
|
2686
|
+
}
|
|
2687
|
+
} else if (connectorId) {
|
|
2688
|
+
if (connectorId === index.ConstantsUtil.CONNECTOR_ID.COINBASE) {
|
|
2689
|
+
const connector = this.getConnectors().find((c) => c.id === index.ConstantsUtil.CONNECTOR_ID.COINBASE);
|
|
2690
|
+
this.setConnectedWalletInfo({ name: "Coinbase Wallet", icon: this.getConnectorImage(connector) }, chainNamespace);
|
|
2691
|
+
}
|
|
2692
|
+
this.setConnectedWalletInfo({ name: connectorId }, chainNamespace);
|
|
2693
|
+
}
|
|
2694
|
+
}
|
|
2695
|
+
async syncIdentity({ address, chainId, chainNamespace }) {
|
|
2696
|
+
var _a;
|
|
2697
|
+
const activeCaipNetwork = (_a = this.caipNetworks) == null ? void 0 : _a.find((n) => n.caipNetworkId === `${chainNamespace}:${chainId}`);
|
|
2698
|
+
if (chainNamespace !== index.ConstantsUtil.CHAIN.EVM || (activeCaipNetwork == null ? void 0 : activeCaipNetwork.testnet)) {
|
|
2699
|
+
return;
|
|
2700
|
+
}
|
|
2701
|
+
try {
|
|
2702
|
+
const { name, avatar } = await this.fetchIdentity({
|
|
2703
|
+
address
|
|
2704
|
+
});
|
|
2705
|
+
this.setProfileName(name, chainNamespace);
|
|
2706
|
+
this.setProfileImage(avatar, chainNamespace);
|
|
2707
|
+
if (!name) {
|
|
2708
|
+
await this.syncReownName(address, chainNamespace);
|
|
2709
|
+
const adapter = this.getAdapter(chainNamespace);
|
|
2710
|
+
const result = await (adapter == null ? void 0 : adapter.getProfile({
|
|
2711
|
+
address,
|
|
2712
|
+
chainId: Number(chainId)
|
|
2713
|
+
}));
|
|
2714
|
+
if (result == null ? void 0 : result.profileName) {
|
|
2715
|
+
this.setProfileName(result.profileName, chainNamespace);
|
|
2716
|
+
if (result.profileImage) {
|
|
2717
|
+
this.setProfileImage(result.profileImage, chainNamespace);
|
|
2718
|
+
}
|
|
2719
|
+
} else {
|
|
2720
|
+
await this.syncReownName(address, chainNamespace);
|
|
2721
|
+
this.setProfileImage(null, chainNamespace);
|
|
2722
|
+
}
|
|
2723
|
+
}
|
|
2724
|
+
} catch {
|
|
2725
|
+
if (chainId === 1) {
|
|
2726
|
+
await this.syncReownName(address, chainNamespace);
|
|
2727
|
+
} else {
|
|
2728
|
+
await this.syncReownName(address, chainNamespace);
|
|
2729
|
+
this.setProfileImage(null, chainNamespace);
|
|
2730
|
+
}
|
|
2731
|
+
}
|
|
2732
|
+
}
|
|
2733
|
+
async syncReownName(address, chainNamespace) {
|
|
2734
|
+
try {
|
|
2735
|
+
const registeredWcNames = await this.getReownName(address);
|
|
2736
|
+
if (registeredWcNames[0]) {
|
|
2737
|
+
const wcName = registeredWcNames[0];
|
|
2738
|
+
this.setProfileName(wcName.name, chainNamespace);
|
|
2739
|
+
} else {
|
|
2740
|
+
this.setProfileName(null, chainNamespace);
|
|
2741
|
+
}
|
|
2742
|
+
} catch {
|
|
2743
|
+
this.setProfileName(null, chainNamespace);
|
|
2744
|
+
}
|
|
2745
|
+
}
|
|
2746
|
+
async syncAdapterConnection(namespace) {
|
|
2747
|
+
var _a, _b, _c;
|
|
2748
|
+
const adapter = this.getAdapter(namespace);
|
|
2749
|
+
const connectorId = index.StorageUtil.getConnectedConnectorId(namespace);
|
|
2750
|
+
const caipNetwork = this.getCaipNetwork();
|
|
2751
|
+
try {
|
|
2752
|
+
if (!adapter || !connectorId) {
|
|
2753
|
+
throw new Error(`Adapter or connectorId not found for namespace ${namespace}`);
|
|
2754
|
+
}
|
|
2755
|
+
const connection = await (adapter == null ? void 0 : adapter.syncConnection({
|
|
2756
|
+
namespace,
|
|
2757
|
+
id: connectorId,
|
|
2758
|
+
chainId: caipNetwork == null ? void 0 : caipNetwork.id,
|
|
2759
|
+
rpcUrl: (_c = (_b = (_a = caipNetwork == null ? void 0 : caipNetwork.rpcUrls) == null ? void 0 : _a.default) == null ? void 0 : _b.http) == null ? void 0 : _c[0]
|
|
2760
|
+
}));
|
|
2761
|
+
if (connection) {
|
|
2762
|
+
const accounts = await (adapter == null ? void 0 : adapter.getAccounts({
|
|
2763
|
+
namespace,
|
|
2764
|
+
id: connectorId
|
|
2765
|
+
}));
|
|
2766
|
+
if (accounts && accounts.accounts.length > 0) {
|
|
2767
|
+
this.setAllAccounts(accounts.accounts, namespace);
|
|
2768
|
+
} else {
|
|
2769
|
+
this.setAllAccounts([index.CoreHelperUtil.createAccount(namespace, connection.address, "eoa")], namespace);
|
|
2770
|
+
}
|
|
2771
|
+
this.syncProvider({ ...connection, chainNamespace: namespace });
|
|
2772
|
+
await this.syncAccount({ ...connection, chainNamespace: namespace });
|
|
2773
|
+
this.setStatus("connected", namespace);
|
|
2774
|
+
} else {
|
|
2775
|
+
this.setStatus("disconnected", namespace);
|
|
2776
|
+
}
|
|
2777
|
+
} catch (e) {
|
|
2778
|
+
index.StorageUtil.deleteConnectedConnectorId(namespace);
|
|
2779
|
+
this.setStatus("disconnected", namespace);
|
|
2780
|
+
}
|
|
2781
|
+
}
|
|
2782
|
+
async syncNamespaceConnection(namespace) {
|
|
2783
|
+
var _a;
|
|
2784
|
+
try {
|
|
2785
|
+
const connectorId = index.StorageUtil.getConnectedConnectorId(namespace);
|
|
2786
|
+
const isEmailUsed = (_a = this.authProvider) == null ? void 0 : _a.getLoginEmailUsed();
|
|
2787
|
+
if (isEmailUsed) {
|
|
2788
|
+
return;
|
|
2789
|
+
}
|
|
2790
|
+
this.setStatus("connecting", namespace);
|
|
2791
|
+
switch (connectorId) {
|
|
2792
|
+
case index.ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT:
|
|
2793
|
+
await this.syncWalletConnectAccount();
|
|
2794
|
+
break;
|
|
2795
|
+
case index.ConstantsUtil.CONNECTOR_ID.AUTH:
|
|
2796
|
+
break;
|
|
2797
|
+
default:
|
|
2798
|
+
await this.syncAdapterConnection(namespace);
|
|
2799
|
+
}
|
|
2800
|
+
} catch (err) {
|
|
2801
|
+
console.warn("AppKit couldn't sync existing connection", err);
|
|
2802
|
+
index.StorageUtil.deleteConnectedConnectorId(namespace);
|
|
2803
|
+
this.setStatus("disconnected", namespace);
|
|
2804
|
+
}
|
|
2805
|
+
}
|
|
2806
|
+
async syncExistingConnection() {
|
|
2807
|
+
await Promise.allSettled(this.chainNamespaces.map((namespace) => this.syncNamespaceConnection(namespace)));
|
|
2808
|
+
}
|
|
2809
|
+
getAdapter(namespace) {
|
|
2810
|
+
var _a;
|
|
2811
|
+
if (!namespace) {
|
|
2812
|
+
return void 0;
|
|
2813
|
+
}
|
|
2814
|
+
return (_a = this.chainAdapters) == null ? void 0 : _a[namespace];
|
|
2815
|
+
}
|
|
2816
|
+
createUniversalProvider() {
|
|
2817
|
+
var _a;
|
|
2818
|
+
if (!this.universalProviderInitPromise && index.CoreHelperUtil.isClient() && ((_a = this.options) == null ? void 0 : _a.projectId)) {
|
|
2819
|
+
this.universalProviderInitPromise = this.initializeUniversalAdapter();
|
|
2820
|
+
}
|
|
2821
|
+
return this.universalProviderInitPromise;
|
|
2822
|
+
}
|
|
2823
|
+
handleAlertError(error) {
|
|
2824
|
+
const matchedUniversalProviderError = Object.entries(ErrorUtil.UniversalProviderErrors).find(([, { message: message2 }]) => error.message.includes(message2));
|
|
2825
|
+
const [errorKey, errorValue] = matchedUniversalProviderError ?? [];
|
|
2826
|
+
const { message, alertErrorKey } = errorValue ?? {};
|
|
2827
|
+
if (errorKey && message && !this.reportedAlertErrors[errorKey]) {
|
|
2828
|
+
const alertError = ErrorUtil.ALERT_ERRORS[alertErrorKey];
|
|
2829
|
+
if (alertError) {
|
|
2830
|
+
index.AlertController.open(alertError, "error");
|
|
2831
|
+
this.reportedAlertErrors[errorKey] = true;
|
|
2832
|
+
}
|
|
2833
|
+
}
|
|
2834
|
+
}
|
|
2835
|
+
async initializeUniversalAdapter() {
|
|
2836
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2837
|
+
const logger = LoggerUtil.createLogger((error, ...args) => {
|
|
2838
|
+
if (error) {
|
|
2839
|
+
this.handleAlertError(error);
|
|
2840
|
+
}
|
|
2841
|
+
console.error(...args);
|
|
2842
|
+
});
|
|
2843
|
+
const universalProviderOptions = {
|
|
2844
|
+
projectId: (_a = this.options) == null ? void 0 : _a.projectId,
|
|
2845
|
+
metadata: {
|
|
2846
|
+
name: ((_b = this.options) == null ? void 0 : _b.metadata) ? (_c = this.options) == null ? void 0 : _c.metadata.name : "",
|
|
2847
|
+
description: ((_d = this.options) == null ? void 0 : _d.metadata) ? (_e = this.options) == null ? void 0 : _e.metadata.description : "",
|
|
2848
|
+
url: ((_f = this.options) == null ? void 0 : _f.metadata) ? (_g = this.options) == null ? void 0 : _g.metadata.url : "",
|
|
2849
|
+
icons: ((_h = this.options) == null ? void 0 : _h.metadata) ? (_i = this.options) == null ? void 0 : _i.metadata.icons : [""]
|
|
2850
|
+
},
|
|
2851
|
+
logger
|
|
2852
|
+
};
|
|
2853
|
+
index.OptionsController.setUsingInjectedUniversalProvider(Boolean((_j = this.options) == null ? void 0 : _j.universalProvider));
|
|
2854
|
+
this.universalProvider = this.options.universalProvider ?? await index.M.init(universalProviderOptions);
|
|
2855
|
+
this.listenWalletConnect();
|
|
2856
|
+
}
|
|
2857
|
+
async getUniversalProvider() {
|
|
2858
|
+
if (!this.universalProvider) {
|
|
2859
|
+
try {
|
|
2860
|
+
await this.createUniversalProvider();
|
|
2861
|
+
} catch (error) {
|
|
2862
|
+
throw new Error("AppKit:getUniversalProvider - Cannot create provider");
|
|
2863
|
+
}
|
|
2864
|
+
}
|
|
2865
|
+
return this.universalProvider;
|
|
2866
|
+
}
|
|
2867
|
+
createAuthProvider() {
|
|
2868
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2869
|
+
const isEmailEnabled = ((_b = (_a = this.options) == null ? void 0 : _a.features) == null ? void 0 : _b.email) === void 0 ? index.ConstantsUtil$2.DEFAULT_FEATURES.email : (_d = (_c = this.options) == null ? void 0 : _c.features) == null ? void 0 : _d.email;
|
|
2870
|
+
const isSocialsEnabled = ((_f = (_e = this.options) == null ? void 0 : _e.features) == null ? void 0 : _f.socials) ? ((_i = (_h = (_g = this.options) == null ? void 0 : _g.features) == null ? void 0 : _h.socials) == null ? void 0 : _i.length) > 0 : index.ConstantsUtil$2.DEFAULT_FEATURES.socials;
|
|
2871
|
+
const isAuthEnabled = isEmailEnabled || isSocialsEnabled;
|
|
2872
|
+
if (!this.authProvider && ((_j = this.options) == null ? void 0 : _j.projectId) && isAuthEnabled) {
|
|
2873
|
+
this.authProvider = W3mFrameProviderSingleton.getInstance({
|
|
2874
|
+
projectId: this.options.projectId,
|
|
2875
|
+
enableLogger: this.options.enableAuthLogger,
|
|
2876
|
+
chainId: (_k = this.getCaipNetwork()) == null ? void 0 : _k.caipNetworkId,
|
|
2877
|
+
onTimeout: () => {
|
|
2878
|
+
index.AlertController.open(ErrorUtil.ALERT_ERRORS.SOCIALS_TIMEOUT, "error");
|
|
2879
|
+
}
|
|
2880
|
+
});
|
|
2881
|
+
this.subscribeState((val) => {
|
|
2882
|
+
var _a2;
|
|
2883
|
+
if (!val.open) {
|
|
2884
|
+
(_a2 = this.authProvider) == null ? void 0 : _a2.rejectRpcRequests();
|
|
2885
|
+
}
|
|
2886
|
+
});
|
|
2887
|
+
this.syncAuthConnector(this.authProvider);
|
|
2888
|
+
}
|
|
2889
|
+
}
|
|
2890
|
+
async createUniversalProviderForAdapter(chainNamespace) {
|
|
2891
|
+
var _a, _b, _c;
|
|
2892
|
+
await this.getUniversalProvider();
|
|
2893
|
+
if (this.universalProvider) {
|
|
2894
|
+
(_c = (_b = (_a = this.chainAdapters) == null ? void 0 : _a[chainNamespace]) == null ? void 0 : _b.setUniversalProvider) == null ? void 0 : _c.call(_b, this.universalProvider);
|
|
2895
|
+
}
|
|
2896
|
+
}
|
|
2897
|
+
createAuthProviderForAdapter(chainNamespace) {
|
|
2898
|
+
var _a, _b, _c;
|
|
2899
|
+
this.createAuthProvider();
|
|
2900
|
+
if (this.authProvider) {
|
|
2901
|
+
(_c = (_b = (_a = this.chainAdapters) == null ? void 0 : _a[chainNamespace]) == null ? void 0 : _b.setAuthProvider) == null ? void 0 : _c.call(_b, this.authProvider);
|
|
2902
|
+
}
|
|
2903
|
+
}
|
|
2904
|
+
createAdapter(blueprint) {
|
|
2905
|
+
var _a;
|
|
2906
|
+
if (!blueprint) {
|
|
2907
|
+
return;
|
|
2908
|
+
}
|
|
2909
|
+
const namespace = blueprint.namespace;
|
|
2910
|
+
if (!namespace) {
|
|
2911
|
+
return;
|
|
2912
|
+
}
|
|
2913
|
+
this.createClients();
|
|
2914
|
+
const adapterBlueprint = blueprint;
|
|
2915
|
+
adapterBlueprint.namespace = namespace;
|
|
2916
|
+
adapterBlueprint.construct({
|
|
2917
|
+
namespace,
|
|
2918
|
+
projectId: (_a = this.options) == null ? void 0 : _a.projectId,
|
|
2919
|
+
networks: this.caipNetworks
|
|
2920
|
+
});
|
|
2921
|
+
if (!this.chainNamespaces.includes(namespace)) {
|
|
2922
|
+
this.chainNamespaces.push(namespace);
|
|
2923
|
+
}
|
|
2924
|
+
if (this.chainAdapters) {
|
|
2925
|
+
this.chainAdapters[namespace] = adapterBlueprint;
|
|
2926
|
+
}
|
|
2927
|
+
}
|
|
2928
|
+
createAdapters(blueprints) {
|
|
2929
|
+
this.createClients();
|
|
2930
|
+
return this.chainNamespaces.reduce((adapters, namespace) => {
|
|
2931
|
+
var _a;
|
|
2932
|
+
const blueprint = blueprints == null ? void 0 : blueprints.find((b) => b.namespace === namespace);
|
|
2933
|
+
if (blueprint) {
|
|
2934
|
+
adapters[namespace] = blueprint;
|
|
2935
|
+
adapters[namespace].namespace = namespace;
|
|
2936
|
+
adapters[namespace].construct({
|
|
2937
|
+
namespace,
|
|
2938
|
+
projectId: (_a = this.options) == null ? void 0 : _a.projectId,
|
|
2939
|
+
networks: this.caipNetworks
|
|
2940
|
+
});
|
|
2941
|
+
} else {
|
|
2942
|
+
adapters[namespace] = new UniversalAdapter({
|
|
2943
|
+
namespace,
|
|
2944
|
+
networks: this.caipNetworks
|
|
2945
|
+
});
|
|
2946
|
+
}
|
|
2947
|
+
return adapters;
|
|
2948
|
+
}, {});
|
|
2949
|
+
}
|
|
2950
|
+
onConnectors(chainNamespace) {
|
|
2951
|
+
const adapter = this.getAdapter(chainNamespace);
|
|
2952
|
+
adapter == null ? void 0 : adapter.on("connectors", this.setConnectors.bind(this));
|
|
2953
|
+
}
|
|
2954
|
+
async initChainAdapter(namespace) {
|
|
2955
|
+
var _a;
|
|
2956
|
+
this.onConnectors(namespace);
|
|
2957
|
+
this.listenAdapter(namespace);
|
|
2958
|
+
(_a = this.chainAdapters) == null ? void 0 : _a[namespace].syncConnectors(this.options, this);
|
|
2959
|
+
await this.createUniversalProviderForAdapter(namespace);
|
|
2960
|
+
this.createAuthProviderForAdapter(namespace);
|
|
2961
|
+
}
|
|
2962
|
+
async initChainAdapters() {
|
|
2963
|
+
await Promise.all(this.chainNamespaces.map(async (namespace) => {
|
|
2964
|
+
await this.initChainAdapter(namespace);
|
|
2965
|
+
}));
|
|
2966
|
+
}
|
|
2967
|
+
getUnsupportedNetwork(caipNetworkId) {
|
|
2968
|
+
return {
|
|
2969
|
+
id: caipNetworkId.split(":")[1],
|
|
2970
|
+
caipNetworkId,
|
|
2971
|
+
name: index.ConstantsUtil.UNSUPPORTED_NETWORK_NAME,
|
|
2972
|
+
chainNamespace: caipNetworkId.split(":")[0],
|
|
2973
|
+
nativeCurrency: {
|
|
2974
|
+
name: "",
|
|
2975
|
+
decimals: 0,
|
|
2976
|
+
symbol: ""
|
|
2977
|
+
},
|
|
2978
|
+
rpcUrls: {
|
|
2979
|
+
default: {
|
|
2980
|
+
http: []
|
|
2981
|
+
}
|
|
2982
|
+
}
|
|
2983
|
+
};
|
|
2984
|
+
}
|
|
2985
|
+
getDefaultNetwork() {
|
|
2986
|
+
var _a, _b;
|
|
2987
|
+
const caipNetworkId = index.StorageUtil.getActiveCaipNetworkId();
|
|
2988
|
+
if (caipNetworkId) {
|
|
2989
|
+
const caipNetwork = (_a = this.caipNetworks) == null ? void 0 : _a.find((n) => n.caipNetworkId === caipNetworkId);
|
|
2990
|
+
if (caipNetwork) {
|
|
2991
|
+
return caipNetwork;
|
|
2992
|
+
}
|
|
2993
|
+
return this.getUnsupportedNetwork(caipNetworkId);
|
|
2994
|
+
}
|
|
2995
|
+
return (_b = this.caipNetworks) == null ? void 0 : _b[0];
|
|
2996
|
+
}
|
|
2997
|
+
async injectModalUi() {
|
|
2998
|
+
if (!this.initPromise && !isInitialized && index.CoreHelperUtil.isClient()) {
|
|
2999
|
+
isInitialized = true;
|
|
3000
|
+
this.initPromise = new Promise(async (resolve) => {
|
|
3001
|
+
await Promise.all([
|
|
3002
|
+
Promise.resolve().then(() => require("./index-CnudU77V.js")),
|
|
3003
|
+
Promise.resolve().then(() => require("./w3m-modal-DCcF1qEB.js"))
|
|
3004
|
+
]);
|
|
3005
|
+
const modal2 = document.createElement("w3m-modal");
|
|
3006
|
+
if (!index.OptionsController.state.disableAppend && !index.OptionsController.state.enableEmbedded) {
|
|
3007
|
+
document.body.insertAdjacentElement("beforeend", modal2);
|
|
3008
|
+
}
|
|
3009
|
+
resolve();
|
|
3010
|
+
});
|
|
3011
|
+
}
|
|
3012
|
+
return this.initPromise;
|
|
3013
|
+
}
|
|
3014
|
+
}
|
|
3015
|
+
const PACKAGE_VERSION = "1.6.8";
|
|
3016
|
+
let modal = void 0;
|
|
3017
|
+
function createAppKit(options) {
|
|
3018
|
+
if (!modal) {
|
|
3019
|
+
modal = new AppKit({
|
|
3020
|
+
...options,
|
|
3021
|
+
sdkVersion: index.CoreHelperUtil.generateSdkVersion(options.adapters ?? [], "react", PACKAGE_VERSION)
|
|
3022
|
+
});
|
|
3023
|
+
index$1.getAppKit(modal);
|
|
3024
|
+
}
|
|
3025
|
+
return modal;
|
|
3026
|
+
}
|
|
3027
|
+
function useAppKitNetwork() {
|
|
3028
|
+
const { caipNetwork, caipNetworkId, chainId } = react.useAppKitNetworkCore();
|
|
3029
|
+
function switchNetwork(network) {
|
|
3030
|
+
modal == null ? void 0 : modal.switchNetwork(network);
|
|
3031
|
+
}
|
|
3032
|
+
return {
|
|
3033
|
+
caipNetwork,
|
|
3034
|
+
caipNetworkId,
|
|
3035
|
+
chainId,
|
|
3036
|
+
switchNetwork
|
|
3037
|
+
};
|
|
3038
|
+
}
|
|
3039
|
+
exports.createAppKit = createAppKit;
|
|
3040
|
+
exports.useAppKitNetwork = useAppKitNetwork;
|