@getpara/react-common 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/classes/ParaInternal.d.ts +25 -0
- package/dist/classes/ParaInternal.js +20 -0
- package/dist/classes/index.d.ts +1 -0
- package/dist/classes/index.js +1 -0
- package/dist/components/HeroSpinner.d.ts +9 -0
- package/dist/components/HeroSpinner.js +37 -0
- package/dist/components/KnownDevices.d.ts +8 -0
- package/dist/components/KnownDevices.js +39 -0
- package/dist/components/MoonPayEmbed.d.ts +3 -0
- package/dist/components/MoonPayEmbed.js +142 -0
- package/dist/components/QRCode.d.ts +10 -0
- package/dist/components/QRCode.js +65 -0
- package/dist/components/RampEmbed.d.ts +4 -0
- package/dist/components/RampEmbed.js +95 -0
- package/dist/components/StripeEmbed.d.ts +4 -0
- package/dist/components/StripeEmbed.js +128 -0
- package/dist/components/UserIdentifier.d.ts +2 -0
- package/dist/components/UserIdentifier.js +65 -0
- package/dist/components/common.d.ts +9 -0
- package/dist/components/common.js +44 -0
- package/dist/components/index.d.ts +8 -0
- package/dist/components/index.js +8 -0
- package/dist/constants/aaguiMetadata.d.ts +140 -0
- package/dist/constants/aaguiMetadata.js +140 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/useCopyToClipboard.d.ts +3 -0
- package/dist/hooks/useCopyToClipboard.js +37 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/types/index.d.ts +16 -0
- package/dist/types/index.js +1 -0
- package/dist/utils/formatBiometricHints.d.ts +15 -0
- package/dist/utils/formatBiometricHints.js +49 -0
- package/dist/utils/formatPhoneNumber.d.ts +1 -0
- package/dist/utils/formatPhoneNumber.js +9 -0
- package/dist/utils/getBrowserName.d.ts +1 -0
- package/dist/utils/getBrowserName.js +2 -0
- package/dist/utils/getDeviceLogo.d.ts +2 -0
- package/dist/utils/getDeviceLogo.js +31 -0
- package/dist/utils/getDeviceModelName.d.ts +1 -0
- package/dist/utils/getDeviceModelName.js +13 -0
- package/dist/utils/index.d.ts +35 -0
- package/dist/utils/index.js +92 -0
- package/dist/utils/offRampSend.d.ts +7 -0
- package/dist/utils/offRampSend.js +67 -0
- package/package.json +44 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import ParaWeb from '@getpara/web-sdk';
|
|
2
|
+
export declare class ParaInternal extends ParaWeb {
|
|
3
|
+
getSupportedCreateAuthMethods: () => Promise<Set<import("@getpara/web-sdk").AuthMethod>>;
|
|
4
|
+
isUsingExternalWallet: () => boolean;
|
|
5
|
+
getTransmissionKeyShares: ({ isForNewDevice }?: {
|
|
6
|
+
isForNewDevice?: boolean;
|
|
7
|
+
}) => Promise<any>;
|
|
8
|
+
userSetupAfterLogin: () => Promise<{
|
|
9
|
+
data: {
|
|
10
|
+
partnerId?: string;
|
|
11
|
+
needsWallet?: boolean;
|
|
12
|
+
sessionLookupId: string;
|
|
13
|
+
};
|
|
14
|
+
}>;
|
|
15
|
+
setLoginEncryptionKeyPair: (keyPair?: import("node-forge").pki.rsa.KeyPair) => Promise<void>;
|
|
16
|
+
getPortalURL: (partnerId?: string) => Promise<string>;
|
|
17
|
+
isProviderModalDisabled: () => boolean;
|
|
18
|
+
supportedAuthMethods: (auth: import("@getpara/user-management-client").Auth) => Promise<Set<import("@getpara/web-sdk").AuthMethod>>;
|
|
19
|
+
getUserBiometricLocationHints: () => Promise<import("@getpara/user-management-client").BiometricLocationHint[]>;
|
|
20
|
+
exitLoops: () => void;
|
|
21
|
+
exitLogin: () => void;
|
|
22
|
+
exitAccountCreation: () => void;
|
|
23
|
+
exitOAuth: () => void;
|
|
24
|
+
exitFarcaster: () => void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ParaInternal.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ParaInternal.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IconType } from '@getpara/react-components';
|
|
2
|
+
import { PropsWithChildren, ReactNode } from 'react';
|
|
3
|
+
type Status = 'loading' | 'error' | 'inactive';
|
|
4
|
+
export declare function HeroSpinner({ icon, status, text, }: PropsWithChildren<{
|
|
5
|
+
icon?: IconType;
|
|
6
|
+
status?: Status;
|
|
7
|
+
text?: ReactNode;
|
|
8
|
+
}>): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
`;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BiometricHints } from '../utils/index.js';
|
|
2
|
+
interface KnownDevicesProps {
|
|
3
|
+
hints: BiometricHints;
|
|
4
|
+
link?: string;
|
|
5
|
+
showCurrentDevice?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const KnownDevices: ({ hints, link, showCurrentDevice }: KnownDevicesProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
`;
|
|
@@ -0,0 +1,142 @@
|
|
|
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
|
+
`;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IconType } from '@getpara/react-components';
|
|
2
|
+
interface QRCodeProps {
|
|
3
|
+
link?: string;
|
|
4
|
+
icon?: IconType;
|
|
5
|
+
imageSrc?: string;
|
|
6
|
+
qrSize?: number;
|
|
7
|
+
spinnerSize?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare const QRCode: ({ link, imageSrc, icon, qrSize, spinnerSize }: QRCodeProps) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
`;
|
|
@@ -0,0 +1,95 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Props } from '../types/index.js';
|
|
2
|
+
export declare const STRIPE_PUBLISHABLE_KEY = "pk_live_51MvquNGrzDeP5yP9EgVSMBPQbrbg0oHDjPIIXypePd0jzOFjbadyfO7wBKLHhUtbKIUiEUVC3YYcTJyAmJ8xA7JE00T2UDfYKz";
|
|
3
|
+
export declare const STRIPE_PUBLISHABLE_KEY_TEST = "pk_test_51Q2z5k2epVn9Kq0ZSbUzuetKb4azH6E6UPcvWmjRxvHmxLAJbIK0pwDbPQo63W9OyDng337ntNu3ZXx3AJ7MhFmR00XgfRmPgP";
|
|
4
|
+
export declare const StripeEmbed: ({ para, isDark, isEmbedded, onRampPurchase, setOnRampPurchase }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,128 @@
|
|
|
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
|
+
`;
|