@getpara/react-sdk 2.0.0-dev.2 → 2.0.0-dev.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/cli.mjs +22 -7
- package/dist/index.d.ts +0 -1
- package/dist/index.js +6 -7058
- package/dist/modal/ParaModal.js +301 -0
- package/dist/modal/components/Account/Account.js +148 -0
- package/dist/modal/components/Account/AccountProfile.d.ts +1 -0
- package/dist/modal/components/Account/AccountProfile.js +168 -0
- package/dist/modal/components/Account/AccountProfileLink.d.ts +1 -0
- package/dist/modal/components/Account/AccountProfileLink.js +206 -0
- package/dist/modal/components/Account/AccountProfileLinkOptions.d.ts +1 -0
- package/dist/modal/components/Account/AccountProfileLinkOptions.js +111 -0
- package/dist/modal/components/Account/AccountProfileUnlink.d.ts +1 -0
- package/dist/modal/components/Account/AccountProfileUnlink.js +47 -0
- package/dist/modal/components/AddFunds/AddFunds.d.ts +0 -2
- package/dist/modal/components/AddFunds/AddFunds.js +69 -0
- package/dist/modal/components/AddFunds/AddFundsAsset.d.ts +1 -0
- package/dist/modal/components/AddFunds/AddFundsAsset.js +125 -0
- package/dist/modal/components/AddFunds/AddFundsAwaiting.js +78 -0
- package/dist/modal/components/AddFunds/AddFundsContext.d.ts +31 -0
- package/dist/modal/components/AddFunds/AddFundsContext.js +160 -0
- package/dist/modal/components/AddFunds/AddFundsDone.js +49 -0
- package/dist/modal/components/AddFunds/AddFundsProvider.d.ts +1 -0
- package/dist/modal/components/AddFunds/AddFundsProvider.js +109 -0
- package/dist/modal/components/AddFunds/AddFundsReceive.d.ts +1 -0
- package/dist/modal/components/AddFunds/AddFundsReceive.js +83 -0
- package/dist/modal/components/AddFunds/AddFundsSettings.d.ts +1 -0
- package/dist/modal/components/AddFunds/AddFundsSettings.js +237 -0
- package/dist/{MoonPayEmbed-Q2HP2BFI.js → modal/components/AddFunds/MoonPayEmbed.js} +1 -3
- package/dist/modal/components/AddFunds/common.d.ts +19 -0
- package/dist/modal/components/AddFunds/common.js +24 -0
- package/dist/modal/components/AddFunds/index.js +4 -0
- package/dist/modal/components/AuthInput/AuthInput.d.ts +17 -3
- package/dist/modal/components/AuthInput/AuthInput.js +277 -0
- package/dist/modal/components/AuthInput/hooks/useDropdownPosition.js +33 -0
- package/dist/modal/components/AuthInput/phoneMasks.js +253 -0
- package/dist/modal/components/AuthMainStep/AuthMainStep.d.ts +4 -3
- package/dist/modal/components/AuthMainStep/AuthMainStep.js +50 -0
- package/dist/modal/components/AuthMainStep/AuthMainStepContent.d.ts +4 -3
- package/dist/modal/components/AuthMainStep/AuthMainStepContent.js +164 -0
- package/dist/modal/components/AuthOptions/AuthOptions.d.ts +4 -3
- package/dist/modal/components/AuthOptions/AuthOptions.js +85 -0
- package/dist/modal/components/AwaitingBiometricsStep/AwaitingBiometricsStep.js +18 -0
- package/dist/modal/components/AwaitingOAuthStep/AwaitingOAuthStep.js +10 -0
- package/dist/modal/components/AwaitingPasswordStep/AwaitingPasswordStep.js +18 -0
- package/dist/modal/components/AwaitingWalletCreationStep/AwaitingWalletCreationStep.d.ts +5 -1
- package/dist/modal/components/AwaitingWalletCreationStep/AwaitingWalletCreationStep.js +49 -0
- package/dist/modal/components/BiometricCreationStep/BiometricCreationStep.d.ts +1 -1
- package/dist/modal/components/BiometricCreationStep/BiometricCreationStep.js +62 -0
- package/dist/modal/components/BiometricLoginStep/BiometricLoginStep.d.ts +1 -1
- package/dist/modal/components/BiometricLoginStep/BiometricLoginStep.js +48 -0
- package/dist/modal/components/Body/AnimatedHeightWrapper.js +29 -0
- package/dist/modal/components/Body/Body.d.ts +4 -3
- package/dist/modal/components/Body/Body.js +350 -0
- package/dist/modal/components/ChainSwitch/ChainSwitch.js +95 -0
- package/dist/modal/components/ChainSwitch/config.js +17 -0
- package/dist/modal/components/Controls/Controls.js +78 -0
- package/dist/modal/components/Controls/Selects.js +173 -0
- package/dist/modal/components/ExternalWalletNetworkSelectStep/ExternalWalletNetworkSelectStep.d.ts +1 -0
- package/dist/modal/components/ExternalWalletNetworkSelectStep/ExternalWalletNetworkSelectStep.js +75 -0
- package/dist/modal/components/ExternalWalletStep/ExternalWalletStep.d.ts +7 -0
- package/dist/modal/components/ExternalWalletStep/ExternalWalletStep.js +175 -0
- package/dist/modal/components/ExternalWalletStep/config.js +17 -0
- package/dist/modal/components/ExternalWalletVerificationStep/ExternalWalletVerificationStep.js +39 -0
- package/dist/modal/components/ExternalWallets/ExternalWallets.js +184 -0
- package/dist/modal/components/Footer/Footer.js +95 -0
- package/dist/modal/components/Header/Header.js +43 -0
- package/dist/modal/components/Header/hooks/useStepTitle.js +61 -0
- package/dist/modal/components/Hero/Hero.js +116 -0
- package/dist/modal/components/IFrameStep/IFrameStep.js +59 -0
- package/dist/modal/components/LoginDoneStep/LoginDoneStep.d.ts +4 -0
- package/dist/modal/components/LoginDoneStep/LoginDoneStep.js +44 -0
- package/dist/modal/components/ModalContent/ModalContent.d.ts +0 -4
- package/dist/modal/components/ModalContent/ModalContent.js +88 -0
- package/dist/modal/components/OAuth/FarcasterOAuthStep.d.ts +1 -0
- package/dist/modal/components/OAuth/FarcasterOAuthStep.js +31 -0
- package/dist/modal/components/OAuth/OAuth.d.ts +2 -2
- package/dist/modal/components/OAuth/OAuth.js +79 -0
- package/dist/modal/components/OAuth/TelegramOAuthStep.d.ts +7 -0
- package/dist/modal/components/OAuth/TelegramOAuthStep.js +74 -0
- package/dist/modal/components/OnRampComponents/AddingFunds.js +23 -0
- package/dist/modal/components/OnRampComponents/OnRampProviderButton.js +77 -0
- package/dist/modal/components/RecoverySecretStep/RecoverySecretStep.js +107 -0
- package/dist/modal/components/Setup2FAStep/Setup2FAStep.js +132 -0
- package/dist/modal/components/TwoFactorDoneStep/TwoFactorDoneStep.js +27 -0
- package/dist/modal/components/VerificationCodeStep/VerificationCodeStep.d.ts +12 -1
- package/dist/modal/components/VerificationCodeStep/VerificationCodeStep.js +160 -0
- package/dist/modal/components/Waiting/Waiting.js +17 -0
- package/dist/modal/components/WalletCard/PartnerIcon.js +34 -0
- package/dist/modal/components/WalletCard/WalletCard.d.ts +3 -3
- package/dist/modal/components/WalletCard/WalletCard.js +128 -0
- package/dist/modal/components/WalletCreationDoneStep/WalletCreationDoneStep.js +83 -0
- package/dist/modal/components/common.d.ts +49 -13
- package/dist/modal/components/common.js +261 -0
- package/dist/modal/components/index.js +2 -0
- package/dist/modal/constants/constants.d.ts +10 -2
- package/dist/modal/constants/constants.js +142 -0
- package/dist/modal/constants/defaults.js +10 -0
- package/dist/modal/constants/oAuthLogos.d.ts +15 -6
- package/dist/modal/constants/oAuthLogos.js +158 -0
- package/dist/modal/constants/walletTypeConfig.d.ts +6 -0
- package/dist/modal/constants/walletTypeConfig.js +13 -0
- package/dist/modal/hooks/useGoBack.js +43 -0
- package/dist/modal/hooks/useTelegramLogin.d.ts +12 -0
- package/dist/modal/hooks/useTelegramLogin.js +65 -0
- package/dist/modal/index.d.ts +1 -1
- package/dist/modal/index.js +29 -0
- package/dist/modal/stores/index.d.ts +0 -1
- package/dist/modal/stores/index.js +2 -0
- package/dist/modal/stores/modal/actions.js +135 -0
- package/dist/modal/stores/modal/useModalStore.d.ts +17 -16
- package/dist/modal/stores/modal/useModalStore.js +73 -0
- package/dist/modal/types/commonTypes.js +1 -0
- package/dist/modal/types/modalProps.d.ts +15 -2
- package/dist/modal/types/modalProps.js +12 -0
- package/dist/modal/utils/authInputHelpers.d.ts +5 -0
- package/dist/modal/utils/authInputHelpers.js +41 -0
- package/dist/modal/utils/authLayoutHelpers.js +8 -0
- package/dist/modal/utils/countryCodes.js +45 -0
- package/dist/modal/utils/getMailtoLink.js +10 -0
- package/dist/modal/utils/getTileButtonFlex.js +20 -0
- package/dist/modal/utils/getWalletDisplayName.d.ts +5 -0
- package/dist/modal/utils/getWalletDisplayName.js +22 -0
- package/dist/modal/utils/isPasskeySupported.js +15 -0
- package/dist/modal/utils/openPopup.js +60 -0
- package/dist/modal/utils/routeMobileExternalWallet.js +31 -0
- package/dist/modal/utils/steps.d.ts +21 -2
- package/dist/modal/utils/steps.js +273 -0
- package/dist/modal/utils/stringFormatters.d.ts +1 -0
- package/dist/modal/utils/stringFormatters.js +19 -0
- package/dist/modal/utils/validateOnRampConfig.js +32 -0
- package/dist/package.json +6 -0
- package/dist/provider/ParaProvider.js +117 -0
- package/dist/provider/actions/getEmbeddedAccount.d.ts +26 -0
- package/dist/provider/actions/getEmbeddedAccount.js +52 -0
- package/dist/provider/actions/getWallet.d.ts +3 -3
- package/dist/provider/actions/getWallet.js +18 -0
- package/dist/provider/actions/index.d.ts +40 -18
- package/dist/provider/actions/index.js +79 -0
- package/dist/provider/actions/utils.d.ts +4 -3
- package/dist/provider/actions/utils.js +34 -0
- package/dist/provider/components/CosmosWalletWrapper.js +43 -0
- package/dist/provider/components/EvmWalletWrapper.js +43 -0
- package/dist/provider/components/ExternalWalletWrapper.js +140 -0
- package/dist/provider/components/SolanaWalletWrapper.js +44 -0
- package/dist/provider/external/getParaCosmosConnector.js +19 -0
- package/dist/provider/external/getParaCosmosLib.d.ts +4 -0
- package/dist/provider/external/getParaCosmosLib.js +16 -0
- package/dist/provider/external/getParaEvmConnector.js +19 -0
- package/dist/provider/external/getParaEvmLib.d.ts +4 -0
- package/dist/provider/external/getParaEvmLib.js +16 -0
- package/dist/provider/external/getParaSolanaConnector.js +19 -0
- package/dist/provider/external/getParaSolanaLib.d.ts +4 -0
- package/dist/provider/external/getParaSolanaLib.js +16 -0
- package/dist/provider/external/stubs/CosmosExternalWalletContextStub.d.ts +1 -11
- package/dist/provider/external/stubs/CosmosExternalWalletContextStub.js +8 -0
- package/dist/provider/external/stubs/EvmExternalWalletContextStub.d.ts +1 -2
- package/dist/provider/external/stubs/EvmExternalWalletContextStub.js +8 -0
- package/dist/provider/external/stubs/SolanaExternalWalletContextStub.d.ts +1 -7
- package/dist/provider/external/stubs/SolanaExternalWalletContextStub.js +8 -0
- package/dist/provider/hooks/index.js +4 -0
- package/dist/provider/hooks/mutations/core.d.ts +27 -0
- package/dist/provider/hooks/mutations/core.js +66 -0
- package/dist/provider/hooks/mutations/index.d.ts +3 -34
- package/dist/provider/hooks/mutations/index.js +9 -0
- package/dist/provider/hooks/mutations/useLinkAccount.d.ts +9 -0
- package/dist/provider/hooks/mutations/useLinkAccount.js +18 -0
- package/dist/provider/hooks/mutations/utils.d.ts +11 -3
- package/dist/provider/hooks/mutations/utils.js +90 -0
- package/dist/provider/hooks/queries/core.d.ts +4 -0
- package/dist/provider/hooks/queries/core.js +16 -0
- package/dist/provider/hooks/queries/index.d.ts +2 -0
- package/dist/provider/hooks/queries/index.js +11 -0
- package/dist/provider/hooks/queries/useAccount.d.ts +86 -7
- package/dist/provider/hooks/queries/useAccount.js +135 -0
- package/dist/provider/hooks/queries/useIsFullyLoggedIn.d.ts +5 -0
- package/dist/provider/hooks/queries/useIsFullyLoggedIn.js +24 -0
- package/dist/provider/hooks/queries/useWallet.d.ts +1 -1
- package/dist/provider/hooks/queries/useWallet.js +26 -0
- package/dist/provider/hooks/queries/useWalletBalance.d.ts +6 -0
- package/dist/provider/hooks/queries/useWalletBalance.js +55 -0
- package/dist/provider/hooks/queries/utils.d.ts +7 -0
- package/dist/provider/hooks/queries/utils.js +25 -0
- package/dist/provider/hooks/utils/index.js +10 -0
- package/dist/provider/hooks/utils/useAutoSessionKeepAlive.js +74 -0
- package/dist/provider/hooks/utils/useClient.d.ts +1 -1
- package/dist/provider/hooks/utils/useClient.js +10 -0
- package/dist/provider/hooks/utils/useEventListeners.d.ts +1 -1
- package/dist/provider/hooks/utils/useEventListeners.js +157 -0
- package/dist/provider/hooks/utils/useFormattedBiometricHints.d.ts +4 -0
- package/dist/provider/hooks/utils/useFormattedBiometricHints.js +27 -0
- package/dist/provider/hooks/utils/useInternalClient.js +10 -0
- package/dist/provider/hooks/utils/useModal.d.ts +4 -1
- package/dist/provider/hooks/utils/useModal.js +27 -0
- package/dist/provider/hooks/utils/useWalletState.d.ts +3 -3
- package/dist/provider/hooks/utils/useWalletState.js +48 -0
- package/dist/provider/index.d.ts +2 -0
- package/dist/provider/index.js +11 -0
- package/dist/provider/providers/AccountLinkProvider.d.ts +47 -0
- package/dist/provider/providers/AccountLinkProvider.js +452 -0
- package/dist/provider/providers/AuthProvider.d.ts +12 -6
- package/dist/provider/providers/AuthProvider.js +523 -0
- package/dist/provider/providers/CosmosExternalWalletProvider.js +66 -0
- package/dist/provider/providers/EvmExternalWalletProvider.js +74 -0
- package/dist/provider/providers/ExternalWalletProvider.d.ts +23 -43
- package/dist/provider/providers/ExternalWalletProvider.js +596 -0
- package/dist/provider/providers/SolanaExternalWalletProvider.js +66 -0
- package/dist/provider/stores/getters.d.ts +1 -1
- package/dist/provider/stores/getters.js +13 -0
- package/dist/provider/stores/setters.js +7 -0
- package/dist/provider/stores/slices/analytics.d.ts +3 -0
- package/dist/provider/stores/slices/analytics.js +9 -0
- package/dist/provider/stores/slices/client.js +9 -0
- package/dist/provider/stores/slices/config.js +9 -0
- package/dist/provider/stores/slices/externalWallets.js +46 -0
- package/dist/provider/stores/slices/index.d.ts +1 -0
- package/dist/provider/stores/slices/index.js +6 -0
- package/dist/provider/stores/slices/modal.js +18 -0
- package/dist/provider/stores/slices/wallet.js +13 -0
- package/dist/provider/stores/types.d.ts +19 -5
- package/dist/provider/stores/types.js +1 -0
- package/dist/provider/stores/useStore.js +34 -0
- package/dist/provider/types/externalWalletProviders.js +1 -0
- package/dist/provider/types/provider.d.ts +23 -4
- package/dist/provider/types/provider.js +1 -0
- package/dist/provider/types/query.js +1 -0
- package/dist/provider/types/utils.d.ts +28 -5
- package/dist/provider/types/utils.js +1 -0
- package/dist/provider/utils/constants.d.ts +5 -0
- package/dist/provider/utils/constants.js +10 -0
- package/dist/provider/utils/paraConfigTypeGuards.js +13 -0
- package/dist/provider/utils/renameMutations.d.ts +2 -2
- package/dist/provider/utils/renameMutations.js +18 -0
- package/package.json +40 -39
- package/dist/MoonPayEmbed-Q2HP2BFI.js.br +0 -0
- package/dist/MoonPayEmbed-Q2HP2BFI.js.gz +0 -0
- package/dist/chunk-MMUBH76A.js.br +0 -0
- package/dist/chunk-MMUBH76A.js.gz +0 -0
- package/dist/index.js.br +0 -0
- package/dist/index.js.gz +0 -0
- package/dist/modal/components/StripeComponents/StripeComponents.d.ts +0 -16
- package/dist/modal/hooks/useCreateAccount.d.ts +0 -4
- package/dist/modal/stores/userInfo/actions.d.ts +0 -3
- package/dist/modal/stores/userInfo/useUserInfoStore.d.ts +0 -19
- package/dist/provider/actions/checkIfUserExists.d.ts +0 -4
- package/dist/provider/actions/createUser.d.ts +0 -4
- package/dist/provider/actions/getAccount.d.ts +0 -10
- package/dist/provider/actions/initiateLogin.d.ts +0 -4
- package/dist/provider/actions/keepSessionAlive.d.ts +0 -2
- package/dist/provider/actions/logout.d.ts +0 -5
- package/dist/provider/actions/signMessage.d.ts +0 -8
- package/dist/provider/actions/signTransaction.d.ts +0 -8
- package/dist/provider/actions/waitForAccountCreation.d.ts +0 -5
- package/dist/provider/actions/waitForLoginAndSetup.d.ts +0 -6
- package/dist/provider/actions/waitForPasskeyAndCreateWallet.d.ts +0 -2
- package/dist/provider/hooks/mutations/useCheckIfUserExists.d.ts +0 -13
- package/dist/provider/hooks/mutations/useCreateUser.d.ts +0 -13
- package/dist/provider/hooks/mutations/useInitiateLogin.d.ts +0 -14
- package/dist/provider/hooks/mutations/useKeepSessionAlive.d.ts +0 -12
- package/dist/provider/hooks/mutations/useLogout.d.ts +0 -13
- package/dist/provider/hooks/mutations/useSignMessage.d.ts +0 -15
- package/dist/provider/hooks/mutations/useSignTransaction.d.ts +0 -15
- package/dist/provider/hooks/mutations/useWaitForAccountCreation.d.ts +0 -13
- package/dist/provider/hooks/mutations/useWaitForLoginAndSetup.d.ts +0 -14
- package/dist/provider/hooks/mutations/useWaitForPasskeyAndCreateWallet.d.ts +0 -13
- /package/dist/modal/{components/AuthInput → utils}/countryCodes.d.ts +0 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Dispatch, PropsWithChildren, ReactNode, SetStateAction } from 'react';
|
|
2
|
+
import { useWallet } from '../../../provider/hooks/index.js';
|
|
3
|
+
import { EnabledFlow, Network, OnRampAsset, OnRampConfig, OnRampProvider } from '@getpara/web-sdk';
|
|
4
|
+
import { IconType } from '@getpara/react-components';
|
|
5
|
+
export type Tab = EnabledFlow;
|
|
6
|
+
export declare const TABS: [
|
|
7
|
+
Tab,
|
|
8
|
+
keyof Pick<OnRampConfig, 'isBuyEnabled' | 'isReceiveEnabled' | 'isWithdrawEnabled'>,
|
|
9
|
+
IconType,
|
|
10
|
+
ReactNode
|
|
11
|
+
][];
|
|
12
|
+
type Value = {
|
|
13
|
+
network: Network | undefined;
|
|
14
|
+
setNetwork: Dispatch<SetStateAction<Value['network']>>;
|
|
15
|
+
asset: OnRampAsset | undefined;
|
|
16
|
+
setAsset: Dispatch<SetStateAction<Value['asset']>>;
|
|
17
|
+
fiatQuantity: string | undefined;
|
|
18
|
+
setFiatQuantity: Dispatch<SetStateAction<Value['fiatQuantity']>>;
|
|
19
|
+
networks: Network[];
|
|
20
|
+
assets: OnRampAsset[];
|
|
21
|
+
isProviderAllowed: Partial<Record<OnRampProvider, boolean>>;
|
|
22
|
+
tab: Tab;
|
|
23
|
+
activeWallet: ReturnType<typeof useWallet>['data'];
|
|
24
|
+
onRampConfig: OnRampConfig;
|
|
25
|
+
};
|
|
26
|
+
export declare const AddFundsContext: import("react").Context<Value>;
|
|
27
|
+
export declare function AddFundsContextProvider({ tab, children }: PropsWithChildren<{
|
|
28
|
+
tab: Tab;
|
|
29
|
+
}>): import("react/jsx-runtime").JSX.Element;
|
|
30
|
+
export declare const useAddFunds: () => Value;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
__spreadProps,
|
|
4
|
+
__spreadValues
|
|
5
|
+
} from "../../../chunk-MMUBH76A.js";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
import {
|
|
8
|
+
createContext,
|
|
9
|
+
useContext,
|
|
10
|
+
useEffect,
|
|
11
|
+
useMemo,
|
|
12
|
+
useState
|
|
13
|
+
} from "react";
|
|
14
|
+
import { OnRampStep, useModalStore } from "../../stores/index.js";
|
|
15
|
+
import { useWallet } from "../../../provider/hooks/index.js";
|
|
16
|
+
import { useExternalWallets } from "../../../provider/providers/ExternalWalletProvider.js";
|
|
17
|
+
import {
|
|
18
|
+
EnabledFlow,
|
|
19
|
+
getOnRampAssets,
|
|
20
|
+
getOnRampNetworks,
|
|
21
|
+
OnRampPurchaseType
|
|
22
|
+
} from "@getpara/web-sdk";
|
|
23
|
+
import { getNetworkFromChainId, getNetworkOrMainNetEquivalent } from "@getpara/react-common";
|
|
24
|
+
const TABS = [
|
|
25
|
+
[EnabledFlow.BUY, "isBuyEnabled", "creditCard", "Buy"],
|
|
26
|
+
[EnabledFlow.RECEIVE, "isReceiveEnabled", "qrCode", "Receive"],
|
|
27
|
+
[EnabledFlow.WITHDRAW, "isWithdrawEnabled", "arrowCircleBrokenDownLeft", "Withdraw"]
|
|
28
|
+
];
|
|
29
|
+
const DEFAULT = {
|
|
30
|
+
networks: [],
|
|
31
|
+
assets: [],
|
|
32
|
+
isProviderAllowed: {},
|
|
33
|
+
tab: TABS[0][0],
|
|
34
|
+
network: void 0,
|
|
35
|
+
setNetwork: () => {
|
|
36
|
+
},
|
|
37
|
+
asset: void 0,
|
|
38
|
+
setAsset: () => {
|
|
39
|
+
},
|
|
40
|
+
fiatQuantity: "25.00",
|
|
41
|
+
setFiatQuantity: () => {
|
|
42
|
+
},
|
|
43
|
+
onRampConfig: {},
|
|
44
|
+
activeWallet: {}
|
|
45
|
+
};
|
|
46
|
+
function isValid(onRampConfig, walletType, network, asset) {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
return network && asset && walletType ? !!((_b = (_a = onRampConfig == null ? void 0 : onRampConfig.assetInfo[walletType]) == null ? void 0 : _a[network]) == null ? void 0 : _b[asset]) : false;
|
|
49
|
+
}
|
|
50
|
+
const AddFundsContext = createContext(DEFAULT);
|
|
51
|
+
function AddFundsContextProvider({ tab, children }) {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
const onRampConfig = useModalStore((state) => state.onRampConfig);
|
|
54
|
+
const onRampStep = useModalStore((state) => state.onRampStep);
|
|
55
|
+
const setOnRampStep = useModalStore((state) => state.setOnRampStep);
|
|
56
|
+
const { chainId } = useExternalWallets();
|
|
57
|
+
const { data: activeWallet } = useWallet();
|
|
58
|
+
const [fiatQuantity, setFiatQuantity] = useState((_b = (_a = onRampConfig == null ? void 0 : onRampConfig.defaultBuyAmount) == null ? void 0 : _a[0]) != null ? _b : "25.00");
|
|
59
|
+
const networks = useMemo(() => {
|
|
60
|
+
if (!onRampConfig) {
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
const detectedNetwork = getNetworkFromChainId(chainId);
|
|
64
|
+
const isExternal = (activeWallet == null ? void 0 : activeWallet.isExternal) && !!detectedNetwork;
|
|
65
|
+
return isExternal ? [getNetworkOrMainNetEquivalent(detectedNetwork, onRampConfig.testMode)] : getOnRampNetworks(onRampConfig.assetInfo, {
|
|
66
|
+
walletType: activeWallet == null ? void 0 : activeWallet.type,
|
|
67
|
+
allowed: onRampConfig.allowedAssets ? Object.keys(onRampConfig.allowedAssets) : void 0,
|
|
68
|
+
providers: onRampConfig.providers,
|
|
69
|
+
action: OnRampPurchaseType[tab === EnabledFlow.BUY ? "BUY" : "SELL"]
|
|
70
|
+
});
|
|
71
|
+
}, [chainId, activeWallet, onRampConfig, tab]);
|
|
72
|
+
const assets = useMemo(() => {
|
|
73
|
+
if (!onRampConfig) {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
return [
|
|
77
|
+
...new Set(
|
|
78
|
+
Object.values(
|
|
79
|
+
networks.reduce((acc, network2) => {
|
|
80
|
+
var _a2;
|
|
81
|
+
const configValue = (_a2 = onRampConfig.allowedAssets) == null ? void 0 : _a2[network2];
|
|
82
|
+
const allowed = configValue === true ? void 0 : configValue;
|
|
83
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
84
|
+
[network2]: getOnRampAssets(onRampConfig.assetInfo, {
|
|
85
|
+
walletType: activeWallet == null ? void 0 : activeWallet.type,
|
|
86
|
+
network: network2,
|
|
87
|
+
allowed,
|
|
88
|
+
providers: onRampConfig.providers,
|
|
89
|
+
action: OnRampPurchaseType[tab === EnabledFlow.BUY ? "BUY" : "SELL"]
|
|
90
|
+
})
|
|
91
|
+
});
|
|
92
|
+
}, {})
|
|
93
|
+
).flat()
|
|
94
|
+
)
|
|
95
|
+
];
|
|
96
|
+
}, [networks, onRampConfig, activeWallet, tab]);
|
|
97
|
+
const [network, setNetwork] = useState(
|
|
98
|
+
!!(activeWallet == null ? void 0 : activeWallet.type) && !!(onRampConfig == null ? void 0 : onRampConfig.defaultOnRampNetwork) && !!onRampConfig.assetInfo[activeWallet.type][onRampConfig.defaultOnRampNetwork] ? onRampConfig.defaultOnRampNetwork : void 0
|
|
99
|
+
);
|
|
100
|
+
const [asset, setAsset] = useState(
|
|
101
|
+
!!network && !!(onRampConfig == null ? void 0 : onRampConfig.defaultOnRampAsset) && assets.includes(onRampConfig.defaultOnRampAsset) ? onRampConfig.defaultOnRampAsset : void 0
|
|
102
|
+
);
|
|
103
|
+
const isProviderAllowed = useMemo(
|
|
104
|
+
() => onRampConfig && !!(activeWallet == null ? void 0 : activeWallet.type) ? onRampConfig.providers.reduce(
|
|
105
|
+
(acc, id) => {
|
|
106
|
+
var _a2, _b2, _c, _d, _e;
|
|
107
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
108
|
+
[id]: !!network && !!asset && !!((_e = (_d = (_c = (_b2 = (_a2 = onRampConfig.assetInfo[activeWallet.type]) == null ? void 0 : _a2[network]) == null ? void 0 : _b2[asset]) == null ? void 0 : _c[id]) == null ? void 0 : _d[1]) == null ? void 0 : _e[tab === EnabledFlow.BUY ? "BUY" : "SELL"])
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
{}
|
|
112
|
+
) : {},
|
|
113
|
+
[onRampConfig, network, asset, activeWallet, tab]
|
|
114
|
+
);
|
|
115
|
+
const value = useMemo(() => {
|
|
116
|
+
if (!onRampConfig || !activeWallet) {
|
|
117
|
+
return DEFAULT;
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
tab,
|
|
121
|
+
networks,
|
|
122
|
+
assets,
|
|
123
|
+
isProviderAllowed,
|
|
124
|
+
asset,
|
|
125
|
+
setAsset,
|
|
126
|
+
network,
|
|
127
|
+
setNetwork,
|
|
128
|
+
fiatQuantity,
|
|
129
|
+
setFiatQuantity,
|
|
130
|
+
activeWallet,
|
|
131
|
+
onRampConfig
|
|
132
|
+
};
|
|
133
|
+
}, [
|
|
134
|
+
tab,
|
|
135
|
+
networks,
|
|
136
|
+
assets,
|
|
137
|
+
isProviderAllowed,
|
|
138
|
+
asset,
|
|
139
|
+
setAsset,
|
|
140
|
+
network,
|
|
141
|
+
setNetwork,
|
|
142
|
+
fiatQuantity,
|
|
143
|
+
setFiatQuantity,
|
|
144
|
+
activeWallet,
|
|
145
|
+
onRampConfig
|
|
146
|
+
]);
|
|
147
|
+
useEffect(() => {
|
|
148
|
+
if (!!activeWallet && onRampStep === OnRampStep.PROVIDER && !isValid(onRampConfig, activeWallet.type, network, asset)) {
|
|
149
|
+
setOnRampStep(OnRampStep.SETTINGS);
|
|
150
|
+
}
|
|
151
|
+
}, [onRampStep, onRampConfig, activeWallet, network, asset, setOnRampStep]);
|
|
152
|
+
return /* @__PURE__ */ jsx(AddFundsContext.Provider, { value, children });
|
|
153
|
+
}
|
|
154
|
+
const useAddFunds = () => useContext(AddFundsContext);
|
|
155
|
+
export {
|
|
156
|
+
AddFundsContext,
|
|
157
|
+
AddFundsContextProvider,
|
|
158
|
+
TABS,
|
|
159
|
+
useAddFunds
|
|
160
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "../../../chunk-MMUBH76A.js";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { Heading, HeroIcon, InnerStepContainer, StepContainer } from "../common.js";
|
|
5
|
+
import { useModalStore } from "../../stores/index.js";
|
|
6
|
+
import { useMemo } from "react";
|
|
7
|
+
import { CpslButton, CpslText } from "@getpara/react-components";
|
|
8
|
+
import { getAddFundsStep } from "../../utils/steps.js";
|
|
9
|
+
import { useStore } from "../../../provider/stores/useStore.js";
|
|
10
|
+
import { EnabledFlow } from "@getpara/web-sdk";
|
|
11
|
+
const AddFundsDone = ({ isSuccess, onClose }) => {
|
|
12
|
+
var _a;
|
|
13
|
+
const hideWallets = useStore((state) => {
|
|
14
|
+
var _a2;
|
|
15
|
+
return (_a2 = state.modalConfig) == null ? void 0 : _a2.hideWallets;
|
|
16
|
+
});
|
|
17
|
+
const setStep = useModalStore((state) => state.setStep);
|
|
18
|
+
const onRampPurchase = useModalStore((state) => state.onRampPurchase);
|
|
19
|
+
const accountAddFundTab = useModalStore((state) => state.accountAddFundTab);
|
|
20
|
+
const formatter = useMemo(() => {
|
|
21
|
+
return new Intl.NumberFormat("en-US", {
|
|
22
|
+
style: "currency",
|
|
23
|
+
currency: (onRampPurchase == null ? void 0 : onRampPurchase.fiat) || "USD"
|
|
24
|
+
});
|
|
25
|
+
}, [onRampPurchase == null ? void 0 : onRampPurchase.fiat]);
|
|
26
|
+
const heading = isSuccess ? "Transaction Successful" : "Something Went Wrong";
|
|
27
|
+
const text = isSuccess ? `${formatter.format(parseFloat((_a = onRampPurchase == null ? void 0 : onRampPurchase.fiatQuantity) != null ? _a : "0"))} is now available in your ${hideWallets ? "account" : "wallet"}.` : `No funds were added to your ${hideWallets ? "account" : "wallet"}.`;
|
|
28
|
+
const buttonText = isSuccess ? "Done" : "Try Again";
|
|
29
|
+
return /* @__PURE__ */ jsxs(StepContainer, { children: [
|
|
30
|
+
/* @__PURE__ */ jsx(HeroIcon, { icon: "checkCircleFilled" }),
|
|
31
|
+
/* @__PURE__ */ jsxs(InnerStepContainer, { children: [
|
|
32
|
+
/* @__PURE__ */ jsx(Heading, { variant: "headingS", weight: "bold", children: heading }),
|
|
33
|
+
/* @__PURE__ */ jsx(CpslText, { variant: "bodyS", color: "secondary", children: text })
|
|
34
|
+
] }),
|
|
35
|
+
/* @__PURE__ */ jsx(
|
|
36
|
+
CpslButton,
|
|
37
|
+
{
|
|
38
|
+
fullWidth: true,
|
|
39
|
+
onClick: () => {
|
|
40
|
+
isSuccess ? onClose() : setStep(getAddFundsStep(accountAddFundTab != null ? accountAddFundTab : EnabledFlow.BUY));
|
|
41
|
+
},
|
|
42
|
+
children: buttonText
|
|
43
|
+
}
|
|
44
|
+
)
|
|
45
|
+
] });
|
|
46
|
+
};
|
|
47
|
+
export {
|
|
48
|
+
AddFundsDone
|
|
49
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function AddFundsProvider(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
__async,
|
|
4
|
+
__spreadProps,
|
|
5
|
+
__spreadValues
|
|
6
|
+
} from "../../../chunk-MMUBH76A.js";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { safeStyled } from "@getpara/react-common";
|
|
9
|
+
import { Heading, InnerStepContainer } from "../common.js";
|
|
10
|
+
import { CpslText } from "@getpara/react-components";
|
|
11
|
+
import { useAddFunds } from "./AddFundsContext.js";
|
|
12
|
+
import { useModalStore } from "../../stores/index.js";
|
|
13
|
+
import { useStore } from "../../../provider/stores/useStore.js";
|
|
14
|
+
import { motion, AnimatePresence } from "framer-motion";
|
|
15
|
+
import { OnRampProviderButton } from "../OnRampComponents/OnRampProviderButton.js";
|
|
16
|
+
import { useWallet } from "../../../provider/index.js";
|
|
17
|
+
import { EnabledFlow, OnRampProvider, OnRampPurchaseType } from "@getpara/web-sdk";
|
|
18
|
+
import { ModalStep } from "../../utils/steps.js";
|
|
19
|
+
import { contentMotionProps } from "./common.js";
|
|
20
|
+
import { useInternalClient } from "../../../provider/hooks/utils/useInternalClient.js";
|
|
21
|
+
function AddFundsProvider() {
|
|
22
|
+
const para = useInternalClient();
|
|
23
|
+
const hideWallets = useStore((state) => {
|
|
24
|
+
var _a;
|
|
25
|
+
return (_a = state.modalConfig) == null ? void 0 : _a.hideWallets;
|
|
26
|
+
});
|
|
27
|
+
const onRampConfig = useModalStore((state) => state.onRampConfig);
|
|
28
|
+
const setOnRampPurchase = useModalStore((state) => state.setOnRampPurchase);
|
|
29
|
+
const setModalStep = useModalStore((state) => state.setStep);
|
|
30
|
+
const { asset, network, fiatQuantity, isProviderAllowed, tab } = useAddFunds();
|
|
31
|
+
const { data: activeWallet } = useWallet();
|
|
32
|
+
return /* @__PURE__ */ jsxs(Container, __spreadProps(__spreadValues({}, contentMotionProps), { children: [
|
|
33
|
+
/* @__PURE__ */ jsx(Heading, { variant: "headingS", weight: "bold", children: "Choose Provider" }),
|
|
34
|
+
/* @__PURE__ */ jsxs($InnerStepContainer, { children: [
|
|
35
|
+
/* @__PURE__ */ jsxs(NoProviders, { isHidden: Object.values(isProviderAllowed).some((v) => !!v), variant: "bodyM", children: [
|
|
36
|
+
"No providers are available for this ",
|
|
37
|
+
hideWallets ? "account" : "wallet"
|
|
38
|
+
] }),
|
|
39
|
+
/* @__PURE__ */ jsx(AnimatePresence, { children: onRampConfig ? onRampConfig.providers.map((id, index) => {
|
|
40
|
+
return isProviderAllowed[id] ? /* @__PURE__ */ jsx(
|
|
41
|
+
motion.div,
|
|
42
|
+
{
|
|
43
|
+
style: { width: "100%" },
|
|
44
|
+
layout: true,
|
|
45
|
+
initial: { opacity: 0, transform: "translateX(25px)" },
|
|
46
|
+
animate: { opacity: 1, transform: "none" },
|
|
47
|
+
exit: { opacity: 0, transform: "translateX(-25px)" },
|
|
48
|
+
transition: { duration: 0.2 },
|
|
49
|
+
children: /* @__PURE__ */ jsx(
|
|
50
|
+
OnRampProviderButton,
|
|
51
|
+
{
|
|
52
|
+
config: onRampConfig,
|
|
53
|
+
index,
|
|
54
|
+
onClick: () => __async(this, null, function* () {
|
|
55
|
+
if (!(activeWallet == null ? void 0 : activeWallet.type)) return;
|
|
56
|
+
const isPopup = id !== OnRampProvider.RAMP;
|
|
57
|
+
const { onRampPurchase: newOnRampPurchase } = yield para.initiateOnRampTransaction({
|
|
58
|
+
walletId: activeWallet.isExternal ? void 0 : activeWallet.id,
|
|
59
|
+
externalWalletAddress: activeWallet.isExternal ? activeWallet.id : void 0,
|
|
60
|
+
shouldOpenPopup: isPopup,
|
|
61
|
+
params: {
|
|
62
|
+
type: tab === EnabledFlow.BUY ? OnRampPurchaseType.BUY : OnRampPurchaseType.SELL,
|
|
63
|
+
walletType: activeWallet.type,
|
|
64
|
+
provider: id,
|
|
65
|
+
network,
|
|
66
|
+
asset,
|
|
67
|
+
fiatQuantity,
|
|
68
|
+
testMode: onRampConfig == null ? void 0 : onRampConfig.testMode
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
setOnRampPurchase(__spreadProps(__spreadValues({}, newOnRampPurchase), { fiat: "USD" }));
|
|
72
|
+
!isPopup && setModalStep(ModalStep.ADD_FUNDS_AWAITING);
|
|
73
|
+
})
|
|
74
|
+
},
|
|
75
|
+
id
|
|
76
|
+
)
|
|
77
|
+
},
|
|
78
|
+
id
|
|
79
|
+
) : null;
|
|
80
|
+
}) : null })
|
|
81
|
+
] })
|
|
82
|
+
] }));
|
|
83
|
+
}
|
|
84
|
+
const Container = safeStyled(motion.div)`
|
|
85
|
+
width: 100%;
|
|
86
|
+
height: 100%;
|
|
87
|
+
align-self: center;
|
|
88
|
+
display: flex;
|
|
89
|
+
flex-direction: column;
|
|
90
|
+
align-items: center;
|
|
91
|
+
gap: 8px;
|
|
92
|
+
height: 320px;
|
|
93
|
+
`;
|
|
94
|
+
const $InnerStepContainer = safeStyled(InnerStepContainer)`
|
|
95
|
+
position: relative;
|
|
96
|
+
`;
|
|
97
|
+
const NoProviders = safeStyled(CpslText)`
|
|
98
|
+
width: 100%;
|
|
99
|
+
text-align: center;
|
|
100
|
+
visibility: ${({ isHidden }) => isHidden ? "hidden" : "visible"};
|
|
101
|
+
position: absolute;
|
|
102
|
+
top: 0;
|
|
103
|
+
left: 0;
|
|
104
|
+
right: 0;
|
|
105
|
+
transition: visibility 0.2s;
|
|
106
|
+
`;
|
|
107
|
+
export {
|
|
108
|
+
AddFundsProvider
|
|
109
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function AddFundsReceive(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "../../../chunk-MMUBH76A.js";
|
|
3
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import {
|
|
5
|
+
CpslButton,
|
|
6
|
+
CpslDivider,
|
|
7
|
+
CpslIcon,
|
|
8
|
+
CpslIdenticon,
|
|
9
|
+
CpslQrCode,
|
|
10
|
+
CpslSpinner,
|
|
11
|
+
CpslText
|
|
12
|
+
} from "@getpara/react-components";
|
|
13
|
+
import { CenteredText, FilledDisabledInput, InnerStepContainer, QRContainer } from "../common.js";
|
|
14
|
+
import { isMobile } from "@getpara/web-sdk";
|
|
15
|
+
import { useModalStore } from "../../stores/index.js";
|
|
16
|
+
import { useStore } from "../../../provider/stores/useStore.js";
|
|
17
|
+
import { useCopyToClipboard } from "@getpara/react-common";
|
|
18
|
+
import { useMemo } from "react";
|
|
19
|
+
import { useWallet } from "../../../provider/hooks/index.js";
|
|
20
|
+
import { useAddFunds } from "./AddFundsContext.js";
|
|
21
|
+
import { formatNetworkList } from "../../utils/stringFormatters.js";
|
|
22
|
+
import { useInternalClient } from "../../../provider/hooks/utils/useInternalClient.js";
|
|
23
|
+
const GENERIC_WALLET = {
|
|
24
|
+
EVM: "Ethereum or EVM-based networks",
|
|
25
|
+
SOLANA: "Solana or SVM-based networks",
|
|
26
|
+
COSMOS: "Cosmos networks"
|
|
27
|
+
};
|
|
28
|
+
function AddFundsReceive() {
|
|
29
|
+
const [isCopied, copy] = useCopyToClipboard();
|
|
30
|
+
const { networks } = useAddFunds();
|
|
31
|
+
const para = useInternalClient();
|
|
32
|
+
const appName = useStore((state) => state.appName);
|
|
33
|
+
const hideWallets = useStore((state) => {
|
|
34
|
+
var _a;
|
|
35
|
+
return (_a = state.modalConfig) == null ? void 0 : _a.hideWallets;
|
|
36
|
+
});
|
|
37
|
+
const onRampConfig = useModalStore((state) => state.onRampConfig);
|
|
38
|
+
const { data: activeWallet } = useWallet();
|
|
39
|
+
const address = useMemo(
|
|
40
|
+
() => activeWallet ? para.getDisplayAddress(activeWallet.id, { addressType: activeWallet.type }) : "",
|
|
41
|
+
[para, activeWallet == null ? void 0 : activeWallet.id, activeWallet == null ? void 0 : activeWallet.type]
|
|
42
|
+
);
|
|
43
|
+
const onCopy = () => {
|
|
44
|
+
copy(address);
|
|
45
|
+
};
|
|
46
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
47
|
+
activeWallet && /* @__PURE__ */ jsx(InnerStepContainer, { children: /* @__PURE__ */ jsxs(
|
|
48
|
+
FilledDisabledInput,
|
|
49
|
+
{
|
|
50
|
+
noAutoDisable: true,
|
|
51
|
+
readonly: true,
|
|
52
|
+
placeholder: para.getDisplayAddress(activeWallet.id, {
|
|
53
|
+
truncate: true,
|
|
54
|
+
addressType: activeWallet.type,
|
|
55
|
+
targetLength: 16
|
|
56
|
+
}),
|
|
57
|
+
children: [
|
|
58
|
+
/* @__PURE__ */ jsx(CpslIdenticon, { slot: "start", size: "32px", hash: para.getIdenticonHash(activeWallet.id, activeWallet.type) }),
|
|
59
|
+
/* @__PURE__ */ jsx(CpslButton, { slot: "end", variant: "ghost", onClick: onCopy, children: /* @__PURE__ */ jsx(CpslIcon, { icon: isCopied ? "check" : "copy" }) })
|
|
60
|
+
]
|
|
61
|
+
},
|
|
62
|
+
address
|
|
63
|
+
) }),
|
|
64
|
+
!isMobile() && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
65
|
+
/* @__PURE__ */ jsx(CpslDivider, { children: "or" }),
|
|
66
|
+
/* @__PURE__ */ jsxs(InnerStepContainer, { children: [
|
|
67
|
+
/* @__PURE__ */ jsx(QRContainer, { children: !address ? /* @__PURE__ */ jsx(CpslSpinner, { size: 100 }) : /* @__PURE__ */ jsx(CpslQrCode, { url: address }, address) }),
|
|
68
|
+
/* @__PURE__ */ jsx(CpslText, { weight: "semiBold", color: "secondary", children: "Scan with your crypto wallet" })
|
|
69
|
+
] })
|
|
70
|
+
] }),
|
|
71
|
+
(activeWallet == null ? void 0 : activeWallet.type) && /* @__PURE__ */ jsxs(InnerStepContainer, { children: [
|
|
72
|
+
/* @__PURE__ */ jsxs(CenteredText, { weight: "semiBold", children: [
|
|
73
|
+
!!(onRampConfig == null ? void 0 : onRampConfig.allowedAssets) && networks.length > 0 || hideWallets ? appName != null ? appName : "This App" : "This Wallet",
|
|
74
|
+
" ",
|
|
75
|
+
"Only Supports:"
|
|
76
|
+
] }),
|
|
77
|
+
/* @__PURE__ */ jsx(CenteredText, { weight: "medium", color: "secondary", children: !!(onRampConfig == null ? void 0 : onRampConfig.allowedAssets) && networks.length > 0 ? formatNetworkList(networks) : GENERIC_WALLET[activeWallet.type] })
|
|
78
|
+
] })
|
|
79
|
+
] });
|
|
80
|
+
}
|
|
81
|
+
export {
|
|
82
|
+
AddFundsReceive
|
|
83
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function AddFundsSettings(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
__spreadProps,
|
|
4
|
+
__spreadValues
|
|
5
|
+
} from "../../../chunk-MMUBH76A.js";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { useEffect, useMemo, useState } from "react";
|
|
8
|
+
import { useAddFunds } from "./AddFundsContext.js";
|
|
9
|
+
import { CpslButton, CpslIcon, CpslInput, CpslRow, CpslText } from "@getpara/react-components";
|
|
10
|
+
import { AssetIcon, HeaderSelect, HeaderSelectContainer, HeaderSelectItem, NetworkIcon } from "../common.js";
|
|
11
|
+
import { getAssetCode, getNetworkName } from "../../constants/constants.js";
|
|
12
|
+
import { EnabledFlow, getOnRampNetworks, OnRampPurchaseType } from "@getpara/web-sdk";
|
|
13
|
+
import { OnRampStep, useModalStore } from "../../stores/index.js";
|
|
14
|
+
import { useStore } from "../../../provider/stores/useStore.js";
|
|
15
|
+
import { safeStyled } from "@getpara/react-common";
|
|
16
|
+
import { contentMotionProps, NoProviders } from "./common.js";
|
|
17
|
+
import { AnimatePresence, motion, useIsPresent } from "framer-motion";
|
|
18
|
+
import { AddFundsAsset } from "./AddFundsAsset.js";
|
|
19
|
+
function NetworkPill({
|
|
20
|
+
network,
|
|
21
|
+
gap = "4px",
|
|
22
|
+
slot,
|
|
23
|
+
start,
|
|
24
|
+
fix = false
|
|
25
|
+
}) {
|
|
26
|
+
return /* @__PURE__ */ jsxs(CpslRow, __spreadProps(__spreadValues({ gap }, slot ? { slot } : {}), { children: [
|
|
27
|
+
start,
|
|
28
|
+
/* @__PURE__ */ jsx(NetworkIcon, { network, size: "24px" }),
|
|
29
|
+
/* @__PURE__ */ jsx(CpslText, { variant: "bodyXS", color: "contrast", style: fix ? { marginRight: "8px" } : void 0, children: getNetworkName(network) })
|
|
30
|
+
] }));
|
|
31
|
+
}
|
|
32
|
+
function AssetPill({ asset, gap = "4px", slot, fix }) {
|
|
33
|
+
if (!asset) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
return /* @__PURE__ */ jsxs(CpslRow, __spreadProps(__spreadValues({ gap }, slot ? { slot } : {}), { children: [
|
|
37
|
+
/* @__PURE__ */ jsx(AssetIcon, { asset, size: "24px" }),
|
|
38
|
+
/* @__PURE__ */ jsx(CpslText, { variant: "bodyXS", color: "contrast", style: fix ? { marginRight: "8px" } : void 0, children: getAssetCode(asset) })
|
|
39
|
+
] }));
|
|
40
|
+
}
|
|
41
|
+
const NetworkLabel = /* @__PURE__ */ jsx(CpslText, { variant: "bodyXS", color: "secondary", style: { margin: "0 8px" }, children: "Network" });
|
|
42
|
+
function AddFundsSettings() {
|
|
43
|
+
const isPresent = useIsPresent();
|
|
44
|
+
const hideWallets = useStore((state) => {
|
|
45
|
+
var _a;
|
|
46
|
+
return (_a = state.modalConfig) == null ? void 0 : _a.hideWallets;
|
|
47
|
+
});
|
|
48
|
+
const setOnRampStep = useModalStore((state) => state.setOnRampStep);
|
|
49
|
+
const {
|
|
50
|
+
assets,
|
|
51
|
+
networks,
|
|
52
|
+
asset,
|
|
53
|
+
setAsset,
|
|
54
|
+
network,
|
|
55
|
+
setNetwork,
|
|
56
|
+
fiatQuantity,
|
|
57
|
+
setFiatQuantity,
|
|
58
|
+
onRampConfig,
|
|
59
|
+
activeWallet,
|
|
60
|
+
isProviderAllowed,
|
|
61
|
+
tab
|
|
62
|
+
} = useAddFunds();
|
|
63
|
+
const [value, setValue] = useState(parseFloat(fiatQuantity || "25.00").toFixed(2));
|
|
64
|
+
const narrowedNetworks = useMemo(() => {
|
|
65
|
+
return !asset ? networks : getOnRampNetworks(onRampConfig.assetInfo, {
|
|
66
|
+
walletType: activeWallet == null ? void 0 : activeWallet.type,
|
|
67
|
+
allowed: onRampConfig.allowedAssets ? Object.entries(onRampConfig.allowedAssets).filter(([_, value2]) => value2 === true || value2.includes(asset)).map(([key]) => key) : void 0,
|
|
68
|
+
assets: [asset],
|
|
69
|
+
providers: onRampConfig.providers,
|
|
70
|
+
action: tab === EnabledFlow.BUY ? OnRampPurchaseType.BUY : OnRampPurchaseType.SELL
|
|
71
|
+
});
|
|
72
|
+
}, [networks, network, asset, activeWallet == null ? void 0 : activeWallet.type, onRampConfig.providers, tab]);
|
|
73
|
+
const content = useMemo(() => {
|
|
74
|
+
if (!!asset && Object.values(isProviderAllowed).every((v) => !v) || assets.length === 0) {
|
|
75
|
+
return /* @__PURE__ */ jsx(Container, __spreadProps(__spreadValues({}, contentMotionProps), { isPresent, children: /* @__PURE__ */ jsxs(NoProviders, { isHidden: Object.values(isProviderAllowed).some((v) => !!v), variant: "bodyM", children: [
|
|
76
|
+
"No providers are available for this ",
|
|
77
|
+
hideWallets ? "account" : "wallet"
|
|
78
|
+
] }) }), "noProviders");
|
|
79
|
+
}
|
|
80
|
+
return !!asset ? /* @__PURE__ */ jsx(Container, __spreadProps(__spreadValues({}, contentMotionProps), { isPresent, children: assets.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
81
|
+
/* @__PURE__ */ jsxs(CpslRow, { children: [
|
|
82
|
+
/* @__PURE__ */ jsx(HeaderSelectContainer, { children: assets.length > 1 ? /* @__PURE__ */ jsxs(
|
|
83
|
+
HeaderSelect,
|
|
84
|
+
{
|
|
85
|
+
selectedValue: asset,
|
|
86
|
+
onCpslSelectValueChange: (e) => {
|
|
87
|
+
setAsset(e.detail);
|
|
88
|
+
},
|
|
89
|
+
showFormattedSelectedItem: true,
|
|
90
|
+
placeholder: "Choose asset...",
|
|
91
|
+
anchorElId: "inputContainer",
|
|
92
|
+
$width: 160,
|
|
93
|
+
autoWidth: true,
|
|
94
|
+
selectedItemVariant: "bodyXS",
|
|
95
|
+
children: [
|
|
96
|
+
asset && /* @__PURE__ */ jsx(AssetPill, { asset, slot: "selected-item" }),
|
|
97
|
+
assets.map((a) => /* @__PURE__ */ jsx(HeaderSelectItem, { slot: "items", value: a, children: /* @__PURE__ */ jsx(AssetPill, { gap: "8px", asset: a }) }, a))
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
) : /* @__PURE__ */ jsx(AssetPill, { asset, fix: true }) }),
|
|
101
|
+
/* @__PURE__ */ jsx(HeaderSelectContainer, { children: narrowedNetworks.length > 1 ? /* @__PURE__ */ jsxs(
|
|
102
|
+
HeaderSelect,
|
|
103
|
+
{
|
|
104
|
+
selectedValue: network,
|
|
105
|
+
onCpslSelectValueChange: (e) => {
|
|
106
|
+
setNetwork(e.detail);
|
|
107
|
+
},
|
|
108
|
+
showFormattedSelectedItem: true,
|
|
109
|
+
placeholder: "Choose network...",
|
|
110
|
+
$width: 160,
|
|
111
|
+
autoWidth: true,
|
|
112
|
+
selectedItemVariant: "bodyXS",
|
|
113
|
+
children: [
|
|
114
|
+
network && /* @__PURE__ */ jsx(NetworkPill, { network, start: NetworkLabel, slot: "selected-item" }),
|
|
115
|
+
narrowedNetworks.map((n) => /* @__PURE__ */ jsx(HeaderSelectItem, { slot: "items", value: n, children: /* @__PURE__ */ jsx(NetworkPill, { gap: "8px", network: n }) }, n))
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
) : network ? /* @__PURE__ */ jsx(NetworkPill, { network, start: NetworkLabel, fix: true }) : null })
|
|
119
|
+
] }),
|
|
120
|
+
/* @__PURE__ */ jsxs(CpslRow, { col: true, gap: "16px", children: [
|
|
121
|
+
/* @__PURE__ */ jsx(
|
|
122
|
+
Input,
|
|
123
|
+
{
|
|
124
|
+
value: value || "",
|
|
125
|
+
fitContent: true,
|
|
126
|
+
autoselect: true,
|
|
127
|
+
onKeyDown: (e) => {
|
|
128
|
+
if (!/^(\d|\.)$/.test(e.key) && !["Delete", "Backspace", "Tab", "Shift"].includes(e.key)) {
|
|
129
|
+
e.preventDefault();
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
onChange: (e) => {
|
|
133
|
+
var _a;
|
|
134
|
+
const numericValue = (((_a = e.currentTarget) == null ? void 0 : _a.value) || "").replace(/[^0-9.]/g, "");
|
|
135
|
+
if (numericValue !== "") {
|
|
136
|
+
const formattedValue = parseFloat(numericValue).toFixed(2);
|
|
137
|
+
setValue(formattedValue);
|
|
138
|
+
} else {
|
|
139
|
+
setValue(null);
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
onBlur: (e) => {
|
|
143
|
+
const numericValue = (e.currentTarget.value || "").replace(/[^0-9.]/g, "");
|
|
144
|
+
if (numericValue === "") {
|
|
145
|
+
setValue(null);
|
|
146
|
+
} else {
|
|
147
|
+
setValue(parseFloat(numericValue).toFixed(2));
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
placeholder: "0",
|
|
151
|
+
children: /* @__PURE__ */ jsx(CurrencySign, { slot: "start", children: "$" })
|
|
152
|
+
},
|
|
153
|
+
value || ""
|
|
154
|
+
),
|
|
155
|
+
/* @__PURE__ */ jsx(CpslRow, { style: { width: "100%" }, children: ["25", "50", "100"].map((quantity) => {
|
|
156
|
+
return /* @__PURE__ */ jsxs(PresetButton, { fullWidth: true, variant: "secondary", onClick: () => setValue(`${quantity}.00`), children: [
|
|
157
|
+
"$",
|
|
158
|
+
quantity
|
|
159
|
+
] }, quantity);
|
|
160
|
+
}) })
|
|
161
|
+
] }),
|
|
162
|
+
/* @__PURE__ */ jsxs(
|
|
163
|
+
CpslButton,
|
|
164
|
+
{
|
|
165
|
+
fullWidth: true,
|
|
166
|
+
disabled: value === "",
|
|
167
|
+
onClick: () => {
|
|
168
|
+
setFiatQuantity(value != null ? value : void 0);
|
|
169
|
+
setOnRampStep(OnRampStep.PROVIDER);
|
|
170
|
+
},
|
|
171
|
+
children: [
|
|
172
|
+
"Continue",
|
|
173
|
+
/* @__PURE__ */ jsx(CpslIcon, { icon: "arrow" })
|
|
174
|
+
]
|
|
175
|
+
}
|
|
176
|
+
)
|
|
177
|
+
] }) }), "quantity") : /* @__PURE__ */ jsx(AssetContainer, __spreadProps(__spreadValues({}, contentMotionProps), { isPresent, children: /* @__PURE__ */ jsx(AddFundsAsset, {}) }), "asset");
|
|
178
|
+
}, [asset, network, assets, narrowedNetworks, isProviderAllowed, isPresent, value]);
|
|
179
|
+
useEffect(() => {
|
|
180
|
+
if (!network || !narrowedNetworks.includes(network)) {
|
|
181
|
+
setNetwork(narrowedNetworks[0]);
|
|
182
|
+
}
|
|
183
|
+
}, [narrowedNetworks, network, tab]);
|
|
184
|
+
useEffect(() => {
|
|
185
|
+
if (!!asset && !assets.includes(asset)) {
|
|
186
|
+
setAsset(assets[0]);
|
|
187
|
+
}
|
|
188
|
+
}, [assets, asset, tab]);
|
|
189
|
+
return /* @__PURE__ */ jsx(AnimatePresence, { mode: "wait", children: content });
|
|
190
|
+
}
|
|
191
|
+
const Container = safeStyled(motion.div)`
|
|
192
|
+
width: 100%;
|
|
193
|
+
height: 100%;
|
|
194
|
+
align-self: center;
|
|
195
|
+
display: flex;
|
|
196
|
+
flex-direction: column;
|
|
197
|
+
align-items: center;
|
|
198
|
+
gap: 32px;
|
|
199
|
+
position: relative;
|
|
200
|
+
height: 320px;
|
|
201
|
+
${({ isPresent }) => isPresent ? "transform: none !important;" : ""};
|
|
202
|
+
|
|
203
|
+
& > * {
|
|
204
|
+
width: 100%;
|
|
205
|
+
}
|
|
206
|
+
`;
|
|
207
|
+
const AssetContainer = safeStyled(Container)`
|
|
208
|
+
gap: 8px;
|
|
209
|
+
`;
|
|
210
|
+
const CurrencySign = safeStyled.div`
|
|
211
|
+
font-size: 72px;
|
|
212
|
+
color: var(--cpsl-color-text-primary);
|
|
213
|
+
position: relative;
|
|
214
|
+
right: -16px;
|
|
215
|
+
`;
|
|
216
|
+
const PresetButton = safeStyled(CpslButton)`
|
|
217
|
+
--button-color: var(--cpsl-color-text-contrast);
|
|
218
|
+
--button-font-size: 24px;
|
|
219
|
+
--button-secondary-background-color: var(--cpsl-color-background-8);
|
|
220
|
+
--button-secondary-border-color: var(--cpsl-color-background-8);
|
|
221
|
+
--button-secondary-hover-color: var(--cpsl-color-text-contrast);
|
|
222
|
+
--button-secondary-hover-background-color: var(--cpsl-color-background-16);
|
|
223
|
+
--button-secondary-hover-border-color: var(--cpsl-color-background-16);
|
|
224
|
+
flex: 1;
|
|
225
|
+
`;
|
|
226
|
+
const Input = safeStyled(CpslInput)`
|
|
227
|
+
--container-background-color: transparent;
|
|
228
|
+
--container-height: 90px;
|
|
229
|
+
--container-border-width: 0;
|
|
230
|
+
--input-background-color: transparent;
|
|
231
|
+
--input-font-size: 72px;
|
|
232
|
+
--input-text-align: center;
|
|
233
|
+
--input-width: 100%;
|
|
234
|
+
`;
|
|
235
|
+
export {
|
|
236
|
+
AddFundsSettings
|
|
237
|
+
};
|