@getpara/react-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4 -0
- package/dist/modal/ParaModal.d.ts +2 -0
- package/dist/modal/ParaModal.js +250 -0
- package/dist/modal/components/Account/Account.d.ts +5 -0
- package/dist/modal/components/Account/Account.js +59 -0
- package/dist/modal/components/AddFunds/AddFunds.d.ts +3 -0
- package/dist/modal/components/AddFunds/AddFunds.js +146 -0
- package/dist/modal/components/AddFunds/AddFundsAwaiting.d.ts +1 -0
- package/dist/modal/components/AddFunds/AddFundsAwaiting.js +64 -0
- package/dist/modal/components/AddFunds/AddFundsDone.d.ts +6 -0
- package/dist/modal/components/AddFunds/AddFundsDone.js +26 -0
- package/dist/modal/components/AddFunds/MoonPayEmbed.d.ts +2 -0
- package/dist/modal/components/AddFunds/MoonPayEmbed.js +2 -0
- package/dist/modal/components/AddFunds/index.d.ts +3 -0
- package/dist/modal/components/AddFunds/index.js +3 -0
- package/dist/modal/components/AuthInput/AuthInput.d.ts +6 -0
- package/dist/modal/components/AuthInput/AuthInput.js +214 -0
- package/dist/modal/components/AuthInput/countryCodes.d.ts +8 -0
- package/dist/modal/components/AuthInput/countryCodes.js +40 -0
- package/dist/modal/components/AuthInput/hooks/useDropdownPosition.d.ts +7 -0
- package/dist/modal/components/AuthInput/hooks/useDropdownPosition.js +23 -0
- package/dist/modal/components/AuthInput/phoneMasks.d.ts +247 -0
- package/dist/modal/components/AuthInput/phoneMasks.js +247 -0
- package/dist/modal/components/AuthMainStep/AuthMainStep.d.ts +8 -0
- package/dist/modal/components/AuthMainStep/AuthMainStep.js +21 -0
- package/dist/modal/components/AuthMainStep/AuthMainStepContent.d.ts +8 -0
- package/dist/modal/components/AuthMainStep/AuthMainStepContent.js +89 -0
- package/dist/modal/components/AuthOptions/AuthOptions.d.ts +8 -0
- package/dist/modal/components/AuthOptions/AuthOptions.js +28 -0
- package/dist/modal/components/AwaitingBiometricsStep/AwaitingBiometricsStep.d.ts +1 -0
- package/dist/modal/components/AwaitingBiometricsStep/AwaitingBiometricsStep.js +7 -0
- package/dist/modal/components/AwaitingOAuthStep/AwaitingOAuthStep.d.ts +1 -0
- package/dist/modal/components/AwaitingOAuthStep/AwaitingOAuthStep.js +5 -0
- package/dist/modal/components/AwaitingPasswordStep/AwaitingPasswordStep.d.ts +1 -0
- package/dist/modal/components/AwaitingPasswordStep/AwaitingPasswordStep.js +7 -0
- package/dist/modal/components/AwaitingWalletCreationStep/AwaitingWalletCreationStep.d.ts +1 -0
- package/dist/modal/components/AwaitingWalletCreationStep/AwaitingWalletCreationStep.js +18 -0
- package/dist/modal/components/BiometricCreationStep/BiometricCreationStep.d.ts +4 -0
- package/dist/modal/components/BiometricCreationStep/BiometricCreationStep.js +17 -0
- package/dist/modal/components/BiometricLoginStep/BiometricLoginStep.d.ts +1 -0
- package/dist/modal/components/BiometricLoginStep/BiometricLoginStep.js +127 -0
- package/dist/modal/components/Body/AnimatedHeightWrapper.d.ts +6 -0
- package/dist/modal/components/Body/AnimatedHeightWrapper.js +26 -0
- package/dist/modal/components/Body/Body.d.ts +12 -0
- package/dist/modal/components/Body/Body.js +232 -0
- package/dist/modal/components/ChainSwitch/ChainSwitch.d.ts +1 -0
- package/dist/modal/components/ChainSwitch/ChainSwitch.js +77 -0
- package/dist/modal/components/ChainSwitch/config.d.ts +7 -0
- package/dist/modal/components/ChainSwitch/config.js +11 -0
- package/dist/modal/components/Controls/Controls.d.ts +5 -0
- package/dist/modal/components/Controls/Controls.js +54 -0
- package/dist/modal/components/Controls/Selects.d.ts +2 -0
- package/dist/modal/components/Controls/Selects.js +157 -0
- package/dist/modal/components/ExternalWalletStep/ExternalWalletStep.d.ts +1 -0
- package/dist/modal/components/ExternalWalletStep/ExternalWalletStep.js +116 -0
- package/dist/modal/components/ExternalWalletStep/config.d.ts +7 -0
- package/dist/modal/components/ExternalWalletStep/config.js +11 -0
- package/dist/modal/components/ExternalWallets/ExternalWallets.d.ts +1 -0
- package/dist/modal/components/ExternalWallets/ExternalWallets.js +142 -0
- package/dist/modal/components/ExternalWalletsWrapper/ExternalWalletsWrapper.d.ts +7 -0
- package/dist/modal/components/ExternalWalletsWrapper/ExternalWalletsWrapper.js +118 -0
- package/dist/modal/components/Footer/Footer.d.ts +1 -0
- package/dist/modal/components/Footer/Footer.js +71 -0
- package/dist/modal/components/Header/Header.d.ts +1 -0
- package/dist/modal/components/Header/Header.js +24 -0
- package/dist/modal/components/Header/hooks/useStepTitle.d.ts +3 -0
- package/dist/modal/components/Header/hooks/useStepTitle.js +42 -0
- package/dist/modal/components/Hero/Hero.d.ts +1 -0
- package/dist/modal/components/Hero/Hero.js +118 -0
- package/dist/modal/components/IFrameStep/IFrameStep.d.ts +1 -0
- package/dist/modal/components/IFrameStep/IFrameStep.js +41 -0
- package/dist/modal/components/LoginDoneStep/LoginDoneStep.d.ts +1 -0
- package/dist/modal/components/LoginDoneStep/LoginDoneStep.js +18 -0
- package/dist/modal/components/ModalContent/ModalContent.d.ts +10 -0
- package/dist/modal/components/ModalContent/ModalContent.js +276 -0
- package/dist/modal/components/OAuth/FarcasterOAuthStep.d.ts +2 -0
- package/dist/modal/components/OAuth/FarcasterOAuthStep.js +81 -0
- package/dist/modal/components/OAuth/OAuth.d.ts +6 -0
- package/dist/modal/components/OAuth/OAuth.js +124 -0
- package/dist/modal/components/OAuth/TelegramOAuthStep.d.ts +1 -0
- package/dist/modal/components/OAuth/TelegramOAuthStep.js +132 -0
- package/dist/modal/components/OnRampComponents/AddingFunds.d.ts +1 -0
- package/dist/modal/components/OnRampComponents/AddingFunds.js +10 -0
- package/dist/modal/components/OnRampComponents/OnRampProviderButton.d.ts +9 -0
- package/dist/modal/components/OnRampComponents/OnRampProviderButton.js +72 -0
- package/dist/modal/components/RecoverySecretStep/RecoverySecretStep.d.ts +6 -0
- package/dist/modal/components/RecoverySecretStep/RecoverySecretStep.js +67 -0
- package/dist/modal/components/Setup2FAStep/Setup2FAStep.d.ts +5 -0
- package/dist/modal/components/Setup2FAStep/Setup2FAStep.js +104 -0
- package/dist/modal/components/StripeComponents/StripeComponents.d.ts +16 -0
- package/dist/modal/components/StripeComponents/StripeComponents.js +78 -0
- package/dist/modal/components/TwoFactorDoneStep/TwoFactorDoneStep.d.ts +5 -0
- package/dist/modal/components/TwoFactorDoneStep/TwoFactorDoneStep.js +8 -0
- package/dist/modal/components/VerificationCodeStep/VerificationCodeStep.d.ts +1 -0
- package/dist/modal/components/VerificationCodeStep/VerificationCodeStep.js +130 -0
- package/dist/modal/components/Waiting/Waiting.d.ts +6 -0
- package/dist/modal/components/Waiting/Waiting.js +6 -0
- package/dist/modal/components/WalletCard/PartnerIcon.d.ts +6 -0
- package/dist/modal/components/WalletCard/PartnerIcon.js +29 -0
- package/dist/modal/components/WalletCard/WalletCard.d.ts +18 -0
- package/dist/modal/components/WalletCard/WalletCard.js +91 -0
- package/dist/modal/components/WalletCreationDoneStep/WalletCreationDoneStep.d.ts +6 -0
- package/dist/modal/components/WalletCreationDoneStep/WalletCreationDoneStep.js +49 -0
- package/dist/modal/components/common.d.ts +19 -0
- package/dist/modal/components/common.js +67 -0
- package/dist/modal/components/index.d.ts +1 -0
- package/dist/modal/components/index.js +1 -0
- package/dist/modal/constants/constants.d.ts +32 -0
- package/dist/modal/constants/constants.js +93 -0
- package/dist/modal/constants/defaults.d.ts +5 -0
- package/dist/modal/constants/defaults.js +5 -0
- package/dist/modal/constants/oAuthLogos.d.ts +8 -0
- package/dist/modal/constants/oAuthLogos.js +18 -0
- package/dist/modal/css/modal.css +13 -0
- package/dist/modal/hooks/useActiveWallet.d.ts +1 -0
- package/dist/modal/hooks/useActiveWallet.js +9 -0
- package/dist/modal/hooks/useEmbeddedExternalConnection.d.ts +1 -0
- package/dist/modal/hooks/useEmbeddedExternalConnection.js +46 -0
- package/dist/modal/hooks/useGoBack.d.ts +1 -0
- package/dist/modal/hooks/useGoBack.js +34 -0
- package/dist/modal/index.d.ts +10 -0
- package/dist/modal/index.js +9 -0
- package/dist/modal/providers/CosmosExternalWalletContextStub.d.ts +29 -0
- package/dist/modal/providers/CosmosExternalWalletContextStub.js +18 -0
- package/dist/modal/providers/EvmExternalWalletContextStub.d.ts +33 -0
- package/dist/modal/providers/EvmExternalWalletContextStub.js +22 -0
- package/dist/modal/providers/ExternalWalletContext.d.ts +75 -0
- package/dist/modal/providers/ExternalWalletContext.js +252 -0
- package/dist/modal/providers/SolanaExternalWalletContextStub.d.ts +21 -0
- package/dist/modal/providers/SolanaExternalWalletContextStub.js +12 -0
- package/dist/modal/public/Inter-VariableFont_slnt,wght.ttf +0 -0
- package/dist/modal/stores/externalWalletProvider/actions.d.ts +3 -0
- package/dist/modal/stores/externalWalletProvider/actions.js +5 -0
- package/dist/modal/stores/externalWalletProvider/useExternalWalletProviderStore.d.ts +20 -0
- package/dist/modal/stores/externalWalletProvider/useExternalWalletProviderStore.js +13 -0
- package/dist/modal/stores/index.d.ts +4 -0
- package/dist/modal/stores/index.js +4 -0
- package/dist/modal/stores/modal/actions.d.ts +3 -0
- package/dist/modal/stores/modal/actions.js +65 -0
- package/dist/modal/stores/modal/useModalStore.d.ts +82 -0
- package/dist/modal/stores/modal/useModalStore.js +41 -0
- package/dist/modal/stores/para/actions.d.ts +3 -0
- package/dist/modal/stores/para/actions.js +5 -0
- package/dist/modal/stores/para/useParaStore.d.ts +10 -0
- package/dist/modal/stores/para/useParaStore.js +3 -0
- package/dist/modal/stores/theme/actions.d.ts +3 -0
- package/dist/modal/stores/theme/actions.js +24 -0
- package/dist/modal/stores/theme/useThemeStore.d.ts +20 -0
- package/dist/modal/stores/theme/useThemeStore.js +14 -0
- package/dist/modal/stores/userInfo/actions.d.ts +3 -0
- package/dist/modal/stores/userInfo/actions.js +28 -0
- package/dist/modal/stores/userInfo/useUserInfoStore.d.ts +19 -0
- package/dist/modal/stores/userInfo/useUserInfoStore.js +9 -0
- package/dist/modal/types/commonTypes.d.ts +48 -0
- package/dist/modal/types/commonTypes.js +1 -0
- package/dist/modal/types/externalWallets.d.ts +31 -0
- package/dist/modal/types/externalWallets.js +21 -0
- package/dist/modal/types/modalProps.d.ts +138 -0
- package/dist/modal/types/modalProps.js +7 -0
- package/dist/modal/utils/authLayoutHelpers.d.ts +3 -0
- package/dist/modal/utils/authLayoutHelpers.js +2 -0
- package/dist/modal/utils/getMailtoLink.d.ts +1 -0
- package/dist/modal/utils/getMailtoLink.js +5 -0
- package/dist/modal/utils/getTileButtonFlex.d.ts +1 -0
- package/dist/modal/utils/getTileButtonFlex.js +15 -0
- package/dist/modal/utils/isPasskeySupported.d.ts +1 -0
- package/dist/modal/utils/isPasskeySupported.js +10 -0
- package/dist/modal/utils/openPopup.d.ts +1 -0
- package/dist/modal/utils/openPopup.js +55 -0
- package/dist/modal/utils/routeMobileExternalWallet.d.ts +1 -0
- package/dist/modal/utils/routeMobileExternalWallet.js +35 -0
- package/dist/modal/utils/steps.d.ts +112 -0
- package/dist/modal/utils/steps.js +215 -0
- package/dist/modal/utils/stringFormatters.d.ts +4 -0
- package/dist/modal/utils/stringFormatters.js +12 -0
- package/dist/modal/utils/validateOnRampConfig.d.ts +5 -0
- package/dist/modal/utils/validateOnRampConfig.js +26 -0
- package/package.json +51 -0
- package/styles.css/package.json +3 -0
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
22
|
+
import { CpslAuthModal, defineCustomElements, generateTheme } from '@getpara/react-components';
|
|
23
|
+
import { ModalContent } from './components/index.js';
|
|
24
|
+
import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';
|
|
25
|
+
import { useParaStore, useModalStore, useUserInfoStore, useThemeStore } from './stores/index.js';
|
|
26
|
+
import { ModalStep, RESET_TO_ACCOUNT_STEPS, RESET_TO_AUTH_STEPS } from './utils/steps.js';
|
|
27
|
+
import { AuthLayout } from './types/modalProps.js';
|
|
28
|
+
import { DEFAULTS } from './constants/defaults.js';
|
|
29
|
+
import { useGoBack } from './hooks/useGoBack.js';
|
|
30
|
+
import { CURRENT_WALLET_IDS_CHANGE_EVENT, EXTERNAL_WALLET_CHANGE_EVENT } from '@getpara/web-sdk';
|
|
31
|
+
import { ExternalWalletsWrapper } from './components/ExternalWalletsWrapper/ExternalWalletsWrapper.js';
|
|
32
|
+
import styled from 'styled-components';
|
|
33
|
+
import { useExternalWallets } from './providers/ExternalWalletContext.js';
|
|
34
|
+
import { hasEmbeddedAuth, hasExternalWallet } from './utils/authLayoutHelpers.js';
|
|
35
|
+
defineCustomElements();
|
|
36
|
+
export const ParaModal = forwardRef((_a, ref) => {
|
|
37
|
+
var { para: _para, isOpen, theme, appName, logo, disableEmailLogin = false, disablePhoneLogin = false, oAuthMethods, bareModal = false, className, currentStepOverride, externalWallets, authLayout = [AuthLayout.AUTH_FULL, AuthLayout.EXTERNAL_FULL], embeddedModal, onModalStepChange, hideWallets = false, onClose } = _a, rest = __rest(_a, ["para", "isOpen", "theme", "appName", "logo", "disableEmailLogin", "disablePhoneLogin", "oAuthMethods", "bareModal", "className", "currentStepOverride", "externalWallets", "authLayout", "embeddedModal", "onModalStepChange", "hideWallets", "onClose"]);
|
|
38
|
+
const para = _para;
|
|
39
|
+
const modalContentRef = useRef(null);
|
|
40
|
+
const updateThemeState = useThemeStore(state => state.updateState);
|
|
41
|
+
const setWebAuthURLForLogin = useModalStore(state => state.setWebAuthURLForLogin);
|
|
42
|
+
const setWebAuthURLForCreate = useModalStore(state => state.setWebAuthURLForCreate);
|
|
43
|
+
const setBiometricLocationHints = useModalStore(state => state.setBiometricLocationHints);
|
|
44
|
+
const currentStep = useModalStore(state => state.step);
|
|
45
|
+
const setOnModalStepChange = useModalStore(state => state.setOnModalStepChange);
|
|
46
|
+
const setStep = useModalStore(state => state.setStep);
|
|
47
|
+
const setPara = useParaStore(state => state.setPara);
|
|
48
|
+
const setAuthInfo = useUserInfoStore(state => state.setAuthInfo);
|
|
49
|
+
const hasPreviousStep = useModalStore(state => state.hasPreviousStep());
|
|
50
|
+
const setFlow = useModalStore(state => state.setFlow);
|
|
51
|
+
const setIsFullyLoggedIn = useModalStore(state => state.setIsFullyLoggedIn);
|
|
52
|
+
const goBack = useGoBack();
|
|
53
|
+
const setAuthLayout = useThemeStore(state => state.setAuthLayout);
|
|
54
|
+
const storedAuthLayout = useThemeStore(state => state.authLayout);
|
|
55
|
+
const resetModalState = useModalStore(state => state.resetState);
|
|
56
|
+
const resetUserInfoState = useUserInfoStore(state => state.resetState);
|
|
57
|
+
const setRecoveryShare = useUserInfoStore(state => state.setRecoveryShare);
|
|
58
|
+
const [activeWallet, setActiveWallet] = useModalStore(state => [state.activeWallet, state.setActiveWallet]);
|
|
59
|
+
const { disconnectExternalWallet } = useExternalWallets();
|
|
60
|
+
const [isModalMounted, setIsModalMounted] = useState(false);
|
|
61
|
+
const [isInit, setIsInit] = useState(false);
|
|
62
|
+
useImperativeHandle(ref, () => {
|
|
63
|
+
return {
|
|
64
|
+
goBack() {
|
|
65
|
+
goBack();
|
|
66
|
+
},
|
|
67
|
+
canGoBack() {
|
|
68
|
+
return hasPreviousStep;
|
|
69
|
+
},
|
|
70
|
+
currentStep() {
|
|
71
|
+
return currentStep;
|
|
72
|
+
},
|
|
73
|
+
handleModalClose() {
|
|
74
|
+
var _a;
|
|
75
|
+
(_a = modalContentRef === null || modalContentRef === void 0 ? void 0 : modalContentRef.current) === null || _a === void 0 ? void 0 : _a.handleModalClose();
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}, [hasPreviousStep, currentStep]);
|
|
79
|
+
// This will run on mount and on isOpen change but won't cause a rerender unless step or email changes
|
|
80
|
+
const initModal = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
81
|
+
const isAccount = yield para.isFullyLoggedIn();
|
|
82
|
+
if (currentStepOverride) {
|
|
83
|
+
setStep(ModalStep[currentStepOverride.toUpperCase()]);
|
|
84
|
+
}
|
|
85
|
+
else if (isAccount) {
|
|
86
|
+
setFlow('account');
|
|
87
|
+
setStep(ModalStep.ACCOUNT_MAIN);
|
|
88
|
+
setIsFullyLoggedIn(true);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
if (currentStep !== ModalStep.AUTH_MAIN && currentStep !== ModalStep.SECRET) {
|
|
92
|
+
setStep(ModalStep.AUTH_MAIN);
|
|
93
|
+
setFlow();
|
|
94
|
+
setWebAuthURLForLogin();
|
|
95
|
+
setWebAuthURLForCreate();
|
|
96
|
+
setBiometricLocationHints();
|
|
97
|
+
}
|
|
98
|
+
// Disconnect external wallets if the user is not longer logged in
|
|
99
|
+
yield disconnectExternalWallet();
|
|
100
|
+
setActiveWallet([undefined, undefined]);
|
|
101
|
+
setIsFullyLoggedIn(false);
|
|
102
|
+
}
|
|
103
|
+
switch (true) {
|
|
104
|
+
case para.isEmail:
|
|
105
|
+
setAuthInfo({ email: para.getEmail() });
|
|
106
|
+
break;
|
|
107
|
+
case para.isPhone:
|
|
108
|
+
{
|
|
109
|
+
const { phone, countryCode } = para.getPhone();
|
|
110
|
+
setAuthInfo({ phone, countryCode: countryCode });
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
case para.isFarcaster:
|
|
114
|
+
setAuthInfo({ farcasterUsername: para.getFarcasterUsername() });
|
|
115
|
+
break;
|
|
116
|
+
case para.isTelegram:
|
|
117
|
+
setAuthInfo({ telegramUserId: para.telegramUserId });
|
|
118
|
+
if (!isAccount) {
|
|
119
|
+
setStep(ModalStep.TELEGRAM_OAUTH);
|
|
120
|
+
}
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
setIsInit(true);
|
|
124
|
+
});
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
let _authLayout = authLayout;
|
|
127
|
+
// Removing unused auth layouts based on what auth methods are passed in
|
|
128
|
+
if (!(externalWallets === null || externalWallets === void 0 ? void 0 : externalWallets.length) && hasExternalWallet(authLayout)) {
|
|
129
|
+
_authLayout = _authLayout.filter(l => !l.includes('EXTERNAL'));
|
|
130
|
+
}
|
|
131
|
+
if (disableEmailLogin && disablePhoneLogin && !(oAuthMethods === null || oAuthMethods === void 0 ? void 0 : oAuthMethods.length) && hasEmbeddedAuth(authLayout)) {
|
|
132
|
+
_authLayout = _authLayout.filter(l => !l.includes('AUTH'));
|
|
133
|
+
}
|
|
134
|
+
if (JSON.stringify(storedAuthLayout) !== JSON.stringify(_authLayout)) {
|
|
135
|
+
setAuthLayout(_authLayout);
|
|
136
|
+
}
|
|
137
|
+
}, [disableEmailLogin, disablePhoneLogin, oAuthMethods, externalWallets, authLayout]);
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
setOnModalStepChange(onModalStepChange);
|
|
140
|
+
}, [onModalStepChange]);
|
|
141
|
+
useEffect(() => {
|
|
142
|
+
var _a;
|
|
143
|
+
updateThemeState({
|
|
144
|
+
logo,
|
|
145
|
+
appName,
|
|
146
|
+
oAuthLogoVariant: (_a = theme === null || theme === void 0 ? void 0 : theme.oAuthLogoVariant) !== null && _a !== void 0 ? _a : 'default',
|
|
147
|
+
bareModal,
|
|
148
|
+
embeddedModal,
|
|
149
|
+
hideWallets,
|
|
150
|
+
});
|
|
151
|
+
}, [logo, appName, theme === null || theme === void 0 ? void 0 : theme.oAuthLogoVariant, bareModal, embeddedModal, hideWallets]);
|
|
152
|
+
useEffect(() => {
|
|
153
|
+
if (theme) {
|
|
154
|
+
generateTheme(theme);
|
|
155
|
+
updateThemeState({ isDark: theme.mode === 'dark', theme: theme });
|
|
156
|
+
}
|
|
157
|
+
}, [theme]);
|
|
158
|
+
// Set Para instance & init on mount
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
if (para) {
|
|
161
|
+
initModal();
|
|
162
|
+
setPara(para);
|
|
163
|
+
if (bareModal) {
|
|
164
|
+
setIsModalMounted(true);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
console.error('A Para instance must be provided.');
|
|
169
|
+
}
|
|
170
|
+
}, []);
|
|
171
|
+
// Init modal with proper steps on isOpen change
|
|
172
|
+
useEffect(() => {
|
|
173
|
+
if (isOpen && para) {
|
|
174
|
+
initModal();
|
|
175
|
+
}
|
|
176
|
+
}, [isOpen]);
|
|
177
|
+
const updateActiveWallet = () => {
|
|
178
|
+
if (!activeWallet[0] || !para.findWallet(activeWallet[0])) {
|
|
179
|
+
const defaultWallet = para.findWallet(undefined, undefined, { forbidPregen: true });
|
|
180
|
+
defaultWallet && setActiveWallet([defaultWallet.id, defaultWallet.type]);
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
useEffect(() => {
|
|
184
|
+
setPara(para);
|
|
185
|
+
updateActiveWallet();
|
|
186
|
+
}, [para]);
|
|
187
|
+
useEffect(() => {
|
|
188
|
+
window.addEventListener(CURRENT_WALLET_IDS_CHANGE_EVENT, updateActiveWallet);
|
|
189
|
+
window.addEventListener(EXTERNAL_WALLET_CHANGE_EVENT, updateActiveWallet);
|
|
190
|
+
return () => {
|
|
191
|
+
window.removeEventListener(CURRENT_WALLET_IDS_CHANGE_EVENT, updateActiveWallet);
|
|
192
|
+
window.removeEventListener(EXTERNAL_WALLET_CHANGE_EVENT, updateActiveWallet);
|
|
193
|
+
};
|
|
194
|
+
}, []);
|
|
195
|
+
const handleModalEntering = () => {
|
|
196
|
+
setIsModalMounted(true);
|
|
197
|
+
};
|
|
198
|
+
const handleModalExited = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
199
|
+
setIsModalMounted(false);
|
|
200
|
+
if (RESET_TO_AUTH_STEPS.includes(currentStep)) {
|
|
201
|
+
resetModalState();
|
|
202
|
+
resetUserInfoState();
|
|
203
|
+
setRecoveryShare(null);
|
|
204
|
+
}
|
|
205
|
+
else if (RESET_TO_ACCOUNT_STEPS.includes(currentStep)) {
|
|
206
|
+
setStep(ModalStep.LOGIN_DONE);
|
|
207
|
+
}
|
|
208
|
+
if (para) {
|
|
209
|
+
yield initModal();
|
|
210
|
+
para.exitLoops();
|
|
211
|
+
}
|
|
212
|
+
setIsInit(false);
|
|
213
|
+
});
|
|
214
|
+
if (!para) {
|
|
215
|
+
console.error('A Para instance is required.');
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
if (!(storedAuthLayout === null || storedAuthLayout === void 0 ? void 0 : storedAuthLayout.length)) {
|
|
219
|
+
// Checking props here to verify a valid configuration was passed in.
|
|
220
|
+
// Doing this since we auto adjust the auth layouts based on passed in auth method props, if an empty storedAuthLayout was triggered based on invalid props we want to be sure the message reflects that correctly.
|
|
221
|
+
const hasExternalWalletError = !(externalWallets === null || externalWallets === void 0 ? void 0 : externalWallets.length) && hasExternalWallet(authLayout);
|
|
222
|
+
const hasEmbeddedWalletError = disableEmailLogin && disablePhoneLogin && !(oAuthMethods === null || oAuthMethods === void 0 ? void 0 : oAuthMethods.length) && hasEmbeddedAuth(authLayout);
|
|
223
|
+
if (hasExternalWalletError || hasEmbeddedWalletError) {
|
|
224
|
+
if (hasExternalWalletError) {
|
|
225
|
+
console.error('At least one external wallet must be provided if external wallet auth is enabled.');
|
|
226
|
+
}
|
|
227
|
+
if (hasEmbeddedWalletError) {
|
|
228
|
+
console.error('At least one login method (email, phone or OAuth) must be provided if embedded wallet auth is enabled.');
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
console.error('At least one auth layout selection is required.');
|
|
233
|
+
}
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
return (_jsx(ExternalWalletsWrapper, { wallets: externalWallets, children: _jsx(StyledAuthModal, { enterTransitionDuration: DEFAULTS.ANIMATION_DURATION, exitTransitionDuration: DEFAULTS.ANIMATION_DURATION, open: isOpen, onCpslModalExited: handleModalExited, onCpslModalEntering: handleModalEntering, onCpslModalRequestClose: onClose, noOverlay: bareModal, className: className, "data-testid": "modal", "$embeddedModal": embeddedModal, children: isModalMounted && ((isInit && embeddedModal) || !embeddedModal) && (_jsx(ModalContent, Object.assign({ oAuthMethods: oAuthMethods, disableEmailLogin: disableEmailLogin, disablePhoneLogin: disablePhoneLogin, onClose: onClose }, rest))) }) }));
|
|
237
|
+
});
|
|
238
|
+
const StyledAuthModal = styled(CpslAuthModal) `
|
|
239
|
+
${({ $embeddedModal }) => $embeddedModal &&
|
|
240
|
+
`
|
|
241
|
+
&::part(modal-body-card) {
|
|
242
|
+
--card-box-shadow: none;
|
|
243
|
+
--card-border-width: 0px;
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
&::part(modal-footer) {
|
|
247
|
+
--card-box-shadow: none;
|
|
248
|
+
--card-border-width: 0px;
|
|
249
|
+
};`}
|
|
250
|
+
`;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
import styled from 'styled-components';
|
|
12
|
+
import { InnerStepContainer, StepContainer, StyledCpslTileButton } from '../common.js';
|
|
13
|
+
import { CpslButton, CpslIcon, CpslSpinner, CpslText } from '@getpara/react-components';
|
|
14
|
+
import { useParaStore, useModalStore, useThemeStore } from '../../stores/index.js';
|
|
15
|
+
import { useExternalWallets } from '../../providers/ExternalWalletContext.js';
|
|
16
|
+
import { useState } from 'react';
|
|
17
|
+
import { ModalStep } from '../../utils/steps.js';
|
|
18
|
+
export const Account = ({ onClose }) => {
|
|
19
|
+
const onRampConfig = useModalStore(state => state.onRampConfig);
|
|
20
|
+
const setStep = useModalStore(state => state.setStep);
|
|
21
|
+
const para = useParaStore(state => state.para);
|
|
22
|
+
const hideWallets = useThemeStore(state => state.hideWallets);
|
|
23
|
+
const { disconnectExternalWallet } = useExternalWallets();
|
|
24
|
+
const [isDisconnecting, setIsDisconnecting] = useState(false);
|
|
25
|
+
const isOnRampLoaded = !!onRampConfig;
|
|
26
|
+
const handleBuyClick = () => {
|
|
27
|
+
setStep(ModalStep.ADD_FUNDS_BUY);
|
|
28
|
+
};
|
|
29
|
+
const handleReceiveClick = () => {
|
|
30
|
+
setStep(ModalStep.ADD_FUNDS_RECEIVE);
|
|
31
|
+
};
|
|
32
|
+
const handleSellClick = () => {
|
|
33
|
+
setStep(ModalStep.ADD_FUNDS_WITHDRAW);
|
|
34
|
+
};
|
|
35
|
+
const handleDisconnectClick = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
setIsDisconnecting(true);
|
|
37
|
+
yield para.logout();
|
|
38
|
+
yield disconnectExternalWallet();
|
|
39
|
+
onClose();
|
|
40
|
+
setIsDisconnecting(false);
|
|
41
|
+
});
|
|
42
|
+
return (_jsx(StepContainer, { "$wide": true, children: _jsxs(InnerStepContainer, { children: [_jsx(ButtonContainer, { children: isOnRampLoaded ? (_jsxs(_Fragment, { children: [onRampConfig.isBuyEnabled && (_jsx(OptionButton, { icon: "creditCard", onClick: handleBuyClick, children: _jsx(CpslText, { variant: "bodyXS", color: "secondary", weight: "medium", children: "Buy Crypto" }) })), onRampConfig.isReceiveEnabled && (_jsx(OptionButton, { icon: "qrCode02", onClick: handleReceiveClick, children: _jsx(CpslText, { variant: "bodyXS", color: "secondary", weight: "medium", children: "Receive" }) })), onRampConfig.isWithdrawEnabled && (_jsx(OptionButton, { icon: "arrowCircleBrokenDownLeft", onClick: handleSellClick, children: _jsx(CpslText, { variant: "bodyXS", color: "secondary", weight: "medium", children: "Withdraw" }) }))] })) : (_jsx(CpslSpinner, {})) }), _jsx(DisconnectButton, { variant: "destructive", fullWidth: true, onClick: handleDisconnectClick, disabled: isDisconnecting, children: isDisconnecting ? (_jsx(CpslSpinner, { size: 16 })) : (_jsxs(_Fragment, { children: [hideWallets ? 'Logout' : 'Disconnect Wallet', _jsx(CpslIcon, { icon: "logOut", slot: "end" })] })) })] }) }));
|
|
43
|
+
};
|
|
44
|
+
const ButtonContainer = styled.div `
|
|
45
|
+
display: flex;
|
|
46
|
+
align-items: center;
|
|
47
|
+
justify-content: center;
|
|
48
|
+
gap: 8px;
|
|
49
|
+
width: 100%;
|
|
50
|
+
height: 88px;
|
|
51
|
+
`;
|
|
52
|
+
const OptionButton = styled(StyledCpslTileButton) `
|
|
53
|
+
flex: 1;
|
|
54
|
+
|
|
55
|
+
--button-icon-color: var(--cpsl-color-text-primary);
|
|
56
|
+
`;
|
|
57
|
+
const DisconnectButton = styled(CpslButton) `
|
|
58
|
+
--button-border-width: 0px;
|
|
59
|
+
`;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
11
|
+
import { EnabledFlow, getOnRampAssets, getOnRampNetworks, OnRampProvider, OnRampPurchaseType, toAssetInfoArray, WalletType, } from '@getpara/web-sdk';
|
|
12
|
+
import { CenteredText, FilledDisabledInput, Heading, InnerStepContainer, QRContainer, StepContainer } from '../common.js';
|
|
13
|
+
import { CpslButton, CpslDivider, CpslIcon, CpslIdenticon, CpslQrCode, CpslSpinner, CpslTab, CpslTabs, CpslText, } from '@getpara/react-components';
|
|
14
|
+
import { useParaStore, useModalStore, useThemeStore } from '../../stores/index.js';
|
|
15
|
+
import { useEffect, useMemo } from 'react';
|
|
16
|
+
import { OnRampProviderButton } from '../OnRampComponents/OnRampProviderButton.js';
|
|
17
|
+
import { isMobile } from '@getpara/web-sdk';
|
|
18
|
+
import { useActiveWallet } from '../../hooks/useActiveWallet.js';
|
|
19
|
+
import { getAddFundsStep, ModalStep } from '../../utils/steps.js';
|
|
20
|
+
import { motion, AnimatePresence } from 'framer-motion';
|
|
21
|
+
import { useExternalWallets } from '../../providers/ExternalWalletContext.js';
|
|
22
|
+
import { getNetworkFromChainId, getNetworkOrMainNetEquivalent, useCopyToClipboard } from '@getpara/react-common';
|
|
23
|
+
import { formatNetworkList } from '../../utils/stringFormatters.js';
|
|
24
|
+
import styled from 'styled-components';
|
|
25
|
+
const TABS = [
|
|
26
|
+
[EnabledFlow.BUY, 'isBuyEnabled', 'creditCard', 'Buy'],
|
|
27
|
+
[EnabledFlow.RECEIVE, 'isReceiveEnabled', 'qrCode', 'Receive'],
|
|
28
|
+
[EnabledFlow.WITHDRAW, 'isWithdrawEnabled', 'arrowCircleBrokenDownLeft', 'Withdraw'],
|
|
29
|
+
];
|
|
30
|
+
const GENERIC_WALLET = {
|
|
31
|
+
[WalletType.EVM]: 'Ethereum or EVM-based L2s',
|
|
32
|
+
[WalletType.SOLANA]: 'Solana',
|
|
33
|
+
[WalletType.COSMOS]: 'Cosmos',
|
|
34
|
+
};
|
|
35
|
+
export const AddFunds = () => {
|
|
36
|
+
const [isCopied, copy] = useCopyToClipboard();
|
|
37
|
+
const para = useParaStore(state => state.para);
|
|
38
|
+
const appName = useThemeStore(state => state.appName);
|
|
39
|
+
const onRampConfig = useModalStore(state => state.onRampConfig);
|
|
40
|
+
const hideWallets = useThemeStore(state => state.hideWallets);
|
|
41
|
+
const storedTab = useModalStore(state => state.accountAddFundTab);
|
|
42
|
+
const setStep = useModalStore(state => state.setStep);
|
|
43
|
+
const setOnRampPurchase = useModalStore(state => state.setOnRampPurchase);
|
|
44
|
+
const { chainId } = useExternalWallets();
|
|
45
|
+
const activeWallet = useActiveWallet();
|
|
46
|
+
const tabs = TABS.filter(([, key]) => !!onRampConfig[key]);
|
|
47
|
+
const isMultiFlow = tabs.length > 1;
|
|
48
|
+
const tab = storedTab !== null && storedTab !== void 0 ? storedTab : tabs[0][0];
|
|
49
|
+
const address = useMemo(() => (activeWallet ? para.getDisplayAddress(activeWallet.id, { addressType: activeWallet.type }) : ''), [para, activeWallet === null || activeWallet === void 0 ? void 0 : activeWallet.id, activeWallet === null || activeWallet === void 0 ? void 0 : activeWallet.type]);
|
|
50
|
+
const onSetTab = (event) => {
|
|
51
|
+
setStep(getAddFundsStep(event.detail.tab));
|
|
52
|
+
};
|
|
53
|
+
const onCopy = () => {
|
|
54
|
+
copy(address);
|
|
55
|
+
};
|
|
56
|
+
const [allowedNetworks, allowedAssets, isProviderAllowed] = useMemo(() => {
|
|
57
|
+
if (!onRampConfig || !activeWallet) {
|
|
58
|
+
return [[], [], {}];
|
|
59
|
+
}
|
|
60
|
+
const action = tab === EnabledFlow.BUY ? OnRampPurchaseType.BUY : OnRampPurchaseType.SELL;
|
|
61
|
+
const detectedNetwork = getNetworkFromChainId(chainId);
|
|
62
|
+
const isExternal = activeWallet.isExternal && !!detectedNetwork;
|
|
63
|
+
const allowedNetworks = isExternal
|
|
64
|
+
? [getNetworkOrMainNetEquivalent(detectedNetwork, onRampConfig.testMode)]
|
|
65
|
+
: getOnRampNetworks(onRampConfig.assetInfo, {
|
|
66
|
+
walletType: activeWallet.type,
|
|
67
|
+
allowed: onRampConfig.allowedAssets ? Object.keys(onRampConfig.allowedAssets) : undefined,
|
|
68
|
+
});
|
|
69
|
+
const allowedAssetsLookup = allowedNetworks.reduce((acc, network) => {
|
|
70
|
+
var _a;
|
|
71
|
+
const configValue = (_a = onRampConfig.allowedAssets) === null || _a === void 0 ? void 0 : _a[network];
|
|
72
|
+
const allowed = configValue === true ? undefined : configValue;
|
|
73
|
+
return Object.assign(Object.assign({}, acc), { [network]: getOnRampAssets(onRampConfig.assetInfo, { walletType: activeWallet.type, network, allowed }) });
|
|
74
|
+
}, {});
|
|
75
|
+
const isProviderAllowed = onRampConfig.providers.reduce((acc, id) => {
|
|
76
|
+
const hasMatch = toAssetInfoArray(onRampConfig.assetInfo).some(([type, network, asset, validProviders]) => {
|
|
77
|
+
var _a, _b;
|
|
78
|
+
return (type === activeWallet.type &&
|
|
79
|
+
allowedNetworks.includes(network) &&
|
|
80
|
+
(!allowedAssetsLookup[network] || allowedAssetsLookup[network].includes(asset)) &&
|
|
81
|
+
!!((_b = (_a = validProviders[id]) === null || _a === void 0 ? void 0 : _a[1]) === null || _b === void 0 ? void 0 : _b[action]));
|
|
82
|
+
});
|
|
83
|
+
return Object.assign(Object.assign({}, acc), { [id]: hasMatch });
|
|
84
|
+
}, {});
|
|
85
|
+
return [allowedNetworks, [...new Set(Object.values(allowedAssetsLookup).flat())], isProviderAllowed];
|
|
86
|
+
}, [activeWallet === null || activeWallet === void 0 ? void 0 : activeWallet.type, activeWallet === null || activeWallet === void 0 ? void 0 : activeWallet.isExternal, tab, onRampConfig.assetInfo, onRampConfig.allowedAssets, chainId]);
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
setOnRampPurchase(undefined);
|
|
89
|
+
}, []);
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
setOnRampPurchase(undefined);
|
|
92
|
+
}, []);
|
|
93
|
+
if (!onRampConfig || !activeWallet) {
|
|
94
|
+
return (_jsx(SpinnerContainer, { children: _jsx(CpslSpinner, {}) }));
|
|
95
|
+
}
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
setOnRampPurchase(undefined);
|
|
98
|
+
}, []);
|
|
99
|
+
return (_jsxs(StepContainer, { children: [isMultiFlow && (_jsx(InnerStepContainer, { children: _jsx(CpslTabs, { selectedTab: tab, onCpslTabsChanged: onSetTab, children: TABS.map(([tab, _, icon, title]) => (_jsxs(CpslTab, { tab: tab, children: [_jsx(CpslIcon, { slot: "start", icon: icon }), title] }, tab))) }) })), _jsx(_Fragment, { children: [EnabledFlow.BUY, EnabledFlow.WITHDRAW].includes(tab) ? (_jsxs(_Fragment, { children: [_jsx(Heading, { variant: "headingS", weight: "bold", children: "Choose Provider" }), _jsxs($InnerStepContainer, { children: [_jsxs(NoProviders, { isHidden: Object.values(isProviderAllowed).some(v => !!v), variant: "bodyM", children: ["No providers are available for this ", hideWallets ? 'account' : 'wallet'] }), _jsx(AnimatePresence, { children: onRampConfig.providers.map((id, index) => {
|
|
100
|
+
return isProviderAllowed[id] ? (_jsx(motion.div, { style: { width: '100%' }, layout: true, initial: { opacity: 0, transform: 'translateX(25px)' }, animate: { opacity: 1, transform: 'none' }, exit: { opacity: 0, transform: 'translateX(-25px)' }, transition: { duration: 0.2 }, children: _jsx(OnRampProviderButton, { config: onRampConfig, index: index, onClick: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
101
|
+
var _a;
|
|
102
|
+
if (!(activeWallet === null || activeWallet === void 0 ? void 0 : activeWallet.type))
|
|
103
|
+
return;
|
|
104
|
+
const isPopup = id !== OnRampProvider.RAMP;
|
|
105
|
+
const { onRampPurchase: newOnRampPurchase } = yield para.initiateOnRampTransaction({
|
|
106
|
+
walletId: activeWallet.isExternal ? undefined : activeWallet.id,
|
|
107
|
+
externalWalletAddress: activeWallet.isExternal ? activeWallet.id : undefined,
|
|
108
|
+
shouldOpenPopup: isPopup,
|
|
109
|
+
params: {
|
|
110
|
+
type: tab === EnabledFlow.BUY ? OnRampPurchaseType.BUY : OnRampPurchaseType.SELL,
|
|
111
|
+
walletType: activeWallet.type,
|
|
112
|
+
provider: id,
|
|
113
|
+
networks: allowedNetworks,
|
|
114
|
+
assets: allowedAssets,
|
|
115
|
+
defaultNetwork: onRampConfig.defaultOnRampNetwork,
|
|
116
|
+
defaultAsset: onRampConfig.defaultOnRampAsset,
|
|
117
|
+
fiatQuantity: (_a = onRampConfig.defaultBuyAmount) === null || _a === void 0 ? void 0 : _a[0],
|
|
118
|
+
testMode: onRampConfig.testMode,
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
setOnRampPurchase(Object.assign(Object.assign({}, newOnRampPurchase), { fiat: 'USD' }));
|
|
122
|
+
!isPopup && setStep(ModalStep.ADD_FUNDS_AWAITING);
|
|
123
|
+
}) }, id) }, id)) : null;
|
|
124
|
+
}) })] })] })) : (_jsxs(_Fragment, { children: [_jsx(InnerStepContainer, { children: _jsxs(FilledDisabledInput, { noAutoDisable: true, readonly: true, placeholder: address, children: [_jsx(CpslIdenticon, { slot: "start", size: "32px", hash: para.getIdenticonHash(activeWallet.id, activeWallet.type) }), _jsx(CpslButton, { slot: "end", variant: "ghost", onClick: onCopy, children: _jsx(CpslIcon, { icon: isCopied ? 'check' : 'copy' }) })] }, address) }), !isMobile() && (_jsxs(_Fragment, { children: [_jsx(CpslDivider, { children: "or" }), _jsxs(InnerStepContainer, { children: [_jsx(QRContainer, { children: !address ? _jsx(CpslSpinner, { size: 100 }) : _jsx(CpslQrCode, { url: address }, address) }), _jsx(CpslText, { weight: "semiBold", color: "secondary", children: "Scan with your crypto wallet" })] })] })), _jsxs(InnerStepContainer, { children: [_jsxs(CenteredText, { weight: "semiBold", children: [(!!onRampConfig.allowedAssets && allowedNetworks.length > 0) || hideWallets
|
|
125
|
+
? (appName !== null && appName !== void 0 ? appName : 'This App')
|
|
126
|
+
: 'This Wallet', ' ', "Only Supports:"] }), _jsx(CenteredText, { weight: "medium", color: "secondary", children: !!onRampConfig.allowedAssets && allowedNetworks.length > 0
|
|
127
|
+
? formatNetworkList(allowedNetworks)
|
|
128
|
+
: GENERIC_WALLET[activeWallet.type] })] })] })) })] }));
|
|
129
|
+
};
|
|
130
|
+
const SpinnerContainer = styled(StepContainer) `
|
|
131
|
+
margin: 50% 0;
|
|
132
|
+
`;
|
|
133
|
+
const $InnerStepContainer = styled(InnerStepContainer) `
|
|
134
|
+
position: relative;
|
|
135
|
+
min-height: 270px;
|
|
136
|
+
`;
|
|
137
|
+
const NoProviders = styled(CpslText) `
|
|
138
|
+
width: 100%;
|
|
139
|
+
text-align: center;
|
|
140
|
+
visibility: ${({ isHidden }) => (isHidden ? 'hidden' : 'visible')};
|
|
141
|
+
position: absolute;
|
|
142
|
+
top: 0;
|
|
143
|
+
left: 0;
|
|
144
|
+
right: 0;
|
|
145
|
+
transition: visibility 0.2s;
|
|
146
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const AddFundsAwaiting: () => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { StepContainer } from '../common.js';
|
|
3
|
+
import { OnRampProvider } from '@getpara/web-sdk';
|
|
4
|
+
import { useParaStore, useModalStore, useThemeStore } from '../../stores/index.js';
|
|
5
|
+
import { lazy, useEffect, useMemo, useState } from 'react';
|
|
6
|
+
import { ModalStep } from '../../utils/steps.js';
|
|
7
|
+
import { RampEmbed, StripeEmbed } from '@getpara/react-common';
|
|
8
|
+
import styled from 'styled-components';
|
|
9
|
+
import { useGoBack } from '../../hooks/useGoBack.js';
|
|
10
|
+
const STEPS = {
|
|
11
|
+
CANCELLED: ModalStep.ADD_FUNDS_FAILURE,
|
|
12
|
+
FINISHED: ModalStep.ADD_FUNDS_SUCCESS,
|
|
13
|
+
};
|
|
14
|
+
export const AddFundsAwaiting = () => {
|
|
15
|
+
const setStep = useModalStore(state => state.setStep);
|
|
16
|
+
const goBack = useGoBack();
|
|
17
|
+
const onRampConfig = useModalStore(state => state.onRampConfig);
|
|
18
|
+
const onRampPurchase = useModalStore(state => state.onRampPurchase);
|
|
19
|
+
const setOnRampPurchase = useModalStore(state => state.setOnRampPurchase);
|
|
20
|
+
const para = useParaStore(state => state.para);
|
|
21
|
+
const appName = useThemeStore(state => state.appName);
|
|
22
|
+
const isDark = useThemeStore(state => state.isDark);
|
|
23
|
+
const [MoonPayEmbed, setMoonPayEmbed] = useState(null);
|
|
24
|
+
const props = {
|
|
25
|
+
para,
|
|
26
|
+
appName,
|
|
27
|
+
onRampConfig,
|
|
28
|
+
onRampPurchase: onRampPurchase,
|
|
29
|
+
isDark,
|
|
30
|
+
isEmbedded: true,
|
|
31
|
+
setOnRampPurchase,
|
|
32
|
+
onClose: goBack,
|
|
33
|
+
};
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const _MoonPayEmbed = lazy(() => import(`./MoonPayEmbed.js`));
|
|
36
|
+
setMoonPayEmbed(_MoonPayEmbed);
|
|
37
|
+
}, []);
|
|
38
|
+
const onRampEmbed = useMemo(() => {
|
|
39
|
+
if (!onRampPurchase.id) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
switch (onRampPurchase === null || onRampPurchase === void 0 ? void 0 : onRampPurchase.provider) {
|
|
43
|
+
case OnRampProvider.STRIPE:
|
|
44
|
+
return _jsx(StripeEmbed, Object.assign({}, props));
|
|
45
|
+
case OnRampProvider.MOONPAY:
|
|
46
|
+
return !MoonPayEmbed || typeof window === 'undefined' ? null : _jsx(MoonPayEmbed, Object.assign({}, props));
|
|
47
|
+
case OnRampProvider.RAMP:
|
|
48
|
+
return _jsx(RampEmbed, Object.assign({ apiKey: onRampConfig.rampApiKey }, props));
|
|
49
|
+
}
|
|
50
|
+
}, [onRampPurchase === null || onRampPurchase === void 0 ? void 0 : onRampPurchase.provider, MoonPayEmbed]);
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
let timeoutId;
|
|
53
|
+
if ((onRampPurchase === null || onRampPurchase === void 0 ? void 0 : onRampPurchase.status) && ['CANCELLED', 'FINISHED'].includes(onRampPurchase.status)) {
|
|
54
|
+
timeoutId = setTimeout(() => {
|
|
55
|
+
setStep(STEPS[onRampPurchase.status]);
|
|
56
|
+
}, 5000);
|
|
57
|
+
}
|
|
58
|
+
return () => clearTimeout(timeoutId);
|
|
59
|
+
}, [onRampPurchase === null || onRampPurchase === void 0 ? void 0 : onRampPurchase.status]);
|
|
60
|
+
return _jsx(Container, { "$wide": true, children: onRampEmbed });
|
|
61
|
+
};
|
|
62
|
+
const Container = styled(StepContainer) `
|
|
63
|
+
flex: 1;
|
|
64
|
+
`;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Heading, HeroIcon, InnerStepContainer, StepContainer } from '../common.js';
|
|
3
|
+
import { useModalStore, useThemeStore } from '../../stores/index.js';
|
|
4
|
+
import { useMemo } from 'react';
|
|
5
|
+
import { CpslButton, CpslText } from '@getpara/react-components';
|
|
6
|
+
import { getAddFundsStep } from '../../utils/steps.js';
|
|
7
|
+
export const AddFundsDone = ({ isSuccess, onClose }) => {
|
|
8
|
+
const hideWallets = useThemeStore(state => state.hideWallets);
|
|
9
|
+
const setStep = useModalStore(state => state.setStep);
|
|
10
|
+
const onRampPurchase = useModalStore(state => state.onRampPurchase);
|
|
11
|
+
const accountAddFundTab = useModalStore(state => state.accountAddFundTab);
|
|
12
|
+
const formatter = useMemo(() => {
|
|
13
|
+
return new Intl.NumberFormat('en-US', {
|
|
14
|
+
style: 'currency',
|
|
15
|
+
currency: (onRampPurchase === null || onRampPurchase === void 0 ? void 0 : onRampPurchase.fiat) || 'USD',
|
|
16
|
+
});
|
|
17
|
+
}, [onRampPurchase === null || onRampPurchase === void 0 ? void 0 : onRampPurchase.fiat]);
|
|
18
|
+
const heading = isSuccess ? 'Transaction Successful' : 'Something Went Wrong';
|
|
19
|
+
const text = isSuccess
|
|
20
|
+
? `${formatter.format(parseFloat(onRampPurchase === null || onRampPurchase === void 0 ? void 0 : onRampPurchase.fiatQuantity))} is now available in your ${hideWallets ? 'account' : 'wallet'}.`
|
|
21
|
+
: `No funds were added to your ${hideWallets ? 'account' : 'wallet'}.`;
|
|
22
|
+
const buttonText = isSuccess ? 'Done' : 'Try Again';
|
|
23
|
+
return (_jsxs(StepContainer, { children: [_jsx(HeroIcon, { icon: "checkCircleFilled" }), _jsxs(InnerStepContainer, { children: [_jsx(Heading, { variant: "headingS", weight: "bold", children: heading }), _jsx(CpslText, { variant: "bodyS", color: "secondary", children: text })] }), _jsx(CpslButton, { fullWidth: true, onClick: () => {
|
|
24
|
+
isSuccess ? onClose() : setStep(getAddFundsStep(accountAddFundTab));
|
|
25
|
+
}, children: buttonText })] }));
|
|
26
|
+
};
|