@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.js
CHANGED
|
@@ -1954,6 +1954,31 @@ function AdvancedSettings({
|
|
|
1954
1954
|
)
|
|
1955
1955
|
] });
|
|
1956
1956
|
}
|
|
1957
|
+
|
|
1958
|
+
// src/processingStatus.ts
|
|
1959
|
+
var PROCESSING_TIMEOUT_MS = 18e4;
|
|
1960
|
+
function resolvePreferredTransfer(polledTransfer, localTransfer) {
|
|
1961
|
+
return polledTransfer ?? localTransfer;
|
|
1962
|
+
}
|
|
1963
|
+
function getTransferStatus(polledTransfer, localTransfer) {
|
|
1964
|
+
const transfer = resolvePreferredTransfer(polledTransfer, localTransfer);
|
|
1965
|
+
return transfer?.status ?? "UNKNOWN";
|
|
1966
|
+
}
|
|
1967
|
+
function getDisplayTransferStatus(polledTransfer, localTransfer) {
|
|
1968
|
+
return getTransferStatus(polledTransfer, localTransfer).toUpperCase();
|
|
1969
|
+
}
|
|
1970
|
+
function getTransferIdSuffix(polledTransfer, localTransfer) {
|
|
1971
|
+
const transfer = resolvePreferredTransfer(polledTransfer, localTransfer);
|
|
1972
|
+
if (!transfer?.id) return "n/a";
|
|
1973
|
+
return transfer.id.slice(-8);
|
|
1974
|
+
}
|
|
1975
|
+
function hasProcessingTimedOut(processingStartedAtMs, nowMs) {
|
|
1976
|
+
if (!processingStartedAtMs) return false;
|
|
1977
|
+
return nowMs - processingStartedAtMs >= PROCESSING_TIMEOUT_MS;
|
|
1978
|
+
}
|
|
1979
|
+
function buildProcessingTimeoutMessage(status) {
|
|
1980
|
+
return `Payment is taking longer than expected (status: ${status}). Please try again.`;
|
|
1981
|
+
}
|
|
1957
1982
|
var ACTIVE_CREDENTIAL_STORAGE_KEY = "swype_active_credential_id";
|
|
1958
1983
|
function isMobile() {
|
|
1959
1984
|
if (typeof navigator === "undefined") return false;
|
|
@@ -2065,6 +2090,7 @@ function SwypePayment({
|
|
|
2065
2090
|
const [mobileFlow, setMobileFlow] = useState(false);
|
|
2066
2091
|
const pollingTransferIdRef = useRef(null);
|
|
2067
2092
|
const mobileSigningTransferIdRef = useRef(null);
|
|
2093
|
+
const processingStartedAtRef = useRef(null);
|
|
2068
2094
|
const [selectSourceChainName, setSelectSourceChainName] = useState("");
|
|
2069
2095
|
const [selectSourceTokenSymbol, setSelectSourceTokenSymbol] = useState("");
|
|
2070
2096
|
const initializedSelectSourceActionRef = useRef(null);
|
|
@@ -2172,6 +2198,36 @@ function SwypePayment({
|
|
|
2172
2198
|
setError("Transfer failed.");
|
|
2173
2199
|
}
|
|
2174
2200
|
}, [polling.transfer, onComplete]);
|
|
2201
|
+
useEffect(() => {
|
|
2202
|
+
if (step !== "processing") {
|
|
2203
|
+
processingStartedAtRef.current = null;
|
|
2204
|
+
return;
|
|
2205
|
+
}
|
|
2206
|
+
if (!processingStartedAtRef.current) {
|
|
2207
|
+
processingStartedAtRef.current = Date.now();
|
|
2208
|
+
}
|
|
2209
|
+
const elapsedMs = Date.now() - processingStartedAtRef.current;
|
|
2210
|
+
const remainingMs = PROCESSING_TIMEOUT_MS - elapsedMs;
|
|
2211
|
+
const handleTimeout = () => {
|
|
2212
|
+
if (!hasProcessingTimedOut(processingStartedAtRef.current, Date.now())) {
|
|
2213
|
+
return;
|
|
2214
|
+
}
|
|
2215
|
+
const status = getTransferStatus(polling.transfer, transfer);
|
|
2216
|
+
const msg = buildProcessingTimeoutMessage(status);
|
|
2217
|
+
polling.stopPolling();
|
|
2218
|
+
setStep("ready");
|
|
2219
|
+
setError(msg);
|
|
2220
|
+
onError?.(msg);
|
|
2221
|
+
};
|
|
2222
|
+
if (remainingMs <= 0) {
|
|
2223
|
+
handleTimeout();
|
|
2224
|
+
return;
|
|
2225
|
+
}
|
|
2226
|
+
const timeoutId = window.setTimeout(handleTimeout, remainingMs);
|
|
2227
|
+
return () => {
|
|
2228
|
+
window.clearTimeout(timeoutId);
|
|
2229
|
+
};
|
|
2230
|
+
}, [step, polling.transfer, transfer, polling.stopPolling, onError]);
|
|
2175
2231
|
useEffect(() => {
|
|
2176
2232
|
if (!mobileFlow) return;
|
|
2177
2233
|
const polledTransfer = polling.transfer;
|
|
@@ -2263,6 +2319,7 @@ function SwypePayment({
|
|
|
2263
2319
|
return;
|
|
2264
2320
|
}
|
|
2265
2321
|
setStep("processing");
|
|
2322
|
+
processingStartedAtRef.current = Date.now();
|
|
2266
2323
|
setError(null);
|
|
2267
2324
|
setCreatingTransfer(true);
|
|
2268
2325
|
setMobileFlow(false);
|
|
@@ -2348,6 +2405,7 @@ function SwypePayment({
|
|
|
2348
2405
|
setError(null);
|
|
2349
2406
|
setAmount(depositAmount != null ? depositAmount.toString() : "");
|
|
2350
2407
|
setMobileFlow(false);
|
|
2408
|
+
processingStartedAtRef.current = null;
|
|
2351
2409
|
pollingTransferIdRef.current = null;
|
|
2352
2410
|
mobileSigningTransferIdRef.current = null;
|
|
2353
2411
|
setConnectingNewAccount(false);
|
|
@@ -3104,6 +3162,8 @@ function SwypePayment({
|
|
|
3104
3162
|
}
|
|
3105
3163
|
};
|
|
3106
3164
|
const regMsg = getRegistrationMessage();
|
|
3165
|
+
const transferStatus = getDisplayTransferStatus(polling.transfer, transfer);
|
|
3166
|
+
const transferIdSuffix = getTransferIdSuffix(polling.transfer, transfer);
|
|
3107
3167
|
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
3168
|
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
3169
|
return /* @__PURE__ */ jsx("div", { style: cardStyle, children: /* @__PURE__ */ jsxs("div", { style: { textAlign: "center", padding: "16px 0" }, children: [
|
|
@@ -3131,6 +3191,39 @@ function SwypePayment({
|
|
|
3131
3191
|
children: statusDescription
|
|
3132
3192
|
}
|
|
3133
3193
|
),
|
|
3194
|
+
/* @__PURE__ */ jsxs(
|
|
3195
|
+
"p",
|
|
3196
|
+
{
|
|
3197
|
+
style: {
|
|
3198
|
+
marginTop: "12px",
|
|
3199
|
+
marginBottom: 0,
|
|
3200
|
+
fontSize: "0.8rem",
|
|
3201
|
+
color: tokens.textSecondary
|
|
3202
|
+
},
|
|
3203
|
+
children: [
|
|
3204
|
+
"Current status: ",
|
|
3205
|
+
/* @__PURE__ */ jsx("strong", { style: { color: tokens.text }, children: transferStatus }),
|
|
3206
|
+
" \xB7 ",
|
|
3207
|
+
"Transfer: ",
|
|
3208
|
+
/* @__PURE__ */ jsx("span", { style: { color: tokens.textMuted }, children: transferIdSuffix })
|
|
3209
|
+
]
|
|
3210
|
+
}
|
|
3211
|
+
),
|
|
3212
|
+
polling.error && /* @__PURE__ */ jsxs(
|
|
3213
|
+
"p",
|
|
3214
|
+
{
|
|
3215
|
+
style: {
|
|
3216
|
+
marginTop: "8px",
|
|
3217
|
+
marginBottom: 0,
|
|
3218
|
+
fontSize: "0.75rem",
|
|
3219
|
+
color: tokens.textMuted
|
|
3220
|
+
},
|
|
3221
|
+
children: [
|
|
3222
|
+
"Last polling error: ",
|
|
3223
|
+
polling.error
|
|
3224
|
+
]
|
|
3225
|
+
}
|
|
3226
|
+
),
|
|
3134
3227
|
!mobileFlow && authExecutor.results.length > 0 && /* @__PURE__ */ jsx("div", { style: { marginTop: "20px", textAlign: "left" }, children: authExecutor.results.map((r) => /* @__PURE__ */ jsxs(
|
|
3135
3228
|
"div",
|
|
3136
3229
|
{
|