@getpara/react-common 2.0.0-alpha.3 → 2.0.0-alpha.6
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/chunk-GOCCUU3Z.js +42 -0
- package/dist/classes/ParaInternal.d.ts +1 -1
- package/dist/classes/ParaInternal.js +22 -0
- package/dist/classes/index.js +2 -0
- package/dist/components/HeroSpinner.js +55 -0
- package/dist/components/KnownDevices.js +60 -0
- package/dist/components/MoonPayEmbed.js +184 -0
- package/dist/components/NetworkSpeedBanner.d.ts +5 -0
- package/dist/components/NetworkSpeedBanner.js +80 -0
- package/dist/components/QRCode.js +80 -0
- package/dist/components/RampEmbed.js +103 -0
- package/dist/components/StripeEmbed.d.ts +1 -1
- package/dist/components/StripeEmbed.js +138 -0
- package/dist/components/UserIdentifier.js +66 -0
- package/dist/components/common.d.ts +3 -3
- package/dist/components/common.js +54 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +10 -0
- package/dist/constants/aaguiMetadata.js +145 -0
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/useCopyToClipboard.js +36 -0
- package/dist/index.js +5 -1279
- package/dist/package.json +6 -0
- package/dist/types/externalWalletCommon.d.ts +4 -2
- package/dist/types/externalWalletCommon.js +32 -0
- package/dist/types/index.js +2 -0
- package/dist/utils/formatBiometricHints.js +51 -0
- package/dist/utils/getBrowserName.js +7 -0
- package/dist/utils/getDeviceLogo.js +36 -0
- package/dist/utils/getDeviceModelName.js +21 -0
- package/dist/utils/getExternalWalletDisplayName.d.ts +2 -5
- package/dist/utils/getExternalWalletDisplayName.js +22 -0
- package/dist/utils/index.d.ts +7 -2
- package/dist/utils/index.js +124 -0
- package/dist/utils/offRampSend.js +75 -0
- package/package.json +4 -4
- package/dist/index.js.br +0 -0
- package/dist/index.js.gz +0 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
__async
|
|
4
|
+
} from "../chunk-GOCCUU3Z.js";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
7
|
+
import { loadStripeOnramp } from "@stripe/crypto";
|
|
8
|
+
import { Network, OnRampAsset, OnRampProvider, OnRampPurchaseStatus } from "@getpara/web-sdk";
|
|
9
|
+
import { CpslSpinner } from "@getpara/react-components";
|
|
10
|
+
import { SpinnerContainer } from "./common.js";
|
|
11
|
+
import styled from "styled-components";
|
|
12
|
+
const STRIPE_PUBLISHABLE_KEY = "pk_live_51MvquNGrzDeP5yP9EgVSMBPQbrbg0oHDjPIIXypePd0jzOFjbadyfO7wBKLHhUtbKIUiEUVC3YYcTJyAmJ8xA7JE00T2UDfYKz";
|
|
13
|
+
const STRIPE_PUBLISHABLE_KEY_TEST = "pk_test_51MvquNGrzDeP5yP98WgPaAUgQ50I3OpfPhVfiLO47FBHepJnZRPO62IzZY2uxT5ovhSS10RwcTcnaVil1mcJOzIi00dHapODdS";
|
|
14
|
+
const AssetCodes = {
|
|
15
|
+
eth: OnRampAsset.ETHEREUM,
|
|
16
|
+
matic: OnRampAsset.POLYGON,
|
|
17
|
+
sol: OnRampAsset.SOLANA,
|
|
18
|
+
usdc: OnRampAsset.USDC
|
|
19
|
+
};
|
|
20
|
+
const NetworkCodes = {
|
|
21
|
+
base: Network.BASE,
|
|
22
|
+
ethereum: Network.ETHEREUM,
|
|
23
|
+
polygon: Network.POLYGON,
|
|
24
|
+
solana: Network.SOLANA
|
|
25
|
+
};
|
|
26
|
+
const CryptoElementsContext = React.createContext(null);
|
|
27
|
+
CryptoElementsContext.displayName = "CryptoElementsContext";
|
|
28
|
+
const useOnrampSessionListener = (type, session, callback) => {
|
|
29
|
+
React.useEffect(() => {
|
|
30
|
+
if (session && callback) {
|
|
31
|
+
const listener = (e) => callback(e.payload);
|
|
32
|
+
session.addEventListener(type, listener);
|
|
33
|
+
return () => {
|
|
34
|
+
session.removeEventListener(type, listener);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return () => {
|
|
38
|
+
};
|
|
39
|
+
}, [session, callback, type]);
|
|
40
|
+
};
|
|
41
|
+
const StripeEmbed = ({ para, isDark, isEmbedded, onRampPurchase, setOnRampPurchase }) => {
|
|
42
|
+
const [isReady, setIsReady] = useState(false);
|
|
43
|
+
const isStripeEmbed = useMemo(() => onRampPurchase.provider === OnRampProvider.STRIPE, [onRampPurchase]);
|
|
44
|
+
const clientSecret = useMemo(
|
|
45
|
+
() => (onRampPurchase == null ? void 0 : onRampPurchase.provider) === OnRampProvider.STRIPE ? onRampPurchase == null ? void 0 : onRampPurchase.providerKey : void 0,
|
|
46
|
+
[onRampPurchase == null ? void 0 : onRampPurchase.provider, onRampPurchase == null ? void 0 : onRampPurchase.providerKey]
|
|
47
|
+
);
|
|
48
|
+
const [stripeOnRamp, setStripeOnRamp] = useState();
|
|
49
|
+
const onrampElementRef = React.useRef(null);
|
|
50
|
+
const [session, setSession] = React.useState();
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
const containerRef = onrampElementRef.current;
|
|
53
|
+
if (containerRef) {
|
|
54
|
+
containerRef.innerHTML = "";
|
|
55
|
+
if (clientSecret && stripeOnRamp) {
|
|
56
|
+
setSession(
|
|
57
|
+
stripeOnRamp.createSession({
|
|
58
|
+
clientSecret,
|
|
59
|
+
appearance: { theme: isDark ? "dark" : "light" }
|
|
60
|
+
}).mount(containerRef)
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}, [clientSecret, stripeOnRamp]);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
loadStripeOnramp((onRampPurchase == null ? void 0 : onRampPurchase.testMode) ? STRIPE_PUBLISHABLE_KEY_TEST : STRIPE_PUBLISHABLE_KEY).then(setStripeOnRamp);
|
|
67
|
+
}, []);
|
|
68
|
+
const onReady = useCallback(() => {
|
|
69
|
+
setIsReady(true);
|
|
70
|
+
}, []);
|
|
71
|
+
const onSessionChange = useCallback(
|
|
72
|
+
(_0) => __async(void 0, [_0], function* ({ session: session2 }) {
|
|
73
|
+
if (!isStripeEmbed) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
switch (session2.status) {
|
|
77
|
+
case "fulfillment_processing":
|
|
78
|
+
case "fulfillment_complete":
|
|
79
|
+
const updatedPurchase = yield para.ctx.client.updateOnRampPurchase({
|
|
80
|
+
userId: para.getUserId(),
|
|
81
|
+
walletId: onRampPurchase.walletId,
|
|
82
|
+
externalWalletAddress: onRampPurchase.externalWalletAddress,
|
|
83
|
+
purchaseId: onRampPurchase.id,
|
|
84
|
+
updates: {
|
|
85
|
+
status: OnRampPurchaseStatus.FINISHED,
|
|
86
|
+
fiatQuantity: session2.quote.source_amount,
|
|
87
|
+
fiat: session2.quote.source_currency.asset_code,
|
|
88
|
+
network: NetworkCodes[session2.quote.destination_currency.currency_network],
|
|
89
|
+
asset: AssetCodes[session2.quote.destination_currency.asset_code],
|
|
90
|
+
assetQuantity: session2.quote.destination_amount,
|
|
91
|
+
providerKey: null
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
setOnRampPurchase(updatedPurchase);
|
|
95
|
+
if (!isEmbedded) {
|
|
96
|
+
setTimeout(() => {
|
|
97
|
+
if (typeof window !== "undefined") {
|
|
98
|
+
window.close();
|
|
99
|
+
}
|
|
100
|
+
}, 5e3);
|
|
101
|
+
}
|
|
102
|
+
break;
|
|
103
|
+
default:
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}),
|
|
107
|
+
[isStripeEmbed]
|
|
108
|
+
);
|
|
109
|
+
useOnrampSessionListener("onramp_ui_loaded", session, onReady);
|
|
110
|
+
useOnrampSessionListener("onramp_session_updated", session, onSessionChange);
|
|
111
|
+
return /* @__PURE__ */ jsxs(OuterContainer, { children: [
|
|
112
|
+
/* @__PURE__ */ jsx(Container, { isReady, ref: onrampElementRef }),
|
|
113
|
+
!isReady && /* @__PURE__ */ jsx(SpinnerContainer, { style: { width: "100%", height: "100%", flex: 1 }, children: /* @__PURE__ */ jsx(CpslSpinner, { size: 100 }) })
|
|
114
|
+
] });
|
|
115
|
+
};
|
|
116
|
+
const OuterContainer = styled.div`
|
|
117
|
+
height: 100%;
|
|
118
|
+
width: 100%;
|
|
119
|
+
display: flex;
|
|
120
|
+
flex: 1;
|
|
121
|
+
align-items: center;
|
|
122
|
+
justify-content: center;
|
|
123
|
+
`;
|
|
124
|
+
const Container = styled.div`
|
|
125
|
+
height: 100%;
|
|
126
|
+
width: 100%;
|
|
127
|
+
display: ${({ isReady }) => isReady ? "flex" : "none"};
|
|
128
|
+
justify-content: center;
|
|
129
|
+
|
|
130
|
+
& > iframe {
|
|
131
|
+
height: 100%;
|
|
132
|
+
}
|
|
133
|
+
`;
|
|
134
|
+
export {
|
|
135
|
+
STRIPE_PUBLISHABLE_KEY,
|
|
136
|
+
STRIPE_PUBLISHABLE_KEY_TEST,
|
|
137
|
+
StripeEmbed
|
|
138
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "../chunk-GOCCUU3Z.js";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { CpslAvatar, CpslIcon, CpslText } from "@getpara/react-components";
|
|
5
|
+
import styled from "styled-components";
|
|
6
|
+
import { displayPhoneNumber } from "@getpara/web-sdk";
|
|
7
|
+
import { getExternalWalletDisplayName } from "../utils/index.js";
|
|
8
|
+
function defaultDisplay(authInfo) {
|
|
9
|
+
const { authType, identifier, externalWallet } = authInfo;
|
|
10
|
+
switch (authType) {
|
|
11
|
+
case "email":
|
|
12
|
+
return { defaultName: identifier.toLowerCase(), defaultIcon: "mail" };
|
|
13
|
+
case "phone":
|
|
14
|
+
return { defaultName: displayPhoneNumber(identifier), defaultIcon: "phone" };
|
|
15
|
+
case "farcaster":
|
|
16
|
+
return { defaultName: `@${identifier}`, defaultIcon: "farcasterBrand" };
|
|
17
|
+
case "telegram":
|
|
18
|
+
return { defaultName: `Telegram User @${identifier}`, defaultIcon: "telegramBrand" };
|
|
19
|
+
case "externalWallet":
|
|
20
|
+
return { defaultName: getExternalWalletDisplayName(externalWallet), defaultIcon: "wallet" };
|
|
21
|
+
default:
|
|
22
|
+
return { defaultName: null, defaultIcon: null };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const UserIdentifier = ({ authInfo }) => {
|
|
26
|
+
if (!authInfo) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const { authType, displayName, pfpUrl } = authInfo;
|
|
30
|
+
const { defaultName, defaultIcon } = defaultDisplay(authInfo);
|
|
31
|
+
return /* @__PURE__ */ jsxs(Container, { children: [
|
|
32
|
+
/* @__PURE__ */ jsx(IconContainer, { children: pfpUrl ? /* @__PURE__ */ jsx(Avatar, { src: pfpUrl, size: "20px", variant: "round" }) : /* @__PURE__ */ jsx(Icon, { icon: defaultIcon, size: authType === "telegram" ? "20px" : "13px" }) }),
|
|
33
|
+
/* @__PURE__ */ jsx(IdentifierText, { variant: "bodyS", weight: "medium", children: displayName || defaultName })
|
|
34
|
+
] });
|
|
35
|
+
};
|
|
36
|
+
const Container = styled.div`
|
|
37
|
+
padding: 8px 12px 8px 8px;
|
|
38
|
+
border-radius: 1000px;
|
|
39
|
+
background-color: var(--cpsl-color-background-4);
|
|
40
|
+
display: flex;
|
|
41
|
+
align-items: center;
|
|
42
|
+
justify-content: flex-start;
|
|
43
|
+
gap: 4px;
|
|
44
|
+
`;
|
|
45
|
+
const IdentifierText = styled(CpslText)`
|
|
46
|
+
--color-override: var(--cpsl-color-background-96);
|
|
47
|
+
`;
|
|
48
|
+
const IconContainer = styled.div`
|
|
49
|
+
display: flex;
|
|
50
|
+
background: var(--cpsl-color-background-0);
|
|
51
|
+
align-items: center;
|
|
52
|
+
justify-content: center;
|
|
53
|
+
border-radius: 1000px;
|
|
54
|
+
width: 20px;
|
|
55
|
+
height: 20px;
|
|
56
|
+
`;
|
|
57
|
+
const Icon = styled(CpslIcon)`
|
|
58
|
+
--icon-color: var(--cpsl-color-text-primary);
|
|
59
|
+
`;
|
|
60
|
+
const Avatar = styled(CpslAvatar)`
|
|
61
|
+
--container-border-width: 0;
|
|
62
|
+
--container-padding: 0;
|
|
63
|
+
`;
|
|
64
|
+
export {
|
|
65
|
+
UserIdentifier
|
|
66
|
+
};
|
|
@@ -4,6 +4,6 @@ export declare const CenteredColumnContainer: import("styled-components/dist/typ
|
|
|
4
4
|
export declare const FilledDisabledInput: typeof CpslInput;
|
|
5
5
|
export declare const FullWidthFilledDisabledInput: typeof CpslInput;
|
|
6
6
|
export declare const CenteredText: typeof CpslText;
|
|
7
|
-
export declare const HeaderButton: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<Omit<
|
|
8
|
-
ref?: import("react").Ref<
|
|
9
|
-
}, never>> & string & Omit<import("react").ForwardRefExoticComponent<
|
|
7
|
+
export declare const HeaderButton: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<Omit<Omit<any, "ref"> & import("react").RefAttributes<any>, "ref"> & {
|
|
8
|
+
ref?: import("react").Ref<any>;
|
|
9
|
+
}, never>> & string & Omit<import("react").ForwardRefExoticComponent<Omit<any, "ref"> & import("react").RefAttributes<any>>, keyof import("react").Component<any, {}, any>>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "../chunk-GOCCUU3Z.js";
|
|
3
|
+
import { CpslButton, CpslInput, CpslText } from "@getpara/react-components";
|
|
4
|
+
import styled from "styled-components";
|
|
5
|
+
const SpinnerContainer = styled.div`
|
|
6
|
+
display: flex;
|
|
7
|
+
align-items: center;
|
|
8
|
+
justify-content: center;
|
|
9
|
+
`;
|
|
10
|
+
const CenteredColumnContainer = styled.div`
|
|
11
|
+
width: 100%;
|
|
12
|
+
height: 100%;
|
|
13
|
+
align-self: center;
|
|
14
|
+
display: flex;
|
|
15
|
+
flex-direction: column;
|
|
16
|
+
align-items: center;
|
|
17
|
+
gap: 8px;
|
|
18
|
+
`;
|
|
19
|
+
const FilledDisabledInput = styled(CpslInput)`
|
|
20
|
+
--container-border-color: var(--cpsl-color-input-border-placeholder);
|
|
21
|
+
--container-background-color: var(--cpsl-color-background-0);
|
|
22
|
+
--input-background-color: transparent;
|
|
23
|
+
--input-font-weight: 500;
|
|
24
|
+
--input-color: var(--cpsl-color-text-secondary) !important;
|
|
25
|
+
`;
|
|
26
|
+
const FullWidthFilledDisabledInput = styled(FilledDisabledInput)`
|
|
27
|
+
width: 100%;
|
|
28
|
+
`;
|
|
29
|
+
const CenteredText = styled(CpslText)`
|
|
30
|
+
width: 100%;
|
|
31
|
+
text-align: center;
|
|
32
|
+
`;
|
|
33
|
+
const HeaderButton = styled(CpslButton)`
|
|
34
|
+
flex: 0;
|
|
35
|
+
--button-padding-top: 2px;
|
|
36
|
+
--button-padding-bottom: 2px;
|
|
37
|
+
--button-padding-start: 2px;
|
|
38
|
+
--button-padding-end: 2px;
|
|
39
|
+
--button-border-radius: 1000px;
|
|
40
|
+
--button-background-color: var(--cpsl-color-background-4);
|
|
41
|
+
|
|
42
|
+
cpsl-icon {
|
|
43
|
+
--height: 20px;
|
|
44
|
+
--width: 20px;
|
|
45
|
+
}
|
|
46
|
+
`;
|
|
47
|
+
export {
|
|
48
|
+
CenteredColumnContainer,
|
|
49
|
+
CenteredText,
|
|
50
|
+
FilledDisabledInput,
|
|
51
|
+
FullWidthFilledDisabledInput,
|
|
52
|
+
HeaderButton,
|
|
53
|
+
SpinnerContainer
|
|
54
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
export * from "./MoonPayEmbed.js";
|
|
3
|
+
export * from "./RampEmbed.js";
|
|
4
|
+
export * from "./StripeEmbed.js";
|
|
5
|
+
export * from "./common.js";
|
|
6
|
+
export * from "./HeroSpinner.js";
|
|
7
|
+
export * from "./KnownDevices.js";
|
|
8
|
+
export * from "./QRCode.js";
|
|
9
|
+
export * from "./UserIdentifier.js";
|
|
10
|
+
export * from "./NetworkSpeedBanner.js";
|