@getpara/react-sdk 1.9.0 → 1.11.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/modal/components/Account/Account.js +4 -1
- package/dist/modal/components/AddFunds/AddFunds.d.ts +0 -2
- package/dist/modal/components/AddFunds/AddFunds.js +32 -187
- package/dist/modal/components/AddFunds/AddFundsAsset.d.ts +1 -0
- package/dist/modal/components/AddFunds/AddFundsAsset.js +119 -0
- package/dist/modal/components/AddFunds/AddFundsContext.d.ts +31 -0
- package/dist/modal/components/AddFunds/AddFundsContext.js +154 -0
- package/dist/modal/components/AddFunds/AddFundsProvider.d.ts +1 -0
- package/dist/modal/components/AddFunds/AddFundsProvider.js +105 -0
- package/dist/modal/components/AddFunds/AddFundsReceive.d.ts +1 -0
- package/dist/modal/components/AddFunds/AddFundsReceive.js +79 -0
- package/dist/modal/components/AddFunds/AddFundsSettings.d.ts +1 -0
- package/dist/modal/components/AddFunds/AddFundsSettings.js +233 -0
- package/dist/modal/components/AddFunds/common.d.ts +19 -0
- package/dist/modal/components/AddFunds/common.js +24 -0
- package/dist/modal/components/Body/Body.js +3 -1
- package/dist/modal/components/Controls/Selects.js +9 -59
- package/dist/modal/components/WalletCard/WalletCard.js +1 -1
- package/dist/modal/components/common.d.ts +28 -9
- package/dist/modal/components/common.js +74 -1
- package/dist/modal/constants/constants.d.ts +9 -2
- package/dist/modal/constants/constants.js +34 -8
- package/dist/modal/index.d.ts +1 -1
- package/dist/modal/index.js +2 -2
- package/dist/modal/stores/modal/actions.js +11 -1
- package/dist/modal/stores/modal/useModalStore.d.ts +7 -1
- package/dist/modal/stores/modal/useModalStore.js +7 -0
- package/dist/provider/actions/createGuestWallets.d.ts +2 -0
- package/dist/provider/actions/createGuestWallets.js +13 -0
- package/dist/provider/actions/getAccount.d.ts +1 -0
- package/dist/provider/actions/getAccount.js +1 -0
- package/dist/provider/hooks/mutations/index.d.ts +1 -0
- package/dist/provider/hooks/mutations/index.js +2 -0
- package/dist/provider/hooks/mutations/useCreateGuestWallets.d.ts +15 -0
- package/dist/provider/hooks/mutations/useCreateGuestWallets.js +23 -0
- package/dist/provider/hooks/queries/useAccount.d.ts +1 -0
- package/package.json +9 -7
|
@@ -6,7 +6,7 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
|
6
6
|
import styled from "styled-components";
|
|
7
7
|
import { InnerStepContainer, StepContainer, StyledCpslTileButton } from "../common.js";
|
|
8
8
|
import { CpslButton, CpslIcon, CpslSpinner, CpslText } from "@getpara/react-components";
|
|
9
|
-
import { useModalStore, useThemeStore } from "../../stores/index.js";
|
|
9
|
+
import { OnRampStep, useModalStore, useThemeStore } from "../../stores/index.js";
|
|
10
10
|
import { useExternalWallets } from "../../providers/ExternalWalletContext.js";
|
|
11
11
|
import { useState } from "react";
|
|
12
12
|
import { ModalStep } from "../../utils/steps.js";
|
|
@@ -15,18 +15,21 @@ import { formatBalanceString } from "../../utils/stringFormatters.js";
|
|
|
15
15
|
const Account = ({ onClose }) => {
|
|
16
16
|
const onRampConfig = useModalStore((state) => state.onRampConfig);
|
|
17
17
|
const setStep = useModalStore((state) => state.setStep);
|
|
18
|
+
const setOnRampStep = useModalStore((state) => state.setOnRampStep);
|
|
18
19
|
const hideWallets = useThemeStore((state) => state.hideWallets);
|
|
19
20
|
const { disconnectExternalWallet } = useExternalWallets();
|
|
20
21
|
const { balance, isLoading: isBalanceLoading } = useWalletBalance();
|
|
21
22
|
const [isDisconnecting, setIsDisconnecting] = useState(false);
|
|
22
23
|
const isOnRampLoaded = !!onRampConfig;
|
|
23
24
|
const handleBuyClick = () => {
|
|
25
|
+
setOnRampStep(OnRampStep.SETTINGS);
|
|
24
26
|
setStep(ModalStep.ADD_FUNDS_BUY);
|
|
25
27
|
};
|
|
26
28
|
const handleReceiveClick = () => {
|
|
27
29
|
setStep(ModalStep.ADD_FUNDS_RECEIVE);
|
|
28
30
|
};
|
|
29
31
|
const handleSellClick = () => {
|
|
32
|
+
setOnRampStep(OnRampStep.SETTINGS);
|
|
30
33
|
setStep(ModalStep.ADD_FUNDS_WITHDRAW);
|
|
31
34
|
};
|
|
32
35
|
const handleDisconnectClick = () => __async(void 0, null, function* () {
|
|
@@ -1,220 +1,65 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from "
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
EnabledFlow,
|
|
10
|
-
getOnRampAssets,
|
|
11
|
-
getOnRampNetworks,
|
|
12
|
-
OnRampProvider,
|
|
13
|
-
OnRampPurchaseType,
|
|
14
|
-
toAssetInfoArray,
|
|
15
|
-
WalletType
|
|
16
|
-
} from "@getpara/web-sdk";
|
|
17
|
-
import { CenteredText, FilledDisabledInput, Heading, InnerStepContainer, QRContainer, StepContainer } from "../common.js";
|
|
18
|
-
import {
|
|
19
|
-
CpslButton,
|
|
20
|
-
CpslDivider,
|
|
21
|
-
CpslIcon,
|
|
22
|
-
CpslIdenticon,
|
|
23
|
-
CpslQrCode,
|
|
24
|
-
CpslSpinner,
|
|
25
|
-
CpslTab,
|
|
26
|
-
CpslTabs,
|
|
27
|
-
CpslText
|
|
28
|
-
} from "@getpara/react-components";
|
|
29
|
-
import { useModalStore, useThemeStore } from "../../stores/index.js";
|
|
2
|
+
import "../../../chunk-MMUBH76A.js";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { EnabledFlow } from "@getpara/web-sdk";
|
|
5
|
+
import { InnerStepContainer, StepContainer } from "../common.js";
|
|
6
|
+
import { CpslIcon, CpslSpinner, CpslTab, CpslTabs } from "@getpara/react-components";
|
|
7
|
+
import { OnRampStep } from "../../stores/index.js";
|
|
8
|
+
import { useModalStore } from "../../stores/modal/useModalStore.js";
|
|
30
9
|
import { useEffect, useMemo } from "react";
|
|
31
|
-
import { OnRampProviderButton } from "../OnRampComponents/OnRampProviderButton.js";
|
|
32
|
-
import { isMobile } from "@getpara/web-sdk";
|
|
33
10
|
import { useActiveWallet } from "../../hooks/useActiveWallet.js";
|
|
34
|
-
import { getAddFundsStep
|
|
35
|
-
import { motion, AnimatePresence } from "framer-motion";
|
|
36
|
-
import { useExternalWallets } from "../../providers/ExternalWalletContext.js";
|
|
37
|
-
import { getNetworkFromChainId, getNetworkOrMainNetEquivalent, useCopyToClipboard } from "@getpara/react-common";
|
|
38
|
-
import { formatNetworkList } from "../../utils/stringFormatters.js";
|
|
11
|
+
import { getAddFundsStep } from "../../utils/steps.js";
|
|
39
12
|
import styled from "styled-components";
|
|
40
|
-
import {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
];
|
|
46
|
-
const GENERIC_WALLET = {
|
|
47
|
-
[WalletType.EVM]: "Ethereum or EVM-based L2s",
|
|
48
|
-
[WalletType.SOLANA]: "Solana or SVM-based networks",
|
|
49
|
-
[WalletType.COSMOS]: "Cosmos"
|
|
50
|
-
};
|
|
13
|
+
import { AddFundsProvider } from "./AddFundsProvider.js";
|
|
14
|
+
import { AddFundsReceive } from "./AddFundsReceive.js";
|
|
15
|
+
import { AddFundsContextProvider, TABS } from "./AddFundsContext.js";
|
|
16
|
+
import { AnimatePresence } from "framer-motion";
|
|
17
|
+
import { AddFundsSettings } from "./AddFundsSettings.js";
|
|
51
18
|
const AddFunds = () => {
|
|
52
|
-
const [isCopied, copy] = useCopyToClipboard();
|
|
53
|
-
const para = useInternalClient();
|
|
54
|
-
const appName = useThemeStore((state) => state.appName);
|
|
55
19
|
const onRampConfig = useModalStore((state) => state.onRampConfig);
|
|
56
|
-
const
|
|
20
|
+
const onRampStep = useModalStore((state) => state.onRampStep);
|
|
57
21
|
const storedTab = useModalStore((state) => state.accountAddFundTab);
|
|
58
|
-
const
|
|
22
|
+
const setModalStep = useModalStore((state) => state.setStep);
|
|
59
23
|
const setOnRampPurchase = useModalStore((state) => state.setOnRampPurchase);
|
|
60
|
-
const { chainId } = useExternalWallets();
|
|
61
24
|
const activeWallet = useActiveWallet();
|
|
62
25
|
const tabs = TABS.filter(([, key]) => !!onRampConfig[key]);
|
|
63
|
-
const isMultiFlow = tabs.length > 1;
|
|
64
26
|
const tab = storedTab != null ? storedTab : tabs[0][0];
|
|
65
|
-
const
|
|
66
|
-
() => activeWallet ? para.getDisplayAddress(activeWallet.id, { addressType: activeWallet.type }) : "",
|
|
67
|
-
[para, activeWallet == null ? void 0 : activeWallet.id, activeWallet == null ? void 0 : activeWallet.type]
|
|
68
|
-
);
|
|
27
|
+
const isMultiFlow = tabs.length > 1;
|
|
69
28
|
const onSetTab = (event) => {
|
|
70
|
-
|
|
29
|
+
setModalStep(getAddFundsStep(event.detail.tab));
|
|
71
30
|
};
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
31
|
+
const Content = useMemo(() => {
|
|
32
|
+
switch (tab) {
|
|
33
|
+
case EnabledFlow.BUY:
|
|
34
|
+
case EnabledFlow.WITHDRAW: {
|
|
35
|
+
switch (onRampStep) {
|
|
36
|
+
case OnRampStep.SETTINGS:
|
|
37
|
+
return /* @__PURE__ */ jsx(AddFundsSettings, {});
|
|
38
|
+
case OnRampStep.PROVIDER:
|
|
39
|
+
return /* @__PURE__ */ jsx(AddFundsProvider, {});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
default:
|
|
43
|
+
return /* @__PURE__ */ jsx(AddFundsReceive, {});
|
|
78
44
|
}
|
|
79
|
-
|
|
80
|
-
const detectedNetwork = getNetworkFromChainId(chainId);
|
|
81
|
-
const isExternal = activeWallet.isExternal && !!detectedNetwork;
|
|
82
|
-
const allowedNetworks2 = isExternal ? [getNetworkOrMainNetEquivalent(detectedNetwork, onRampConfig.testMode)] : getOnRampNetworks(onRampConfig.assetInfo, {
|
|
83
|
-
walletType: activeWallet.type,
|
|
84
|
-
allowed: onRampConfig.allowedAssets ? Object.keys(onRampConfig.allowedAssets) : void 0
|
|
85
|
-
});
|
|
86
|
-
const allowedAssetsLookup = allowedNetworks2.reduce((acc, network) => {
|
|
87
|
-
var _a;
|
|
88
|
-
const configValue = (_a = onRampConfig.allowedAssets) == null ? void 0 : _a[network];
|
|
89
|
-
const allowed = configValue === true ? void 0 : configValue;
|
|
90
|
-
return __spreadProps(__spreadValues({}, acc), {
|
|
91
|
-
[network]: getOnRampAssets(onRampConfig.assetInfo, { walletType: activeWallet.type, network, allowed })
|
|
92
|
-
});
|
|
93
|
-
}, {});
|
|
94
|
-
const isProviderAllowed2 = onRampConfig.providers.reduce(
|
|
95
|
-
(acc, id) => {
|
|
96
|
-
const hasMatch = toAssetInfoArray(onRampConfig.assetInfo).some(([type, network, asset, validProviders]) => {
|
|
97
|
-
var _a, _b;
|
|
98
|
-
return type === activeWallet.type && allowedNetworks2.includes(network) && (!allowedAssetsLookup[network] || allowedAssetsLookup[network].includes(asset)) && !!((_b = (_a = validProviders[id]) == null ? void 0 : _a[1]) == null ? void 0 : _b[action]);
|
|
99
|
-
});
|
|
100
|
-
return __spreadProps(__spreadValues({}, acc), {
|
|
101
|
-
[id]: hasMatch
|
|
102
|
-
});
|
|
103
|
-
},
|
|
104
|
-
{}
|
|
105
|
-
);
|
|
106
|
-
return [allowedNetworks2, [...new Set(Object.values(allowedAssetsLookup).flat())], isProviderAllowed2];
|
|
107
|
-
}, [activeWallet == null ? void 0 : activeWallet.type, activeWallet == null ? void 0 : activeWallet.isExternal, tab, onRampConfig.assetInfo, onRampConfig.allowedAssets, chainId]);
|
|
108
|
-
useEffect(() => {
|
|
109
|
-
setOnRampPurchase(void 0);
|
|
110
|
-
}, []);
|
|
45
|
+
}, [onRampStep, tab]);
|
|
111
46
|
useEffect(() => {
|
|
112
47
|
setOnRampPurchase(void 0);
|
|
113
48
|
}, []);
|
|
114
49
|
if (!onRampConfig || !activeWallet) {
|
|
115
50
|
return /* @__PURE__ */ jsx(SpinnerContainer, { children: /* @__PURE__ */ jsx(CpslSpinner, {}) });
|
|
116
51
|
}
|
|
117
|
-
useEffect(() => {
|
|
118
|
-
setOnRampPurchase(void 0);
|
|
119
|
-
}, []);
|
|
120
52
|
return /* @__PURE__ */ jsxs(StepContainer, { children: [
|
|
121
53
|
isMultiFlow && /* @__PURE__ */ jsx(InnerStepContainer, { children: /* @__PURE__ */ jsx(CpslTabs, { selectedTab: tab, onCpslTabsChanged: onSetTab, children: TABS.map(([tab2, _, icon, title]) => /* @__PURE__ */ jsxs(CpslTab, { tab: tab2, children: [
|
|
122
54
|
/* @__PURE__ */ jsx(CpslIcon, { slot: "start", icon }),
|
|
123
55
|
title
|
|
124
56
|
] }, tab2)) }) }),
|
|
125
|
-
/* @__PURE__ */ jsx(
|
|
126
|
-
/* @__PURE__ */ jsx(Heading, { variant: "headingS", weight: "bold", children: "Choose Provider" }),
|
|
127
|
-
/* @__PURE__ */ jsxs($InnerStepContainer, { children: [
|
|
128
|
-
/* @__PURE__ */ jsxs(NoProviders, { isHidden: Object.values(isProviderAllowed).some((v) => !!v), variant: "bodyM", children: [
|
|
129
|
-
"No providers are available for this ",
|
|
130
|
-
hideWallets ? "account" : "wallet"
|
|
131
|
-
] }),
|
|
132
|
-
/* @__PURE__ */ jsx(AnimatePresence, { children: onRampConfig.providers.map((id, index) => {
|
|
133
|
-
return isProviderAllowed[id] ? /* @__PURE__ */ jsx(
|
|
134
|
-
motion.div,
|
|
135
|
-
{
|
|
136
|
-
style: { width: "100%" },
|
|
137
|
-
layout: true,
|
|
138
|
-
initial: { opacity: 0, transform: "translateX(25px)" },
|
|
139
|
-
animate: { opacity: 1, transform: "none" },
|
|
140
|
-
exit: { opacity: 0, transform: "translateX(-25px)" },
|
|
141
|
-
transition: { duration: 0.2 },
|
|
142
|
-
children: /* @__PURE__ */ jsx(
|
|
143
|
-
OnRampProviderButton,
|
|
144
|
-
{
|
|
145
|
-
config: onRampConfig,
|
|
146
|
-
index,
|
|
147
|
-
onClick: () => __async(void 0, null, function* () {
|
|
148
|
-
var _a;
|
|
149
|
-
if (!(activeWallet == null ? void 0 : activeWallet.type)) return;
|
|
150
|
-
const isPopup = id !== OnRampProvider.RAMP;
|
|
151
|
-
const { onRampPurchase: newOnRampPurchase } = yield para.initiateOnRampTransaction({
|
|
152
|
-
walletId: activeWallet.isExternal ? void 0 : activeWallet.id,
|
|
153
|
-
externalWalletAddress: activeWallet.isExternal ? activeWallet.id : void 0,
|
|
154
|
-
shouldOpenPopup: isPopup,
|
|
155
|
-
params: {
|
|
156
|
-
type: tab === EnabledFlow.BUY ? OnRampPurchaseType.BUY : OnRampPurchaseType.SELL,
|
|
157
|
-
walletType: activeWallet.type,
|
|
158
|
-
provider: id,
|
|
159
|
-
networks: allowedNetworks,
|
|
160
|
-
assets: allowedAssets,
|
|
161
|
-
defaultNetwork: onRampConfig.defaultOnRampNetwork,
|
|
162
|
-
defaultAsset: onRampConfig.defaultOnRampAsset,
|
|
163
|
-
fiatQuantity: (_a = onRampConfig.defaultBuyAmount) == null ? void 0 : _a[0],
|
|
164
|
-
testMode: onRampConfig.testMode
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
setOnRampPurchase(__spreadProps(__spreadValues({}, newOnRampPurchase), { fiat: "USD" }));
|
|
168
|
-
!isPopup && setStep(ModalStep.ADD_FUNDS_AWAITING);
|
|
169
|
-
})
|
|
170
|
-
},
|
|
171
|
-
id
|
|
172
|
-
)
|
|
173
|
-
},
|
|
174
|
-
id
|
|
175
|
-
) : null;
|
|
176
|
-
}) })
|
|
177
|
-
] })
|
|
178
|
-
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
179
|
-
/* @__PURE__ */ jsx(InnerStepContainer, { children: /* @__PURE__ */ jsxs(FilledDisabledInput, { noAutoDisable: true, readonly: true, placeholder: address, children: [
|
|
180
|
-
/* @__PURE__ */ jsx(CpslIdenticon, { slot: "start", size: "32px", hash: para.getIdenticonHash(activeWallet.id, activeWallet.type) }),
|
|
181
|
-
/* @__PURE__ */ jsx(CpslButton, { slot: "end", variant: "ghost", onClick: onCopy, children: /* @__PURE__ */ jsx(CpslIcon, { icon: isCopied ? "check" : "copy" }) })
|
|
182
|
-
] }, address) }),
|
|
183
|
-
!isMobile() && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
184
|
-
/* @__PURE__ */ jsx(CpslDivider, { children: "or" }),
|
|
185
|
-
/* @__PURE__ */ jsxs(InnerStepContainer, { children: [
|
|
186
|
-
/* @__PURE__ */ jsx(QRContainer, { children: !address ? /* @__PURE__ */ jsx(CpslSpinner, { size: 100 }) : /* @__PURE__ */ jsx(CpslQrCode, { url: address }, address) }),
|
|
187
|
-
/* @__PURE__ */ jsx(CpslText, { weight: "semiBold", color: "secondary", children: "Scan with your crypto wallet" })
|
|
188
|
-
] })
|
|
189
|
-
] }),
|
|
190
|
-
/* @__PURE__ */ jsxs(InnerStepContainer, { children: [
|
|
191
|
-
/* @__PURE__ */ jsxs(CenteredText, { weight: "semiBold", children: [
|
|
192
|
-
!!onRampConfig.allowedAssets && allowedNetworks.length > 0 || hideWallets ? appName != null ? appName : "This App" : "This Wallet",
|
|
193
|
-
" ",
|
|
194
|
-
"Only Supports:"
|
|
195
|
-
] }),
|
|
196
|
-
/* @__PURE__ */ jsx(CenteredText, { weight: "medium", color: "secondary", children: !!onRampConfig.allowedAssets && allowedNetworks.length > 0 ? formatNetworkList(allowedNetworks) : GENERIC_WALLET[activeWallet.type] })
|
|
197
|
-
] })
|
|
198
|
-
] }) })
|
|
57
|
+
/* @__PURE__ */ jsx(AnimatePresence, { mode: "wait", children: /* @__PURE__ */ jsx(AddFundsContextProvider, { "data-testid": "add-funds", tab, children: Content }) })
|
|
199
58
|
] });
|
|
200
59
|
};
|
|
201
60
|
const SpinnerContainer = styled(StepContainer)`
|
|
202
61
|
margin: 50% 0;
|
|
203
62
|
`;
|
|
204
|
-
const $InnerStepContainer = styled(InnerStepContainer)`
|
|
205
|
-
position: relative;
|
|
206
|
-
min-height: 270px;
|
|
207
|
-
`;
|
|
208
|
-
const NoProviders = styled(CpslText)`
|
|
209
|
-
width: 100%;
|
|
210
|
-
text-align: center;
|
|
211
|
-
visibility: ${({ isHidden }) => isHidden ? "hidden" : "visible"};
|
|
212
|
-
position: absolute;
|
|
213
|
-
top: 0;
|
|
214
|
-
left: 0;
|
|
215
|
-
right: 0;
|
|
216
|
-
transition: visibility 0.2s;
|
|
217
|
-
`;
|
|
218
63
|
export {
|
|
219
64
|
AddFunds
|
|
220
65
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function AddFundsAsset(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
__async,
|
|
4
|
+
__spreadProps,
|
|
5
|
+
__spreadValues
|
|
6
|
+
} from "../../../chunk-MMUBH76A.js";
|
|
7
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import * as comp from "@getpara/react-components";
|
|
9
|
+
import { getOnRampNetworks } from "@getpara/web-sdk";
|
|
10
|
+
import styled from "styled-components";
|
|
11
|
+
import { getAssetCode, getAssetName, ON_RAMP_ASSETS } from "../../constants/constants.js";
|
|
12
|
+
import { useModalStore } from "../../stores/index.js";
|
|
13
|
+
import { useRef, useState } from "react";
|
|
14
|
+
import { useAddFunds } from "./AddFundsContext.js";
|
|
15
|
+
import { useActiveWallet } from "../../hooks/useActiveWallet.js";
|
|
16
|
+
import { AssetIcon } from "../common.js";
|
|
17
|
+
import { AnimatePresence, motion } from "framer-motion";
|
|
18
|
+
import { contentMotionProps } from "./common.js";
|
|
19
|
+
function AddFundsAsset() {
|
|
20
|
+
const onRampConfig = useModalStore((state) => state.onRampConfig);
|
|
21
|
+
const { assets, setAsset, network, setNetwork } = useAddFunds();
|
|
22
|
+
const activeWallet = useActiveWallet();
|
|
23
|
+
const [isAtBottom, setIsAtBottom] = useState(false);
|
|
24
|
+
const [isAtTop, setIsAtTop] = useState(true);
|
|
25
|
+
const [searchStr, setSearchStr] = useState("");
|
|
26
|
+
const ref = useRef(null);
|
|
27
|
+
const onSelect = (_asset) => __async(this, null, function* () {
|
|
28
|
+
yield setAsset(_asset);
|
|
29
|
+
if (!network) {
|
|
30
|
+
yield setNetwork(
|
|
31
|
+
getOnRampNetworks(onRampConfig.assetInfo, {
|
|
32
|
+
walletType: activeWallet.type,
|
|
33
|
+
assets: [_asset]
|
|
34
|
+
})[0]
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const onScroll = () => {
|
|
39
|
+
const { scrollTop, scrollHeight, clientHeight } = ref.current;
|
|
40
|
+
if (scrollTop + clientHeight >= scrollHeight - 30) {
|
|
41
|
+
setIsAtBottom(true);
|
|
42
|
+
} else {
|
|
43
|
+
setIsAtBottom(false);
|
|
44
|
+
}
|
|
45
|
+
if (scrollTop < 30) {
|
|
46
|
+
setIsAtTop(true);
|
|
47
|
+
} else {
|
|
48
|
+
setIsAtTop(false);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
52
|
+
/* @__PURE__ */ jsx(AnimatePresence, { mode: "sync", children: assets.length >= 4 && /* @__PURE__ */ jsx(motion.div, __spreadProps(__spreadValues({}, contentMotionProps), { children: /* @__PURE__ */ jsx(
|
|
53
|
+
SearchInput,
|
|
54
|
+
{
|
|
55
|
+
placeholder: "Search for an asset",
|
|
56
|
+
value: searchStr,
|
|
57
|
+
onCpslInput: (e) => {
|
|
58
|
+
setSearchStr(e.detail.value);
|
|
59
|
+
},
|
|
60
|
+
children: /* @__PURE__ */ jsx(comp.CpslIcon, { icon: "search", slot: "start" })
|
|
61
|
+
}
|
|
62
|
+
) })) }),
|
|
63
|
+
/* @__PURE__ */ jsx(ScrollContainer, { isAtBottom, isAtTop, ref, onScroll, children: /* @__PURE__ */ jsx(AssetList, { children: /* @__PURE__ */ jsx(AnimatePresence, { mode: "sync", children: assets.filter((asset) => {
|
|
64
|
+
return searchStr === "" || getAssetCode(asset).toLowerCase().startsWith(searchStr.toLowerCase()) || getAssetName(asset).toLowerCase().startsWith(searchStr.toLowerCase());
|
|
65
|
+
}).map((asset) => /* @__PURE__ */ jsx(
|
|
66
|
+
motion.li,
|
|
67
|
+
{
|
|
68
|
+
style: { width: "100%" },
|
|
69
|
+
initial: { opacity: 0 },
|
|
70
|
+
animate: { opacity: 1 },
|
|
71
|
+
exit: { opacity: 0 },
|
|
72
|
+
transition: { duration: 0.2 },
|
|
73
|
+
children: /* @__PURE__ */ jsxs(AssetButton, { fullWidth: true, variant: "secondary", onClick: () => onSelect(asset), children: [
|
|
74
|
+
/* @__PURE__ */ jsx(AssetIcon, { asset, size: "48px" }),
|
|
75
|
+
/* @__PURE__ */ jsxs(Info, { children: [
|
|
76
|
+
/* @__PURE__ */ jsx(Code, { variant: "bodyL", children: ON_RAMP_ASSETS[asset].code }),
|
|
77
|
+
/* @__PURE__ */ jsx(Name, { variant: "bodyS", children: ON_RAMP_ASSETS[asset].name })
|
|
78
|
+
] })
|
|
79
|
+
] }, asset)
|
|
80
|
+
},
|
|
81
|
+
asset
|
|
82
|
+
)) }) }) })
|
|
83
|
+
] });
|
|
84
|
+
}
|
|
85
|
+
const ScrollContainer = styled.div`
|
|
86
|
+
height: calc(100% - 56px);
|
|
87
|
+
width: 100%;
|
|
88
|
+
display: flex;
|
|
89
|
+
flex-direction: column;
|
|
90
|
+
gap: 8px;
|
|
91
|
+
overflow-y: auto;
|
|
92
|
+
mask-image: ${({ isAtBottom, isAtTop }) => !isAtBottom && !isAtTop ? "linear-gradient(to bottom, transparent 0%, black 24px, black calc(100% - 24px), transparent 100%)" : !isAtBottom ? "linear-gradient(to bottom, black calc(100% - 24px), transparent 100%)" : !isAtTop ? "linear-gradient(to top, black calc(100% - 24px), transparent 100%)" : "none"};
|
|
93
|
+
`;
|
|
94
|
+
const AssetList = styled.ul`
|
|
95
|
+
display: flex;
|
|
96
|
+
flex-direction: column;
|
|
97
|
+
width: 100%;
|
|
98
|
+
gap: 8px;
|
|
99
|
+
`;
|
|
100
|
+
const AssetButton = styled(comp.CpslButton)`
|
|
101
|
+
display: flex;
|
|
102
|
+
justify-content: center;
|
|
103
|
+
align-items: center;
|
|
104
|
+
gap: 8px;
|
|
105
|
+
--button-secondary-background-color: var(--cpsl-color-background-8);
|
|
106
|
+
--button-secondary-border-color: var(--cpsl-color-background-8);
|
|
107
|
+
--button-secondary-hover-background-color: var(--cpsl-color-background-16);
|
|
108
|
+
--button-secondary-hover-border-color: var(--cpsl-color-background-16);
|
|
109
|
+
`;
|
|
110
|
+
const Info = styled(comp.CpslCol)`
|
|
111
|
+
text-align: left;
|
|
112
|
+
`, Code = comp.CpslText, Name = comp.CpslText;
|
|
113
|
+
const SearchInput = styled(comp.CpslInput)`
|
|
114
|
+
--container-background-color: var(--cpsl-color-background-8);
|
|
115
|
+
--input-background-color: transparent;
|
|
116
|
+
`;
|
|
117
|
+
export {
|
|
118
|
+
AddFundsAsset
|
|
119
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Dispatch, PropsWithChildren, ReactNode, SetStateAction } from 'react';
|
|
2
|
+
import { useActiveWallet } from '../../hooks/useActiveWallet.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 useActiveWallet>;
|
|
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,154 @@
|
|
|
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 { useExternalWallets } from "../../providers/ExternalWalletContext.js";
|
|
16
|
+
import { useActiveWallet } from "../../hooks/useActiveWallet.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({ assetInfo }, walletType, network, asset) {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
return !!((_b = (_a = assetInfo[walletType]) == null ? void 0 : _a[network]) == null ? void 0 : _b[asset]);
|
|
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 activeWallet = useActiveWallet();
|
|
58
|
+
const [fiatQuantity, setFiatQuantity] = useState((_b = (_a = onRampConfig.defaultBuyAmount) == null ? void 0 : _a[0]) != null ? _b : "25.00");
|
|
59
|
+
const networks = useMemo(() => {
|
|
60
|
+
const detectedNetwork = getNetworkFromChainId(chainId);
|
|
61
|
+
const isExternal = activeWallet.isExternal && !!detectedNetwork;
|
|
62
|
+
return isExternal ? [getNetworkOrMainNetEquivalent(detectedNetwork, onRampConfig.testMode)] : getOnRampNetworks(onRampConfig.assetInfo, {
|
|
63
|
+
walletType: activeWallet.type,
|
|
64
|
+
allowed: onRampConfig.allowedAssets ? Object.keys(onRampConfig.allowedAssets) : void 0,
|
|
65
|
+
providers: onRampConfig.providers,
|
|
66
|
+
action: OnRampPurchaseType[tab === EnabledFlow.BUY ? "BUY" : "SELL"]
|
|
67
|
+
});
|
|
68
|
+
}, [chainId, activeWallet, onRampConfig, tab]);
|
|
69
|
+
const assets = useMemo(() => {
|
|
70
|
+
return [
|
|
71
|
+
...new Set(
|
|
72
|
+
Object.values(
|
|
73
|
+
networks.reduce((acc, network2) => {
|
|
74
|
+
var _a2;
|
|
75
|
+
const configValue = (_a2 = onRampConfig.allowedAssets) == null ? void 0 : _a2[network2];
|
|
76
|
+
const allowed = configValue === true ? void 0 : configValue;
|
|
77
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
78
|
+
[network2]: getOnRampAssets(onRampConfig.assetInfo, {
|
|
79
|
+
walletType: activeWallet.type,
|
|
80
|
+
network: network2,
|
|
81
|
+
allowed,
|
|
82
|
+
providers: onRampConfig.providers,
|
|
83
|
+
action: OnRampPurchaseType[tab === EnabledFlow.BUY ? "BUY" : "SELL"]
|
|
84
|
+
})
|
|
85
|
+
});
|
|
86
|
+
}, {})
|
|
87
|
+
).flat()
|
|
88
|
+
)
|
|
89
|
+
];
|
|
90
|
+
}, [networks, onRampConfig, activeWallet, tab]);
|
|
91
|
+
const [network, setNetwork] = useState(
|
|
92
|
+
!!(onRampConfig == null ? void 0 : onRampConfig.defaultOnRampNetwork) && !!onRampConfig.assetInfo[activeWallet.type][onRampConfig.defaultOnRampNetwork] ? onRampConfig.defaultOnRampNetwork : void 0
|
|
93
|
+
);
|
|
94
|
+
const [asset, setAsset] = useState(
|
|
95
|
+
!!network && !!(onRampConfig == null ? void 0 : onRampConfig.defaultOnRampAsset) && assets.includes(onRampConfig.defaultOnRampAsset) ? onRampConfig.defaultOnRampAsset : void 0
|
|
96
|
+
);
|
|
97
|
+
const isProviderAllowed = useMemo(
|
|
98
|
+
() => onRampConfig.providers.reduce(
|
|
99
|
+
(acc, id) => {
|
|
100
|
+
var _a2, _b2, _c, _d, _e;
|
|
101
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
102
|
+
[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"])
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
{}
|
|
106
|
+
),
|
|
107
|
+
[onRampConfig, network, asset, activeWallet, tab]
|
|
108
|
+
);
|
|
109
|
+
const value = useMemo(() => {
|
|
110
|
+
if (!onRampConfig || !activeWallet) {
|
|
111
|
+
return DEFAULT;
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
tab,
|
|
115
|
+
networks,
|
|
116
|
+
assets,
|
|
117
|
+
isProviderAllowed,
|
|
118
|
+
asset,
|
|
119
|
+
setAsset,
|
|
120
|
+
network,
|
|
121
|
+
setNetwork,
|
|
122
|
+
fiatQuantity,
|
|
123
|
+
setFiatQuantity,
|
|
124
|
+
activeWallet,
|
|
125
|
+
onRampConfig
|
|
126
|
+
};
|
|
127
|
+
}, [
|
|
128
|
+
tab,
|
|
129
|
+
networks,
|
|
130
|
+
assets,
|
|
131
|
+
isProviderAllowed,
|
|
132
|
+
asset,
|
|
133
|
+
setAsset,
|
|
134
|
+
network,
|
|
135
|
+
setNetwork,
|
|
136
|
+
fiatQuantity,
|
|
137
|
+
setFiatQuantity,
|
|
138
|
+
activeWallet,
|
|
139
|
+
onRampConfig
|
|
140
|
+
]);
|
|
141
|
+
useEffect(() => {
|
|
142
|
+
if (onRampStep === OnRampStep.PROVIDER && !isValid(onRampConfig, activeWallet.type, network, asset)) {
|
|
143
|
+
setOnRampStep(OnRampStep.SETTINGS);
|
|
144
|
+
}
|
|
145
|
+
}, [onRampStep, onRampConfig, activeWallet.type, network, asset, setOnRampStep]);
|
|
146
|
+
return /* @__PURE__ */ jsx(AddFundsContext.Provider, { value, children });
|
|
147
|
+
}
|
|
148
|
+
const useAddFunds = () => useContext(AddFundsContext);
|
|
149
|
+
export {
|
|
150
|
+
AddFundsContext,
|
|
151
|
+
AddFundsContextProvider,
|
|
152
|
+
TABS,
|
|
153
|
+
useAddFunds
|
|
154
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function AddFundsProvider(): import("react/jsx-runtime").JSX.Element;
|