@swype-org/react-sdk 0.1.25 → 0.1.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +69 -108
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +70 -109
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createContext, useRef, useState, useCallback, useMemo, useContext
|
|
1
|
+
import { createContext, useRef, useEffect, useState, useCallback, useMemo, useContext } from 'react';
|
|
2
2
|
import { PrivyProvider, usePrivy } from '@privy-io/react-auth';
|
|
3
3
|
import { createConfig, http, WagmiProvider, useConfig, useConnect, useSwitchChain } from 'wagmi';
|
|
4
4
|
import { mainnet, arbitrum, base } from 'wagmi/chains';
|
|
@@ -74,6 +74,26 @@ var wagmiConfig = createConfig({
|
|
|
74
74
|
[base.id]: http()
|
|
75
75
|
}
|
|
76
76
|
});
|
|
77
|
+
var PRIVY_MODAL_CENTER_CSS = `
|
|
78
|
+
@media (max-width: 440px) {
|
|
79
|
+
#privy-dialog [data-headlessui-state] {
|
|
80
|
+
position: static !important;
|
|
81
|
+
bottom: auto !important;
|
|
82
|
+
margin: auto !important;
|
|
83
|
+
width: 360px !important;
|
|
84
|
+
max-width: calc(100vw - 32px) !important;
|
|
85
|
+
box-shadow: 0px 8px 36px rgba(55, 65, 81, 0.15) !important;
|
|
86
|
+
border-radius: var(--privy-border-radius-lg) !important;
|
|
87
|
+
transform: none !important;
|
|
88
|
+
transition: opacity 100ms ease-in !important;
|
|
89
|
+
}
|
|
90
|
+
#privy-dialog [data-headlessui-state].entering,
|
|
91
|
+
#privy-dialog [data-headlessui-state].leaving {
|
|
92
|
+
opacity: 0 !important;
|
|
93
|
+
transform: none !important;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
`;
|
|
77
97
|
var SwypeContext = createContext(null);
|
|
78
98
|
function SwypeProvider({
|
|
79
99
|
apiBaseUrl,
|
|
@@ -84,6 +104,15 @@ function SwypeProvider({
|
|
|
84
104
|
if (!queryClientRef.current) {
|
|
85
105
|
queryClientRef.current = new QueryClient();
|
|
86
106
|
}
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
const style = document.createElement("style");
|
|
109
|
+
style.setAttribute("data-swype", "privy-modal-center");
|
|
110
|
+
style.textContent = PRIVY_MODAL_CENTER_CSS;
|
|
111
|
+
document.head.appendChild(style);
|
|
112
|
+
return () => {
|
|
113
|
+
style.remove();
|
|
114
|
+
};
|
|
115
|
+
}, []);
|
|
87
116
|
const [depositAmount, setDepositAmountRaw] = useState(null);
|
|
88
117
|
const setDepositAmount = useCallback((amount) => {
|
|
89
118
|
setDepositAmountRaw(amount);
|
|
@@ -796,7 +825,7 @@ async function deviceHasPasskey(credentialId) {
|
|
|
796
825
|
type: "public-key",
|
|
797
826
|
id: base64ToBytes(credentialId)
|
|
798
827
|
}],
|
|
799
|
-
userVerification: "
|
|
828
|
+
userVerification: "discouraged",
|
|
800
829
|
timeout: 3e4
|
|
801
830
|
}
|
|
802
831
|
});
|
|
@@ -2267,17 +2296,15 @@ function SwypePayment({
|
|
|
2267
2296
|
const loadingDataRef = useRef(false);
|
|
2268
2297
|
useEffect(() => {
|
|
2269
2298
|
if (!authenticated) return;
|
|
2299
|
+
if (step === "login") return;
|
|
2270
2300
|
if (accounts.length > 0 || loadingDataRef.current) return;
|
|
2301
|
+
if (!activeCredentialId) return;
|
|
2271
2302
|
let cancelled = false;
|
|
2272
2303
|
loadingDataRef.current = true;
|
|
2273
2304
|
const load = async () => {
|
|
2274
2305
|
setLoadingData(true);
|
|
2275
2306
|
setError(null);
|
|
2276
2307
|
try {
|
|
2277
|
-
if (!activeCredentialId) {
|
|
2278
|
-
setStep("register-passkey");
|
|
2279
|
-
return;
|
|
2280
|
-
}
|
|
2281
2308
|
const token = await getAccessToken();
|
|
2282
2309
|
if (!token) throw new Error("Not authenticated");
|
|
2283
2310
|
const [prov, accts, chn] = await Promise.all([
|
|
@@ -2314,7 +2341,7 @@ function SwypePayment({
|
|
|
2314
2341
|
cancelled = true;
|
|
2315
2342
|
loadingDataRef.current = false;
|
|
2316
2343
|
};
|
|
2317
|
-
}, [authenticated, accounts.length, apiBaseUrl, getAccessToken, activeCredentialId]);
|
|
2344
|
+
}, [authenticated, step, accounts.length, apiBaseUrl, getAccessToken, activeCredentialId]);
|
|
2318
2345
|
useEffect(() => {
|
|
2319
2346
|
if (!polling.transfer) return;
|
|
2320
2347
|
if (polling.transfer.status === "COMPLETED") {
|
|
@@ -3024,7 +3051,7 @@ function SwypePayment({
|
|
|
3024
3051
|
]
|
|
3025
3052
|
}
|
|
3026
3053
|
),
|
|
3027
|
-
/* @__PURE__ */
|
|
3054
|
+
/* @__PURE__ */ jsx(
|
|
3028
3055
|
"div",
|
|
3029
3056
|
{
|
|
3030
3057
|
style: {
|
|
@@ -3037,74 +3064,39 @@ function SwypePayment({
|
|
|
3037
3064
|
border: `1px solid ${tokens.border}`,
|
|
3038
3065
|
lineHeight: 1.7
|
|
3039
3066
|
},
|
|
3040
|
-
children:
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
{
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
style: { display: "flex", justifyContent: "space-between" },
|
|
3068
|
-
children: [
|
|
3069
|
-
/* @__PURE__ */ jsx("span", { children: "Token" }),
|
|
3070
|
-
/* @__PURE__ */ jsx("span", { style: { fontWeight: 600 }, children: destination.token.symbol })
|
|
3071
|
-
]
|
|
3072
|
-
}
|
|
3073
|
-
),
|
|
3074
|
-
/* @__PURE__ */ jsxs(
|
|
3075
|
-
"div",
|
|
3076
|
-
{
|
|
3077
|
-
style: {
|
|
3078
|
-
display: "flex",
|
|
3079
|
-
justifyContent: "space-between",
|
|
3080
|
-
alignItems: "center"
|
|
3081
|
-
},
|
|
3082
|
-
children: [
|
|
3083
|
-
/* @__PURE__ */ jsx("span", { children: "From" }),
|
|
3084
|
-
noAccounts ? /* @__PURE__ */ jsx("span", { style: { fontWeight: 500, color: tokens.textMuted }, children: "New account" }) : /* @__PURE__ */ jsx(
|
|
3085
|
-
AccountDropdown,
|
|
3086
|
-
{
|
|
3087
|
-
accounts,
|
|
3088
|
-
selectedAccountId,
|
|
3089
|
-
selectedWalletId,
|
|
3090
|
-
onSelect: (id) => {
|
|
3091
|
-
setSelectedAccountId(id);
|
|
3092
|
-
setSelectedWalletId(null);
|
|
3093
|
-
setConnectingNewAccount(false);
|
|
3094
|
-
setSelectedProviderId(null);
|
|
3095
|
-
},
|
|
3096
|
-
onWalletSelect: (accountId, walletId) => {
|
|
3097
|
-
setSelectedAccountId(accountId);
|
|
3098
|
-
setSelectedWalletId(walletId);
|
|
3099
|
-
setConnectingNewAccount(false);
|
|
3100
|
-
setSelectedProviderId(null);
|
|
3101
|
-
}
|
|
3067
|
+
children: /* @__PURE__ */ jsx(
|
|
3068
|
+
"div",
|
|
3069
|
+
{
|
|
3070
|
+
style: {
|
|
3071
|
+
display: "flex",
|
|
3072
|
+
justifyContent: "space-between",
|
|
3073
|
+
alignItems: "center"
|
|
3074
|
+
},
|
|
3075
|
+
children: noAccounts ? /* @__PURE__ */ jsx(Fragment, {}) : /* @__PURE__ */ jsxs("div", { children: [
|
|
3076
|
+
/* @__PURE__ */ jsx("span", { children: "From" }),
|
|
3077
|
+
/* @__PURE__ */ jsx(
|
|
3078
|
+
AccountDropdown,
|
|
3079
|
+
{
|
|
3080
|
+
accounts,
|
|
3081
|
+
selectedAccountId,
|
|
3082
|
+
selectedWalletId,
|
|
3083
|
+
onSelect: (id) => {
|
|
3084
|
+
setSelectedAccountId(id);
|
|
3085
|
+
setSelectedWalletId(null);
|
|
3086
|
+
setConnectingNewAccount(false);
|
|
3087
|
+
setSelectedProviderId(null);
|
|
3088
|
+
},
|
|
3089
|
+
onWalletSelect: (accountId, walletId) => {
|
|
3090
|
+
setSelectedAccountId(accountId);
|
|
3091
|
+
setSelectedWalletId(walletId);
|
|
3092
|
+
setConnectingNewAccount(false);
|
|
3093
|
+
setSelectedProviderId(null);
|
|
3102
3094
|
}
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
}
|
|
3106
|
-
|
|
3107
|
-
|
|
3095
|
+
}
|
|
3096
|
+
)
|
|
3097
|
+
] })
|
|
3098
|
+
}
|
|
3099
|
+
)
|
|
3108
3100
|
}
|
|
3109
3101
|
),
|
|
3110
3102
|
noAccounts && /* @__PURE__ */ jsxs("div", { style: { marginBottom: "16px" }, children: [
|
|
@@ -3370,10 +3362,9 @@ function SwypePayment({
|
|
|
3370
3362
|
}
|
|
3371
3363
|
};
|
|
3372
3364
|
const regMsg = getRegistrationMessage();
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
const statusLabel = creatingTransfer ? "Creating
|
|
3376
|
-
const statusDescription = creatingTransfer ? "Setting up your transfer..." : mobileFlow ? "Complete the authorization in your wallet app, then return here." : authExecutor.executing && regMsg.description ? regMsg.description : authExecutor.executing ? "Complete the wallet prompts to authorize this payment." : transferSigning.signing ? "Waiting for backend to prepare your transfer payload..." : polling.isPolling ? "Your payment is being processed. This usually takes a few moments." : "Hang tight...";
|
|
3365
|
+
getDisplayTransferStatus(polling.transfer, transfer);
|
|
3366
|
+
getTransferIdSuffix(polling.transfer, transfer);
|
|
3367
|
+
const statusLabel = creatingTransfer ? "Creating Transfer" : mobileFlow ? "Waiting for Authorization" : authExecutor.executing && regMsg.label ? regMsg.label : authExecutor.executing ? "Authorizing" : transferSigning.signing ? "Sending transfer" : polling.isPolling ? "Transfer Sent" : "Please wait...";
|
|
3377
3368
|
return /* @__PURE__ */ jsx("div", { style: cardStyle, children: /* @__PURE__ */ jsxs("div", { style: { textAlign: "center", padding: "16px 0" }, children: [
|
|
3378
3369
|
/* @__PURE__ */ jsx(Spinner, { size: 48 }),
|
|
3379
3370
|
/* @__PURE__ */ jsx(
|
|
@@ -3387,36 +3378,6 @@ function SwypePayment({
|
|
|
3387
3378
|
children: statusLabel
|
|
3388
3379
|
}
|
|
3389
3380
|
),
|
|
3390
|
-
/* @__PURE__ */ jsx(
|
|
3391
|
-
"p",
|
|
3392
|
-
{
|
|
3393
|
-
style: {
|
|
3394
|
-
fontSize: "0.85rem",
|
|
3395
|
-
color: tokens.textSecondary,
|
|
3396
|
-
margin: 0,
|
|
3397
|
-
lineHeight: 1.5
|
|
3398
|
-
},
|
|
3399
|
-
children: statusDescription
|
|
3400
|
-
}
|
|
3401
|
-
),
|
|
3402
|
-
/* @__PURE__ */ jsxs(
|
|
3403
|
-
"p",
|
|
3404
|
-
{
|
|
3405
|
-
style: {
|
|
3406
|
-
marginTop: "12px",
|
|
3407
|
-
marginBottom: 0,
|
|
3408
|
-
fontSize: "0.8rem",
|
|
3409
|
-
color: tokens.textSecondary
|
|
3410
|
-
},
|
|
3411
|
-
children: [
|
|
3412
|
-
"Current status: ",
|
|
3413
|
-
/* @__PURE__ */ jsx("strong", { style: { color: tokens.text }, children: transferStatus }),
|
|
3414
|
-
" \xB7 ",
|
|
3415
|
-
"Transfer: ",
|
|
3416
|
-
/* @__PURE__ */ jsx("span", { style: { color: tokens.textMuted }, children: transferIdSuffix })
|
|
3417
|
-
]
|
|
3418
|
-
}
|
|
3419
|
-
),
|
|
3420
3381
|
polling.error && /* @__PURE__ */ jsxs(
|
|
3421
3382
|
"p",
|
|
3422
3383
|
{
|