@swype-org/react-sdk 0.1.53 → 0.1.55
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 +52 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +52 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -89,6 +89,7 @@ interface TransferDestination {
|
|
|
89
89
|
chainId: string;
|
|
90
90
|
address: string;
|
|
91
91
|
token: {
|
|
92
|
+
address: string;
|
|
92
93
|
symbol: string;
|
|
93
94
|
};
|
|
94
95
|
amount: Amount;
|
|
@@ -162,7 +163,7 @@ interface Destination {
|
|
|
162
163
|
chainId: string;
|
|
163
164
|
address: string;
|
|
164
165
|
token: {
|
|
165
|
-
|
|
166
|
+
address: string;
|
|
166
167
|
};
|
|
167
168
|
}
|
|
168
169
|
/** Merchant-signed authorization envelope required for transfer creation. */
|
package/dist/index.d.ts
CHANGED
|
@@ -89,6 +89,7 @@ interface TransferDestination {
|
|
|
89
89
|
chainId: string;
|
|
90
90
|
address: string;
|
|
91
91
|
token: {
|
|
92
|
+
address: string;
|
|
92
93
|
symbol: string;
|
|
93
94
|
};
|
|
94
95
|
amount: Amount;
|
|
@@ -162,7 +163,7 @@ interface Destination {
|
|
|
162
163
|
chainId: string;
|
|
163
164
|
address: string;
|
|
164
165
|
token: {
|
|
165
|
-
|
|
166
|
+
address: string;
|
|
166
167
|
};
|
|
167
168
|
}
|
|
168
169
|
/** Merchant-signed authorization envelope required for transfer creation. */
|
package/dist/index.js
CHANGED
|
@@ -212,7 +212,7 @@ async function createTransfer(apiBaseUrl, token, params) {
|
|
|
212
212
|
destinations: [
|
|
213
213
|
{
|
|
214
214
|
chainId: params.destination.chainId,
|
|
215
|
-
token: {
|
|
215
|
+
token: { address: params.destination.token.address },
|
|
216
216
|
address: params.destination.address
|
|
217
217
|
}
|
|
218
218
|
],
|
|
@@ -4007,7 +4007,29 @@ function isInIframe() {
|
|
|
4007
4007
|
}
|
|
4008
4008
|
}
|
|
4009
4009
|
var ACTIVE_CREDENTIAL_STORAGE_KEY = "swype_active_credential_id";
|
|
4010
|
+
var MOBILE_FLOW_STORAGE_KEY = "swype_mobile_flow";
|
|
4010
4011
|
var MIN_SEND_AMOUNT_USD = 0.25;
|
|
4012
|
+
function persistMobileFlowState(data) {
|
|
4013
|
+
try {
|
|
4014
|
+
sessionStorage.setItem(MOBILE_FLOW_STORAGE_KEY, JSON.stringify(data));
|
|
4015
|
+
} catch {
|
|
4016
|
+
}
|
|
4017
|
+
}
|
|
4018
|
+
function loadMobileFlowState() {
|
|
4019
|
+
try {
|
|
4020
|
+
const raw = sessionStorage.getItem(MOBILE_FLOW_STORAGE_KEY);
|
|
4021
|
+
if (!raw) return null;
|
|
4022
|
+
return JSON.parse(raw);
|
|
4023
|
+
} catch {
|
|
4024
|
+
return null;
|
|
4025
|
+
}
|
|
4026
|
+
}
|
|
4027
|
+
function clearMobileFlowState() {
|
|
4028
|
+
try {
|
|
4029
|
+
sessionStorage.removeItem(MOBILE_FLOW_STORAGE_KEY);
|
|
4030
|
+
} catch {
|
|
4031
|
+
}
|
|
4032
|
+
}
|
|
4011
4033
|
function computeSmartDefaults(accts, transferAmount) {
|
|
4012
4034
|
if (accts.length === 0) return null;
|
|
4013
4035
|
for (const acct of accts) {
|
|
@@ -4250,6 +4272,20 @@ function SwypePaymentInner({
|
|
|
4250
4272
|
let cancelled = false;
|
|
4251
4273
|
setError(null);
|
|
4252
4274
|
resetHeadlessLogin();
|
|
4275
|
+
const restoreOrDeposit = () => {
|
|
4276
|
+
const persisted = loadMobileFlowState();
|
|
4277
|
+
if (persisted) {
|
|
4278
|
+
setMobileFlow(true);
|
|
4279
|
+
setDeeplinkUri(persisted.deeplinkUri);
|
|
4280
|
+
setSelectedProviderId(persisted.providerId);
|
|
4281
|
+
pollingTransferIdRef.current = persisted.transferId;
|
|
4282
|
+
mobileSetupFlowRef.current = persisted.isSetup;
|
|
4283
|
+
setStep("open-wallet");
|
|
4284
|
+
polling.startPolling(persisted.transferId);
|
|
4285
|
+
} else {
|
|
4286
|
+
setStep("deposit");
|
|
4287
|
+
}
|
|
4288
|
+
};
|
|
4253
4289
|
const checkPasskey = async () => {
|
|
4254
4290
|
try {
|
|
4255
4291
|
const token = await getAccessToken();
|
|
@@ -4265,7 +4301,7 @@ function SwypePaymentInner({
|
|
|
4265
4301
|
return;
|
|
4266
4302
|
}
|
|
4267
4303
|
if (activeCredentialId && allPasskeys.some((p) => p.credentialId === activeCredentialId)) {
|
|
4268
|
-
|
|
4304
|
+
restoreOrDeposit();
|
|
4269
4305
|
return;
|
|
4270
4306
|
}
|
|
4271
4307
|
if (cancelled) return;
|
|
@@ -4275,7 +4311,7 @@ function SwypePaymentInner({
|
|
|
4275
4311
|
if (matched) {
|
|
4276
4312
|
setActiveCredentialId(matched);
|
|
4277
4313
|
window.localStorage.setItem(ACTIVE_CREDENTIAL_STORAGE_KEY, matched);
|
|
4278
|
-
|
|
4314
|
+
restoreOrDeposit();
|
|
4279
4315
|
return;
|
|
4280
4316
|
}
|
|
4281
4317
|
setStep("create-passkey");
|
|
@@ -4345,10 +4381,12 @@ function SwypePaymentInner({
|
|
|
4345
4381
|
useEffect(() => {
|
|
4346
4382
|
if (!polling.transfer) return;
|
|
4347
4383
|
if (polling.transfer.status === "COMPLETED") {
|
|
4384
|
+
clearMobileFlowState();
|
|
4348
4385
|
setStep("success");
|
|
4349
4386
|
setTransfer(polling.transfer);
|
|
4350
4387
|
onComplete?.(polling.transfer);
|
|
4351
4388
|
} else if (polling.transfer.status === "FAILED") {
|
|
4389
|
+
clearMobileFlowState();
|
|
4352
4390
|
setStep("success");
|
|
4353
4391
|
setTransfer(polling.transfer);
|
|
4354
4392
|
setError("Transfer failed.");
|
|
@@ -4386,6 +4424,7 @@ function SwypePaymentInner({
|
|
|
4386
4424
|
if (!polledTransfer || polledTransfer.status !== "AUTHORIZED") return;
|
|
4387
4425
|
if (mobileSetupFlowRef.current) {
|
|
4388
4426
|
mobileSetupFlowRef.current = false;
|
|
4427
|
+
clearMobileFlowState();
|
|
4389
4428
|
setMobileFlow(false);
|
|
4390
4429
|
setDeeplinkUri(null);
|
|
4391
4430
|
polling.stopPolling();
|
|
@@ -4402,6 +4441,8 @@ function SwypePaymentInner({
|
|
|
4402
4441
|
try {
|
|
4403
4442
|
const signedTransfer = await transferSigning.signTransfer(polledTransfer.id);
|
|
4404
4443
|
setTransfer(signedTransfer);
|
|
4444
|
+
clearMobileFlowState();
|
|
4445
|
+
setStep("processing");
|
|
4405
4446
|
} catch (err) {
|
|
4406
4447
|
mobileSigningTransferIdRef.current = null;
|
|
4407
4448
|
const msg = err instanceof Error ? err.message : "Failed to sign transfer";
|
|
@@ -4596,6 +4637,12 @@ function SwypePaymentInner({
|
|
|
4596
4637
|
polling.startPolling(t.id);
|
|
4597
4638
|
setDeeplinkUri(uri);
|
|
4598
4639
|
setStep("open-wallet");
|
|
4640
|
+
persistMobileFlowState({
|
|
4641
|
+
transferId: t.id,
|
|
4642
|
+
deeplinkUri: uri,
|
|
4643
|
+
providerId: selectedProviderId,
|
|
4644
|
+
isSetup: mobileSetupFlowRef.current
|
|
4645
|
+
});
|
|
4599
4646
|
if (!isInIframe()) {
|
|
4600
4647
|
window.location.href = uri;
|
|
4601
4648
|
}
|
|
@@ -4712,6 +4759,7 @@ function SwypePaymentInner({
|
|
|
4712
4759
|
[accounts]
|
|
4713
4760
|
);
|
|
4714
4761
|
const handleNewPayment = useCallback(() => {
|
|
4762
|
+
clearMobileFlowState();
|
|
4715
4763
|
setStep("deposit");
|
|
4716
4764
|
setTransfer(null);
|
|
4717
4765
|
setError(null);
|
|
@@ -4730,6 +4778,7 @@ function SwypePaymentInner({
|
|
|
4730
4778
|
await logout();
|
|
4731
4779
|
} catch {
|
|
4732
4780
|
}
|
|
4781
|
+
clearMobileFlowState();
|
|
4733
4782
|
if (typeof window !== "undefined") {
|
|
4734
4783
|
window.localStorage.removeItem(ACTIVE_CREDENTIAL_STORAGE_KEY);
|
|
4735
4784
|
}
|