@swype-org/react-sdk 0.1.11 → 0.1.13
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 +101 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +101 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1957,6 +1957,31 @@ function AdvancedSettings({
|
|
|
1957
1957
|
)
|
|
1958
1958
|
] });
|
|
1959
1959
|
}
|
|
1960
|
+
|
|
1961
|
+
// src/processingStatus.ts
|
|
1962
|
+
var PROCESSING_TIMEOUT_MS = 18e4;
|
|
1963
|
+
function resolvePreferredTransfer(polledTransfer, localTransfer) {
|
|
1964
|
+
return polledTransfer ?? localTransfer;
|
|
1965
|
+
}
|
|
1966
|
+
function getTransferStatus(polledTransfer, localTransfer) {
|
|
1967
|
+
const transfer = resolvePreferredTransfer(polledTransfer, localTransfer);
|
|
1968
|
+
return transfer?.status ?? "UNKNOWN";
|
|
1969
|
+
}
|
|
1970
|
+
function getDisplayTransferStatus(polledTransfer, localTransfer) {
|
|
1971
|
+
return getTransferStatus(polledTransfer, localTransfer).toUpperCase();
|
|
1972
|
+
}
|
|
1973
|
+
function getTransferIdSuffix(polledTransfer, localTransfer) {
|
|
1974
|
+
const transfer = resolvePreferredTransfer(polledTransfer, localTransfer);
|
|
1975
|
+
if (!transfer?.id) return "n/a";
|
|
1976
|
+
return transfer.id.slice(-8);
|
|
1977
|
+
}
|
|
1978
|
+
function hasProcessingTimedOut(processingStartedAtMs, nowMs) {
|
|
1979
|
+
if (!processingStartedAtMs) return false;
|
|
1980
|
+
return nowMs - processingStartedAtMs >= PROCESSING_TIMEOUT_MS;
|
|
1981
|
+
}
|
|
1982
|
+
function buildProcessingTimeoutMessage(status) {
|
|
1983
|
+
return `Payment is taking longer than expected (status: ${status}). Please try again.`;
|
|
1984
|
+
}
|
|
1960
1985
|
var ACTIVE_CREDENTIAL_STORAGE_KEY = "swype_active_credential_id";
|
|
1961
1986
|
function isMobile() {
|
|
1962
1987
|
if (typeof navigator === "undefined") return false;
|
|
@@ -2068,6 +2093,7 @@ function SwypePayment({
|
|
|
2068
2093
|
const [mobileFlow, setMobileFlow] = react.useState(false);
|
|
2069
2094
|
const pollingTransferIdRef = react.useRef(null);
|
|
2070
2095
|
const mobileSigningTransferIdRef = react.useRef(null);
|
|
2096
|
+
const processingStartedAtRef = react.useRef(null);
|
|
2071
2097
|
const [selectSourceChainName, setSelectSourceChainName] = react.useState("");
|
|
2072
2098
|
const [selectSourceTokenSymbol, setSelectSourceTokenSymbol] = react.useState("");
|
|
2073
2099
|
const initializedSelectSourceActionRef = react.useRef(null);
|
|
@@ -2175,6 +2201,36 @@ function SwypePayment({
|
|
|
2175
2201
|
setError("Transfer failed.");
|
|
2176
2202
|
}
|
|
2177
2203
|
}, [polling.transfer, onComplete]);
|
|
2204
|
+
react.useEffect(() => {
|
|
2205
|
+
if (step !== "processing") {
|
|
2206
|
+
processingStartedAtRef.current = null;
|
|
2207
|
+
return;
|
|
2208
|
+
}
|
|
2209
|
+
if (!processingStartedAtRef.current) {
|
|
2210
|
+
processingStartedAtRef.current = Date.now();
|
|
2211
|
+
}
|
|
2212
|
+
const elapsedMs = Date.now() - processingStartedAtRef.current;
|
|
2213
|
+
const remainingMs = PROCESSING_TIMEOUT_MS - elapsedMs;
|
|
2214
|
+
const handleTimeout = () => {
|
|
2215
|
+
if (!hasProcessingTimedOut(processingStartedAtRef.current, Date.now())) {
|
|
2216
|
+
return;
|
|
2217
|
+
}
|
|
2218
|
+
const status = getTransferStatus(polling.transfer, transfer);
|
|
2219
|
+
const msg = buildProcessingTimeoutMessage(status);
|
|
2220
|
+
polling.stopPolling();
|
|
2221
|
+
setStep("ready");
|
|
2222
|
+
setError(msg);
|
|
2223
|
+
onError?.(msg);
|
|
2224
|
+
};
|
|
2225
|
+
if (remainingMs <= 0) {
|
|
2226
|
+
handleTimeout();
|
|
2227
|
+
return;
|
|
2228
|
+
}
|
|
2229
|
+
const timeoutId = window.setTimeout(handleTimeout, remainingMs);
|
|
2230
|
+
return () => {
|
|
2231
|
+
window.clearTimeout(timeoutId);
|
|
2232
|
+
};
|
|
2233
|
+
}, [step, polling.transfer, transfer, polling.stopPolling, onError]);
|
|
2178
2234
|
react.useEffect(() => {
|
|
2179
2235
|
if (!mobileFlow) return;
|
|
2180
2236
|
const polledTransfer = polling.transfer;
|
|
@@ -2197,19 +2253,22 @@ function SwypePayment({
|
|
|
2197
2253
|
void sign();
|
|
2198
2254
|
}, [mobileFlow, polling.transfer, transferSigning, onError]);
|
|
2199
2255
|
react.useEffect(() => {
|
|
2200
|
-
if (!mobileFlow
|
|
2256
|
+
if (!mobileFlow) return;
|
|
2257
|
+
const transferIdToResume = pollingTransferIdRef.current ?? transfer?.id;
|
|
2258
|
+
if (!transferIdToResume) return;
|
|
2259
|
+
if (!polling.isPolling) {
|
|
2260
|
+
polling.startPolling(transferIdToResume);
|
|
2261
|
+
}
|
|
2201
2262
|
const handleVisibility = () => {
|
|
2202
2263
|
if (document.visibilityState === "visible") {
|
|
2203
|
-
|
|
2204
|
-
polling.startPolling(pollingTransferIdRef.current);
|
|
2205
|
-
}
|
|
2264
|
+
polling.startPolling(transferIdToResume);
|
|
2206
2265
|
}
|
|
2207
2266
|
};
|
|
2208
2267
|
document.addEventListener("visibilitychange", handleVisibility);
|
|
2209
2268
|
return () => {
|
|
2210
2269
|
document.removeEventListener("visibilitychange", handleVisibility);
|
|
2211
2270
|
};
|
|
2212
|
-
}, [mobileFlow, polling]);
|
|
2271
|
+
}, [mobileFlow, transfer?.id, polling.isPolling, polling.startPolling]);
|
|
2213
2272
|
const pendingSelectSourceAction = authExecutor.pendingSelectSource;
|
|
2214
2273
|
const selectSourceChoices = react.useMemo(() => {
|
|
2215
2274
|
if (!pendingSelectSourceAction) return [];
|
|
@@ -2263,6 +2322,7 @@ function SwypePayment({
|
|
|
2263
2322
|
return;
|
|
2264
2323
|
}
|
|
2265
2324
|
setStep("processing");
|
|
2325
|
+
processingStartedAtRef.current = Date.now();
|
|
2266
2326
|
setError(null);
|
|
2267
2327
|
setCreatingTransfer(true);
|
|
2268
2328
|
setMobileFlow(false);
|
|
@@ -2348,6 +2408,7 @@ function SwypePayment({
|
|
|
2348
2408
|
setError(null);
|
|
2349
2409
|
setAmount(depositAmount != null ? depositAmount.toString() : "");
|
|
2350
2410
|
setMobileFlow(false);
|
|
2411
|
+
processingStartedAtRef.current = null;
|
|
2351
2412
|
pollingTransferIdRef.current = null;
|
|
2352
2413
|
mobileSigningTransferIdRef.current = null;
|
|
2353
2414
|
setConnectingNewAccount(false);
|
|
@@ -3104,6 +3165,8 @@ function SwypePayment({
|
|
|
3104
3165
|
}
|
|
3105
3166
|
};
|
|
3106
3167
|
const regMsg = getRegistrationMessage();
|
|
3168
|
+
const transferStatus = getDisplayTransferStatus(polling.transfer, transfer);
|
|
3169
|
+
const transferIdSuffix = getTransferIdSuffix(polling.transfer, transfer);
|
|
3107
3170
|
const statusLabel = creatingTransfer ? "Creating transfer..." : mobileFlow ? "Waiting for authorization..." : authExecutor.executing && regMsg.label ? regMsg.label : authExecutor.executing ? "Authorizing..." : transferSigning.signing ? "Preparing transfer..." : polling.isPolling ? "Processing payment..." : "Please wait...";
|
|
3108
3171
|
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...";
|
|
3109
3172
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { style: cardStyle, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { textAlign: "center", padding: "16px 0" }, children: [
|
|
@@ -3131,6 +3194,39 @@ function SwypePayment({
|
|
|
3131
3194
|
children: statusDescription
|
|
3132
3195
|
}
|
|
3133
3196
|
),
|
|
3197
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
3198
|
+
"p",
|
|
3199
|
+
{
|
|
3200
|
+
style: {
|
|
3201
|
+
marginTop: "12px",
|
|
3202
|
+
marginBottom: 0,
|
|
3203
|
+
fontSize: "0.8rem",
|
|
3204
|
+
color: tokens.textSecondary
|
|
3205
|
+
},
|
|
3206
|
+
children: [
|
|
3207
|
+
"Current status: ",
|
|
3208
|
+
/* @__PURE__ */ jsxRuntime.jsx("strong", { style: { color: tokens.text }, children: transferStatus }),
|
|
3209
|
+
" \xB7 ",
|
|
3210
|
+
"Transfer: ",
|
|
3211
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { style: { color: tokens.textMuted }, children: transferIdSuffix })
|
|
3212
|
+
]
|
|
3213
|
+
}
|
|
3214
|
+
),
|
|
3215
|
+
polling.error && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3216
|
+
"p",
|
|
3217
|
+
{
|
|
3218
|
+
style: {
|
|
3219
|
+
marginTop: "8px",
|
|
3220
|
+
marginBottom: 0,
|
|
3221
|
+
fontSize: "0.75rem",
|
|
3222
|
+
color: tokens.textMuted
|
|
3223
|
+
},
|
|
3224
|
+
children: [
|
|
3225
|
+
"Last polling error: ",
|
|
3226
|
+
polling.error
|
|
3227
|
+
]
|
|
3228
|
+
}
|
|
3229
|
+
),
|
|
3134
3230
|
!mobileFlow && authExecutor.results.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginTop: "20px", textAlign: "left" }, children: authExecutor.results.map((r) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3135
3231
|
"div",
|
|
3136
3232
|
{
|