@getpara/react-common 1.1.0 → 1.3.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.
@@ -1,20 +0,0 @@
1
- import ParaWeb from '@getpara/web-sdk';
2
- export class ParaInternal extends ParaWeb {
3
- constructor() {
4
- super(...arguments);
5
- this.getSupportedCreateAuthMethods = super.getSupportedCreateAuthMethods;
6
- this.isUsingExternalWallet = super.isUsingExternalWallet;
7
- this.getTransmissionKeyShares = super.getTransmissionKeyShares;
8
- this.userSetupAfterLogin = super.userSetupAfterLogin;
9
- this.setLoginEncryptionKeyPair = super.setLoginEncryptionKeyPair;
10
- this.getPortalURL = super.getPortalURL;
11
- this.isProviderModalDisabled = super.isProviderModalDisabled;
12
- this.supportedAuthMethods = super.supportedAuthMethods;
13
- this.getUserBiometricLocationHints = super.getUserBiometricLocationHints;
14
- this.exitLoops = super.exitLoops;
15
- this.exitLogin = super.exitLogin;
16
- this.exitAccountCreation = super.exitAccountCreation;
17
- this.exitOAuth = super.exitOAuth;
18
- this.exitFarcaster = super.exitFarcaster;
19
- }
20
- }
@@ -1 +0,0 @@
1
- export * from './ParaInternal.js';
@@ -1,37 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { CpslIcon, CpslSpinner, CpslText } from '@getpara/react-components';
3
- import styled from 'styled-components';
4
- export function HeroSpinner({ icon, status = 'inactive', text, }) {
5
- return (_jsxs(Root, { children: [_jsxs(Hero, { children: [_jsx(Spinner, { size: 150, barWidth: 9, variant: status === 'loading' ? 'default' : status }), icon && _jsx(CpslIcon, { icon: icon, size: "80px" })] }), _jsxs(Text, { status: status, children: [status === 'error' && _jsx(CpslIcon, { icon: "alertCircle", size: "16px", style: { stroke: 'currentColor' } }), _jsx(CpslText, { variant: "bodyM", weight: "semiBold", color: status === 'error' ? 'error' : 'primary', children: text })] })] }));
6
- }
7
- const Root = styled.div `
8
- height: 276px;
9
- display: flex;
10
- flex-direction: column;
11
- justify-content: center;
12
- align-items: center;
13
- gap: 16px;
14
- `;
15
- const Hero = styled.div `
16
- width: 150px;
17
- height: 150px;
18
- margin: 16px 0;
19
- display: flex;
20
- justify-content: center;
21
- align-items: center;
22
- position: relative;
23
- `;
24
- const Text = styled.div `
25
- display: flex;
26
- gap: 4px;
27
- align-items: center;
28
- color: ${({ status }) => (status === 'error' ? 'var(--cpsl-color-utility-red)' : 'auto')};
29
- `;
30
- const Spinner = styled(CpslSpinner) `
31
- position: absolute;
32
- width: 150px;
33
- height: 150px;
34
- top: 0;
35
- left: 0;
36
- right: 0;
37
- `;
@@ -1,39 +0,0 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { CpslButton, CpslIcon, CpslText } from '@getpara/react-components';
3
- import styled from 'styled-components';
4
- import { CenteredColumnContainer, FullWidthFilledDisabledInput, CenteredText } from './common.js';
5
- import { QRCode } from './QRCode.js';
6
- import { getDeviceLogo, getDeviceModelName } from '../utils/index.js';
7
- import { useCopyToClipboard } from '../hooks/index.js';
8
- export const KnownDevices = ({ hints, link, showCurrentDevice }) => {
9
- const [isCopied, copy] = useCopyToClipboard();
10
- const handleCopy = () => {
11
- copy(link);
12
- };
13
- return (_jsxs(Container, { children: [_jsx(CenteredText, { weight: "semiBold", children: "Continue with one of your other known devices" }), !!hints.formattedHints.length && (_jsx(DevicesContainer, { children: hints.formattedHints.map(hint => {
14
- var _a, _b, _c;
15
- return ((showCurrentDevice && hint.isKnownDevice) || !hint.isKnownDevice) && (_jsxs(DeviceListItem, { children: [_jsx(DeviceLogo, { icon: getDeviceLogo(hint.device.vendor, hint.isMobile) }), _jsx(CpslText, { weight: "medium", color: "contrast", children: (_b = (_a = getDeviceModelName(hint.device.model)) !== null && _a !== void 0 ? _a : hint.device.vendor) !== null && _b !== void 0 ? _b : hint.os.name }), (hint.browser || hint.passwordManager) && (_jsxs(_Fragment, { children: [_jsx(CpslText, { weight: "medium", color: "secondary", children: "using" }), _jsx(CpslText, { weight: "medium", color: "contrast", children: (_c = hint.passwordManager) !== null && _c !== void 0 ? _c : hint.browser.name })] }))] }, hint.key));
16
- }) })), hints.hasMobileDevice ? (_jsx(QRCode, { link: link, icon: "paraIconQr" })) : (_jsxs(CenteredColumnContainer, { children: [_jsx(FullWidthFilledDisabledInput, { noAutoDisable: true, readonly: true, disabled: true, value: link, children: _jsx(CpslButton, { slot: "end", variant: "ghost", onClick: handleCopy, children: _jsx(CpslIcon, { icon: isCopied ? 'check' : 'copy' }) }) }), _jsx(CenteredText, { color: "secondary", variant: "bodyS", weight: "medium", children: "Navigate to this link using your other device" })] }))] }));
17
- };
18
- const Container = styled(CenteredColumnContainer) `
19
- gap: 16px;
20
- `;
21
- const DevicesContainer = styled.div `
22
- display: flex;
23
- flex-direction: column;
24
- gap: 8px;
25
- background: var(--cpsl-color-background-4);
26
- padding: 16px;
27
- width: 100%;
28
- border-radius: 16px;
29
- `;
30
- const DeviceListItem = styled.div `
31
- display: flex;
32
- gap: 4px;
33
- align-items: center;
34
- `;
35
- const DeviceLogo = styled(CpslIcon) `
36
- --icon-color: var(--cpsl-color-text-contrast);
37
- --height: 16px;
38
- --width: 16px;
39
- `;
@@ -1,142 +0,0 @@
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 } from "react/jsx-runtime";
11
- import { OnRampProvider, OnRampPurchaseStatus } from '@getpara/web-sdk';
12
- import { lazy, useCallback, useEffect, useMemo, useState } from 'react';
13
- import { getCurrencyCodes, reverseCurrencyLookup, offRampSend } from '../utils/index.js';
14
- import styled from 'styled-components';
15
- const MOONPAY_PUBLISHABLE_KEY = 'pk_live_EQva4LydtNDE0Rwd9X7SG9w58wqOzbux';
16
- const MOONPAY_PUBLISHABLE_KEY_TEST = 'pk_test_HYobzemmTBXxcSStVA4dSED6jT';
17
- export const MoonPayEmbed = ({ para, isDark, isEmbedded, onRampConfig, onRampPurchase, setOnRampPurchase }) => {
18
- const [LazyMoonPayBuyWidget, setLazyMoonPayBuyWidget] = useState(null);
19
- const [LazyMoonPaySellWidget, setLazyMoonPaySellWidget] = useState(null);
20
- const [LazyMoonPayProvider, setLazyMoonPayProvider] = useState(null);
21
- useEffect(() => {
22
- const _LazyMoonPayBuyWidget = lazy(() => import('@moonpay/moonpay-react').then(mod => ({ default: mod.MoonPayBuyWidget })));
23
- const _LazyMoonPaySellWidget = lazy(() => import('@moonpay/moonpay-react').then(mod => ({ default: mod.MoonPaySellWidget })));
24
- const _LazyMoonPayProvider = lazy(() => import('@moonpay/moonpay-react').then(mod => ({ default: mod.MoonPayProvider })));
25
- setLazyMoonPayBuyWidget(_LazyMoonPayBuyWidget);
26
- setLazyMoonPaySellWidget(_LazyMoonPaySellWidget);
27
- setLazyMoonPayProvider(_LazyMoonPayProvider);
28
- }, []);
29
- const apiKey = onRampPurchase.testMode ? MOONPAY_PUBLISHABLE_KEY_TEST : MOONPAY_PUBLISHABLE_KEY;
30
- const onUrlSignatureRequested = useCallback((url) => __awaiter(void 0, void 0, void 0, function* () {
31
- if (!para.getUserId() || !onRampPurchase.walletType) {
32
- throw new Error('missing required fields');
33
- }
34
- const res = yield para.ctx.client.signMoonPayUrl(para.getUserId(), {
35
- url,
36
- type: onRampPurchase.walletType,
37
- cosmosPrefix: para.cosmosPrefix,
38
- testMode: onRampPurchase.testMode,
39
- walletId: onRampPurchase.walletId || undefined,
40
- externalWalletAddress: onRampPurchase.externalWalletAddress || undefined,
41
- });
42
- return res.data.signature;
43
- }), [onRampPurchase.walletId, onRampPurchase.walletType, para.cosmosPrefix, onRampPurchase.testMode, para]);
44
- const { currencyCodes, defaultCurrencyCode } = useMemo(() => getCurrencyCodes(onRampConfig, {
45
- provider: OnRampProvider.MOONPAY,
46
- walletType: onRampPurchase.walletType,
47
- purchaseType: onRampPurchase.type,
48
- }), [onRampPurchase.walletType, onRampPurchase.type, onRampConfig.assetInfo, onRampConfig === null || onRampConfig === void 0 ? void 0 : onRampConfig.allowedAssets]);
49
- const onTransactionCompleted = useCallback((payload) => __awaiter(void 0, void 0, void 0, function* () {
50
- try {
51
- const [network, asset] = reverseCurrencyLookup(onRampConfig.assetInfo, OnRampProvider.MOONPAY, payload.quoteCurrency.code);
52
- const updated = yield para.ctx.client.updateOnRampPurchase({
53
- userId: para.getUserId(),
54
- walletId: onRampPurchase.walletId,
55
- purchaseId: onRampPurchase.id,
56
- externalWalletAddress: onRampPurchase.externalWalletAddress,
57
- updates: {
58
- fiatQuantity: payload.baseCurrencyAmount.toString(),
59
- fiat: payload.baseCurrency.code,
60
- network,
61
- asset,
62
- assetQuantity: payload.quoteCurrencyAmount.toString(),
63
- status: OnRampPurchaseStatus.FINISHED,
64
- },
65
- });
66
- setOnRampPurchase(updated);
67
- if (!isEmbedded) {
68
- setTimeout(() => {
69
- window.close();
70
- }, 5000);
71
- }
72
- }
73
- catch (e) {
74
- console.error(e);
75
- }
76
- }), [onRampPurchase.walletId, onRampPurchase.id, onRampPurchase.externalWalletAddress, isEmbedded]);
77
- const onInitiateDeposit = useCallback((payload) => __awaiter(void 0, void 0, void 0, function* () {
78
- const txHash = yield offRampSend(para, onRampPurchase, setOnRampPurchase, {
79
- assetQuantity: payload.cryptoCurrencyAmount,
80
- fiatQuantity: payload.fiatCurrencyAmount || undefined,
81
- fiat: payload.fiatCurrency.code.toUpperCase(),
82
- destinationAddress: payload.depositWalletAddress,
83
- contractAddress: payload.cryptoCurrency.contractAddress,
84
- chainId: payload.cryptoCurrency.chainId,
85
- });
86
- return { depositId: txHash, cancelTransactionOnError: false };
87
- }), [
88
- para,
89
- onRampPurchase.id,
90
- onRampPurchase.testMode,
91
- onRampPurchase.walletId,
92
- onRampPurchase.walletType,
93
- setOnRampPurchase,
94
- ]);
95
- const embed = useMemo(() => {
96
- if (!LazyMoonPayBuyWidget || !LazyMoonPaySellWidget) {
97
- return null;
98
- }
99
- const walletAddresses = currencyCodes.reduce((acc, code) => {
100
- return Object.assign(Object.assign({}, acc), { [code.toLowerCase()]: onRampPurchase.address });
101
- }, {});
102
- return onRampPurchase.type === 'BUY' ? (_jsx(LazyMoonPayBuyWidget, { variant: "embedded", baseCurrencyCode: onRampPurchase.fiat, baseCurrencyAmount: onRampPurchase.fiatQuantity, showOnlyCurrencies: currencyCodes.join(','), defaultCurrencyCode: defaultCurrencyCode, walletAddresses: JSON.stringify(walletAddresses), visible: true, theme: isDark ? 'dark' : 'light', style: {
103
- height: '100%',
104
- width: '100%',
105
- border: 'none',
106
- borderRadius: 0,
107
- margin: 0,
108
- }, onTransactionCompleted: onTransactionCompleted, onUrlSignatureRequested: onUrlSignatureRequested })) : (_jsx(LazyMoonPaySellWidget, { variant: "embedded", refundWalletAddresses: JSON.stringify(walletAddresses), visible: true, theme: isDark ? 'dark' : 'light', style: {
109
- height: '100%',
110
- width: '100%',
111
- border: 'none',
112
- borderRadius: 0,
113
- margin: 0,
114
- }, showOnlyCurrencies: currencyCodes.join(','), defaultCurrencyCode: currencyCodes[0], onInitiateDeposit: onInitiateDeposit, onTransactionCompleted: onTransactionCompleted, onUrlSignatureRequested: onUrlSignatureRequested }));
115
- }, [
116
- onRampPurchase.type,
117
- onRampPurchase.address,
118
- onRampPurchase.walletId,
119
- onRampPurchase.walletType,
120
- defaultCurrencyCode,
121
- currencyCodes,
122
- onInitiateDeposit,
123
- onTransactionCompleted,
124
- onUrlSignatureRequested,
125
- isDark,
126
- LazyMoonPayBuyWidget,
127
- LazyMoonPaySellWidget,
128
- ]);
129
- if (!LazyMoonPayProvider) {
130
- return null;
131
- }
132
- return (_jsx(Container, { isEmbedded: isEmbedded, children: _jsx(LazyMoonPayProvider, { apiKey: apiKey, debug: onRampPurchase.testMode, children: embed }) }));
133
- };
134
- export default MoonPayEmbed;
135
- const Container = styled.div `
136
- width: ${({ isEmbedded }) => (isEmbedded ? '100%' : '100vw')};
137
- height: ${({ isEmbedded }) => (isEmbedded ? '640px' : '100vh')};
138
-
139
- iframe {
140
- border: 0 !important;
141
- }
142
- `;
@@ -1,65 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { CpslButton, CpslIcon, CpslQrCode, CpslSpinner, CpslText } from '@getpara/react-components';
3
- import styled from 'styled-components';
4
- import { useCopyToClipboard } from '../hooks/index.js';
5
- import { isMobile } from '@getpara/web-sdk';
6
- export const QRCode = ({ link, imageSrc, icon, qrSize = 202, spinnerSize = 60 }) => {
7
- const [isCopied, copy] = useCopyToClipboard();
8
- const isMobileScreen = isMobile();
9
- const handleCopy = () => {
10
- copy(link);
11
- };
12
- return (_jsxs(QRContainer, { "$isMobile": isMobileScreen, children: [isMobileScreen && (_jsxs(MobileCopyButton, { fullWidth: true, onClick: handleCopy, children: [_jsx(CopyIcon, { slot: "start", icon: isCopied ? 'check' : 'copy' }), _jsx(CpslText, { variant: "bodyS", children: isCopied ? 'Copied' : 'Copy Link Instead' })] })), !link ? (_jsx(LoadingContainer, { "$size": qrSize, children: _jsx(CpslSpinner, { size: spinnerSize }) })) : (_jsx(StyledQRCode, { url: link, size: qrSize, icon: icon, imageSrc: imageSrc })), !isMobileScreen && (_jsxs(CopyButton, { size: "small", onClick: handleCopy, children: [_jsx(CopyIcon, { slot: "start", icon: isCopied ? 'check' : 'copy' }), _jsx(CpslText, { variant: "body2XS", children: isCopied ? 'Copied' : 'Copy Link Instead' })] }))] }));
13
- };
14
- const QRContainer = styled.div `
15
- display: flex;
16
- flex-direction: column;
17
- justify-content: center;
18
- align-items: center;
19
- border: 1px solid;
20
- border-color: var(--cpsl-color-background-16);
21
- border-radius: 16px;
22
- background-color: white;
23
- overflow: hidden;
24
- padding-bottom: ${({ $isMobile }) => ($isMobile ? '0px' : '16px')};
25
- padding-top: ${({ $isMobile }) => ($isMobile ? '16px' : '0px')};
26
- `;
27
- const StyledQRCode = styled(CpslQrCode) `
28
- --qr-box-shadow: none;
29
- --qr-border-radius: 0px;
30
- `;
31
- const CopyButton = styled(CpslButton) `
32
- --button-primary-color: var(--cpsl-color-text-contrast);
33
- --button-primary-background-color: var(--cpsl-color-background-4);
34
-
35
- --button-primary-hover-color: var(--cpsl-color-text-contrast);
36
- --button-primary-hover-background-color: var(--cpsl-color-background-16);
37
-
38
- --button-primary-active-color: var(--cpsl-color-text-contrast);
39
- --button-primary-active-background-color: var(--cpsl-color-background-4);
40
-
41
- --button-padding-start: 8px;
42
- --button-padding-end: 8px;
43
- --button-padding-top: 2px;
44
- --button-padding-bottom: 2px;
45
-
46
- --button-border-radius: 1000px;
47
- `;
48
- const MobileCopyButton = styled(CopyButton) `
49
- --button-padding-top: 4px;
50
- --button-padding-bottom: 4px;
51
-
52
- padding: 0px 12px;
53
- `;
54
- const CopyIcon = styled(CpslIcon) `
55
- --width: 16px;
56
- --height: 16px;
57
- --icon-color: var(--cpsl-color-text-contrast);
58
- `;
59
- const LoadingContainer = styled.div `
60
- display: flex;
61
- justify-content: center;
62
- align-items: center;
63
- height: ${({ $size }) => `${$size}px`};
64
- width: ${({ $size }) => `${$size}px`};
65
- `;
@@ -1,95 +0,0 @@
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 } from "react/jsx-runtime";
11
- import { useEffect, useRef } from 'react';
12
- import { RampInstantSDK } from '@ramp-network/ramp-instant-sdk';
13
- import { Network, OnRampAsset, OnRampProvider, getPortalBaseURL } from '@getpara/web-sdk';
14
- import { getChainId, getContractAddressFromAsset, getCurrencyCodes, reverseCurrencyLookup, offRampSend, } from '../utils/index.js';
15
- const TEST_MODE_FORBIDDEN = ['ETH_ETH', 'ETH_USDC'];
16
- export const RampEmbed = ({ para, appName, onRampConfig, onRampPurchase, isEmbedded, apiKey, onClose, setOnRampPurchase, }) => {
17
- const { currencyCodes } = getCurrencyCodes(onRampConfig, {
18
- provider: OnRampProvider.RAMP,
19
- purchaseType: onRampPurchase.type,
20
- walletType: onRampPurchase.walletType,
21
- });
22
- const isMounted = useRef(false);
23
- useEffect(() => {
24
- if (!isMounted.current) {
25
- try {
26
- const widget = new RampInstantSDK({
27
- hostAppName: appName,
28
- swapAsset: currencyCodes.filter(code => !onRampPurchase.testMode || !TEST_MODE_FORBIDDEN.includes(code)).join(','),
29
- fiatValue: onRampPurchase.fiatQuantity,
30
- fiatCurrency: onRampPurchase.fiat,
31
- hostLogoUrl: `${getPortalBaseURL(para.ctx)}/wordmark_black.svg`,
32
- hostApiKey: apiKey,
33
- userAddress: onRampPurchase.address,
34
- userEmailAddress: para.getEmail(),
35
- url: (onRampPurchase === null || onRampPurchase === void 0 ? void 0 : onRampPurchase.testMode) ? 'https://app.demo.ramp.network' : 'https://app.ramp.network',
36
- enabledFlows: [onRampPurchase.type === 'BUY' ? 'ONRAMP' : 'OFFRAMP'],
37
- useSendCryptoCallback: true,
38
- variant: 'embedded-mobile',
39
- containerNode: document.getElementById('ramp-container'),
40
- })
41
- .on('PURCHASE_CREATED', (e) => __awaiter(void 0, void 0, void 0, function* () {
42
- const p = e.payload.purchase;
43
- const [network, asset] = onRampPurchase.testMode
44
- ? [Network.ETHEREUM, OnRampAsset.ETHEREUM]
45
- : reverseCurrencyLookup(onRampConfig.assetInfo, OnRampProvider.RAMP, p.asset.symbol) || [];
46
- const updated = yield para.ctx.client.updateOnRampPurchase({
47
- userId: para.getUserId(),
48
- walletId: onRampPurchase.walletId,
49
- externalWalletAddress: onRampPurchase.externalWalletAddress,
50
- purchaseId: onRampPurchase.id,
51
- updates: {
52
- providerKey: p.id,
53
- fiatQuantity: p.fiatValue,
54
- fiat: p.fiatCurrency,
55
- assetQuantity: p.cryptoAmount,
56
- asset,
57
- network,
58
- },
59
- });
60
- setOnRampPurchase(updated);
61
- }))
62
- .on('WIDGET_CLOSE', () => __awaiter(void 0, void 0, void 0, function* () {
63
- onClose === null || onClose === void 0 ? void 0 : onClose();
64
- if (!isEmbedded) {
65
- setTimeout(() => {
66
- window.close();
67
- }, 5000);
68
- }
69
- }))
70
- .onSendCrypto((assetInfo, amount, address) => __awaiter(void 0, void 0, void 0, function* () {
71
- try {
72
- const [network, asset] = reverseCurrencyLookup(onRampConfig.assetInfo, OnRampProvider.RAMP, assetInfo.symbol);
73
- const txHash = yield offRampSend(para, onRampPurchase, setOnRampPurchase, {
74
- assetQuantity: amount,
75
- destinationAddress: address,
76
- contractAddress: getContractAddressFromAsset(network, asset),
77
- chainId: getChainId(network),
78
- testMode: onRampPurchase.testMode,
79
- });
80
- return { txHash };
81
- }
82
- catch (e) {
83
- console.error(e);
84
- }
85
- }));
86
- widget.show();
87
- isMounted.current = true;
88
- }
89
- catch (e) {
90
- console.error(e);
91
- }
92
- }
93
- }, []);
94
- return _jsx("div", { id: "ramp-container", style: { minWidth: '320px', width: '100%', height: '767px' } });
95
- };
@@ -1,128 +0,0 @@
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 } from "react/jsx-runtime";
11
- import React, { useCallback, useEffect, useMemo, useState } from 'react';
12
- import { loadStripeOnramp } from '@stripe/crypto';
13
- import { Network, OnRampAsset, OnRampProvider, OnRampPurchaseStatus } from '@getpara/web-sdk';
14
- import { CpslSpinner } from '@getpara/react-components';
15
- import { SpinnerContainer } from './common.js';
16
- import styled from 'styled-components';
17
- export const STRIPE_PUBLISHABLE_KEY = 'pk_live_51MvquNGrzDeP5yP9EgVSMBPQbrbg0oHDjPIIXypePd0jzOFjbadyfO7wBKLHhUtbKIUiEUVC3YYcTJyAmJ8xA7JE00T2UDfYKz';
18
- export const STRIPE_PUBLISHABLE_KEY_TEST = 'pk_test_51Q2z5k2epVn9Kq0ZSbUzuetKb4azH6E6UPcvWmjRxvHmxLAJbIK0pwDbPQo63W9OyDng337ntNu3ZXx3AJ7MhFmR00XgfRmPgP';
19
- const AssetCodes = {
20
- eth: OnRampAsset.ETHEREUM,
21
- matic: OnRampAsset.POLYGON,
22
- sol: OnRampAsset.SOLANA,
23
- usdc: OnRampAsset.USDC,
24
- };
25
- const NetworkCodes = {
26
- base: Network.BASE,
27
- ethereum: Network.ETHEREUM,
28
- polygon: Network.POLYGON,
29
- solana: Network.SOLANA,
30
- };
31
- const CryptoElementsContext = React.createContext(null);
32
- CryptoElementsContext.displayName = 'CryptoElementsContext';
33
- const useOnrampSessionListener = (type, session, callback) => {
34
- React.useEffect(() => {
35
- if (session && callback) {
36
- const listener = e => callback(e.payload);
37
- session.addEventListener(type, listener);
38
- return () => {
39
- session.removeEventListener(type, listener);
40
- };
41
- }
42
- return () => { };
43
- }, [session, callback, type]);
44
- };
45
- export const StripeEmbed = ({ para, isDark, isEmbedded, onRampPurchase, setOnRampPurchase }) => {
46
- const [isReady, setIsReady] = useState(false);
47
- const isStripeEmbed = useMemo(() => onRampPurchase.provider === OnRampProvider.STRIPE, [onRampPurchase]);
48
- const clientSecret = useMemo(() => ((onRampPurchase === null || onRampPurchase === void 0 ? void 0 : onRampPurchase.provider) === OnRampProvider.STRIPE ? onRampPurchase === null || onRampPurchase === void 0 ? void 0 : onRampPurchase.providerKey : undefined), [onRampPurchase === null || onRampPurchase === void 0 ? void 0 : onRampPurchase.provider, onRampPurchase === null || onRampPurchase === void 0 ? void 0 : onRampPurchase.providerKey]);
49
- const [stripeOnRamp, setStripeOnRamp] = useState();
50
- const onrampElementRef = React.useRef(null);
51
- const [session, setSession] = React.useState();
52
- useEffect(() => {
53
- const containerRef = onrampElementRef.current;
54
- if (containerRef) {
55
- // NB: ideally we want to be able to hot swap/update onramp iframe
56
- // This currently results a flash if one needs to mint a new session when they need to udpate fixed transaction details
57
- containerRef.innerHTML = '';
58
- if (clientSecret && stripeOnRamp) {
59
- setSession(stripeOnRamp
60
- .createSession({
61
- clientSecret,
62
- appearance: { theme: isDark ? 'dark' : 'light' },
63
- })
64
- .mount(containerRef));
65
- }
66
- }
67
- }, [clientSecret, stripeOnRamp]);
68
- useEffect(() => {
69
- loadStripeOnramp((onRampPurchase === null || onRampPurchase === void 0 ? void 0 : onRampPurchase.testMode) ? STRIPE_PUBLISHABLE_KEY_TEST : STRIPE_PUBLISHABLE_KEY).then(setStripeOnRamp);
70
- }, []);
71
- const onReady = useCallback(() => {
72
- setIsReady(true);
73
- }, []);
74
- const onSessionChange = useCallback((_a) => __awaiter(void 0, [_a], void 0, function* ({ session }) {
75
- if (!isStripeEmbed) {
76
- return;
77
- }
78
- switch (session.status) {
79
- case 'fulfillment_processing':
80
- case 'fulfillment_complete':
81
- const updatedPurchase = yield para.ctx.client.updateOnRampPurchase({
82
- userId: para.getUserId(),
83
- walletId: onRampPurchase.walletId,
84
- externalWalletAddress: onRampPurchase.externalWalletAddress,
85
- purchaseId: onRampPurchase.id,
86
- updates: {
87
- status: OnRampPurchaseStatus.FINISHED,
88
- fiatQuantity: session.quote.source_amount,
89
- fiat: session.quote.source_currency.asset_code,
90
- network: NetworkCodes[session.quote.destination_currency.currency_network],
91
- asset: AssetCodes[session.quote.destination_currency.asset_code],
92
- assetQuantity: session.quote.destination_amount,
93
- providerKey: null,
94
- },
95
- });
96
- setOnRampPurchase(updatedPurchase);
97
- if (!isEmbedded) {
98
- setTimeout(() => {
99
- window.close();
100
- }, 5000);
101
- }
102
- break;
103
- default:
104
- break;
105
- }
106
- }), [isStripeEmbed]);
107
- useOnrampSessionListener('onramp_ui_loaded', session, onReady);
108
- useOnrampSessionListener('onramp_session_updated', session, onSessionChange);
109
- return (_jsxs(OuterContainer, { children: [_jsx(Container, { isReady: isReady, ref: onrampElementRef }), !isReady && (_jsx(SpinnerContainer, { style: { width: '100%', height: '100%', flex: 1 }, children: _jsx(CpslSpinner, { size: 100 }) }))] }));
110
- };
111
- const OuterContainer = styled.div `
112
- height: 100%;
113
- width: 100%;
114
- display: flex;
115
- flex: 1;
116
- align-items: center;
117
- justify-content: center;
118
- `;
119
- const Container = styled.div `
120
- height: 100%;
121
- width: 100%;
122
- display: ${({ isReady }) => (isReady ? 'flex' : 'none')};
123
- justify-content: center;
124
-
125
- & > iframe {
126
- height: 100%;
127
- }
128
- `;
@@ -1,65 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { CpslAvatar, CpslIcon, CpslText } from '@getpara/react-components';
3
- import parsePhoneNumberFromString from 'libphonenumber-js';
4
- import styled from 'styled-components';
5
- function defaultDisplayName(authType, identifier) {
6
- switch (authType) {
7
- case 'email':
8
- return identifier.toLowerCase();
9
- case 'phone':
10
- const parsed = parsePhoneNumberFromString(identifier);
11
- return `+${parsed.countryCallingCode} ${parsed.formatNational()}`;
12
- case 'farcaster':
13
- return `@${identifier}`;
14
- case 'telegram':
15
- return `Telegram User @${identifier}`;
16
- default:
17
- return null;
18
- }
19
- }
20
- export const UserIdentifier = ({ identifier, authType, displayName, pfpUrl }) => {
21
- let icon;
22
- switch (authType) {
23
- case 'email':
24
- icon = 'mail';
25
- break;
26
- case 'phone':
27
- icon = 'phone';
28
- break;
29
- case 'farcaster':
30
- icon = 'farcasterBrand';
31
- break;
32
- case 'telegram':
33
- icon = 'telegramBrand';
34
- break;
35
- }
36
- return (_jsxs(Container, { children: [_jsx(IconContainer, { children: pfpUrl ? (_jsx(Avatar, { src: pfpUrl, size: "20px" })) : (_jsx(Icon, { icon: icon, size: authType === 'telegram' ? '20px' : '13px' })) }), _jsx(IdentifierText, { variant: "bodyS", weight: "medium", children: displayName || defaultDisplayName(authType, identifier) })] }));
37
- };
38
- const Container = styled.div `
39
- padding: 8px 12px 8px 8px;
40
- border-radius: 1000px;
41
- background-color: var(--cpsl-color-background-4);
42
- display: flex;
43
- align-items: center;
44
- justify-content: flex-start;
45
- gap: 4px;
46
- `;
47
- const IdentifierText = styled(CpslText) `
48
- --color-override: var(--cpsl-color-background-96);
49
- `;
50
- const IconContainer = styled.div `
51
- display: flex;
52
- background: var(--cpsl-color-background-0);
53
- align-items: center;
54
- justify-content: center;
55
- border-radius: 1000px;
56
- width: 20px;
57
- height: 20px;
58
- `;
59
- const Icon = styled(CpslIcon) `
60
- --icon-color: var(--cpsl-color-text-primary);
61
- `;
62
- const Avatar = styled(CpslAvatar) `
63
- --container-border-width: 0;
64
- --container-padding: 0;
65
- `;
@@ -1,44 +0,0 @@
1
- import { CpslButton, CpslInput, CpslText } from '@getpara/react-components';
2
- import styled from 'styled-components';
3
- export const SpinnerContainer = styled.div `
4
- display: flex;
5
- align-items: center;
6
- justify-content: center;
7
- `;
8
- export const CenteredColumnContainer = styled.div `
9
- width: 100%;
10
- height: 100%;
11
- align-self: center;
12
- display: flex;
13
- flex-direction: column;
14
- align-items: center;
15
- gap: 8px;
16
- `;
17
- export const FilledDisabledInput = styled(CpslInput) `
18
- --container-border-color: var(--cpsl-color-input-border-placeholder);
19
- --container-background-color: var(--cpsl-color-background-0);
20
- --input-background-color: transparent;
21
- --input-font-weight: 500;
22
- --input-color: var(--cpsl-color-text-secondary) !important;
23
- `;
24
- export const FullWidthFilledDisabledInput = styled(FilledDisabledInput) `
25
- width: 100%;
26
- `;
27
- export const CenteredText = styled(CpslText) `
28
- width: 100%;
29
- text-align: center;
30
- `;
31
- export const HeaderButton = styled(CpslButton) `
32
- flex: 0;
33
- --button-padding-top: 2px;
34
- --button-padding-bottom: 2px;
35
- --button-padding-start: 2px;
36
- --button-padding-end: 2px;
37
- --button-border-radius: 1000px;
38
- --button-background-color: var(--cpsl-color-background-4);
39
-
40
- cpsl-icon {
41
- --height: 20px;
42
- --width: 20px;
43
- }
44
- `;
@@ -1,8 +0,0 @@
1
- export * from './MoonPayEmbed.js';
2
- export * from './RampEmbed.js';
3
- export * from './StripeEmbed.js';
4
- export * from './common.js';
5
- export * from './HeroSpinner.js';
6
- export * from './KnownDevices.js';
7
- export * from './QRCode.js';
8
- export * from './UserIdentifier.js';