@swype-org/react-sdk 0.1.12 → 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 +93 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +93 -0
- 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;
|
|
@@ -2266,6 +2322,7 @@ function SwypePayment({
|
|
|
2266
2322
|
return;
|
|
2267
2323
|
}
|
|
2268
2324
|
setStep("processing");
|
|
2325
|
+
processingStartedAtRef.current = Date.now();
|
|
2269
2326
|
setError(null);
|
|
2270
2327
|
setCreatingTransfer(true);
|
|
2271
2328
|
setMobileFlow(false);
|
|
@@ -2351,6 +2408,7 @@ function SwypePayment({
|
|
|
2351
2408
|
setError(null);
|
|
2352
2409
|
setAmount(depositAmount != null ? depositAmount.toString() : "");
|
|
2353
2410
|
setMobileFlow(false);
|
|
2411
|
+
processingStartedAtRef.current = null;
|
|
2354
2412
|
pollingTransferIdRef.current = null;
|
|
2355
2413
|
mobileSigningTransferIdRef.current = null;
|
|
2356
2414
|
setConnectingNewAccount(false);
|
|
@@ -3107,6 +3165,8 @@ function SwypePayment({
|
|
|
3107
3165
|
}
|
|
3108
3166
|
};
|
|
3109
3167
|
const regMsg = getRegistrationMessage();
|
|
3168
|
+
const transferStatus = getDisplayTransferStatus(polling.transfer, transfer);
|
|
3169
|
+
const transferIdSuffix = getTransferIdSuffix(polling.transfer, transfer);
|
|
3110
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...";
|
|
3111
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...";
|
|
3112
3172
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { style: cardStyle, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { textAlign: "center", padding: "16px 0" }, children: [
|
|
@@ -3134,6 +3194,39 @@ function SwypePayment({
|
|
|
3134
3194
|
children: statusDescription
|
|
3135
3195
|
}
|
|
3136
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
|
+
),
|
|
3137
3230
|
!mobileFlow && authExecutor.results.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginTop: "20px", textAlign: "left" }, children: authExecutor.results.map((r) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3138
3231
|
"div",
|
|
3139
3232
|
{
|