@swype-org/react-sdk 0.1.53 → 0.1.56

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.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
- symbol: string;
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
- symbol: string;
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: { symbol: params.destination.token.symbol },
215
+ token: { address: params.destination.token.address },
216
216
  address: params.destination.address
217
217
  }
218
218
  ],
@@ -1892,6 +1892,7 @@ var containerStyle5 = {
1892
1892
  width: "100%"
1893
1893
  };
1894
1894
  var inputStyle = (tokens, filled) => ({
1895
+ boxSizing: "border-box",
1895
1896
  width: 44,
1896
1897
  maxWidth: "calc((100% - 40px) / 6)",
1897
1898
  height: 52,
@@ -4007,7 +4008,29 @@ function isInIframe() {
4007
4008
  }
4008
4009
  }
4009
4010
  var ACTIVE_CREDENTIAL_STORAGE_KEY = "swype_active_credential_id";
4011
+ var MOBILE_FLOW_STORAGE_KEY = "swype_mobile_flow";
4010
4012
  var MIN_SEND_AMOUNT_USD = 0.25;
4013
+ function persistMobileFlowState(data) {
4014
+ try {
4015
+ sessionStorage.setItem(MOBILE_FLOW_STORAGE_KEY, JSON.stringify(data));
4016
+ } catch {
4017
+ }
4018
+ }
4019
+ function loadMobileFlowState() {
4020
+ try {
4021
+ const raw = sessionStorage.getItem(MOBILE_FLOW_STORAGE_KEY);
4022
+ if (!raw) return null;
4023
+ return JSON.parse(raw);
4024
+ } catch {
4025
+ return null;
4026
+ }
4027
+ }
4028
+ function clearMobileFlowState() {
4029
+ try {
4030
+ sessionStorage.removeItem(MOBILE_FLOW_STORAGE_KEY);
4031
+ } catch {
4032
+ }
4033
+ }
4011
4034
  function computeSmartDefaults(accts, transferAmount) {
4012
4035
  if (accts.length === 0) return null;
4013
4036
  for (const acct of accts) {
@@ -4250,6 +4273,20 @@ function SwypePaymentInner({
4250
4273
  let cancelled = false;
4251
4274
  setError(null);
4252
4275
  resetHeadlessLogin();
4276
+ const restoreOrDeposit = () => {
4277
+ const persisted = loadMobileFlowState();
4278
+ if (persisted) {
4279
+ setMobileFlow(true);
4280
+ setDeeplinkUri(persisted.deeplinkUri);
4281
+ setSelectedProviderId(persisted.providerId);
4282
+ pollingTransferIdRef.current = persisted.transferId;
4283
+ mobileSetupFlowRef.current = persisted.isSetup;
4284
+ setStep("open-wallet");
4285
+ polling.startPolling(persisted.transferId);
4286
+ } else {
4287
+ setStep("deposit");
4288
+ }
4289
+ };
4253
4290
  const checkPasskey = async () => {
4254
4291
  try {
4255
4292
  const token = await getAccessToken();
@@ -4265,7 +4302,7 @@ function SwypePaymentInner({
4265
4302
  return;
4266
4303
  }
4267
4304
  if (activeCredentialId && allPasskeys.some((p) => p.credentialId === activeCredentialId)) {
4268
- setStep("deposit");
4305
+ restoreOrDeposit();
4269
4306
  return;
4270
4307
  }
4271
4308
  if (cancelled) return;
@@ -4275,7 +4312,7 @@ function SwypePaymentInner({
4275
4312
  if (matched) {
4276
4313
  setActiveCredentialId(matched);
4277
4314
  window.localStorage.setItem(ACTIVE_CREDENTIAL_STORAGE_KEY, matched);
4278
- setStep("deposit");
4315
+ restoreOrDeposit();
4279
4316
  return;
4280
4317
  }
4281
4318
  setStep("create-passkey");
@@ -4345,10 +4382,12 @@ function SwypePaymentInner({
4345
4382
  useEffect(() => {
4346
4383
  if (!polling.transfer) return;
4347
4384
  if (polling.transfer.status === "COMPLETED") {
4385
+ clearMobileFlowState();
4348
4386
  setStep("success");
4349
4387
  setTransfer(polling.transfer);
4350
4388
  onComplete?.(polling.transfer);
4351
4389
  } else if (polling.transfer.status === "FAILED") {
4390
+ clearMobileFlowState();
4352
4391
  setStep("success");
4353
4392
  setTransfer(polling.transfer);
4354
4393
  setError("Transfer failed.");
@@ -4386,13 +4425,15 @@ function SwypePaymentInner({
4386
4425
  if (!polledTransfer || polledTransfer.status !== "AUTHORIZED") return;
4387
4426
  if (mobileSetupFlowRef.current) {
4388
4427
  mobileSetupFlowRef.current = false;
4389
- setMobileFlow(false);
4428
+ clearMobileFlowState();
4390
4429
  setDeeplinkUri(null);
4391
4430
  polling.stopPolling();
4392
4431
  setTransfer(polledTransfer);
4393
4432
  reloadAccounts().catch(() => {
4433
+ }).then(() => {
4434
+ setMobileFlow(false);
4435
+ setStep("deposit");
4394
4436
  });
4395
- setStep("deposit");
4396
4437
  return;
4397
4438
  }
4398
4439
  if (transferSigning.signing) return;
@@ -4402,6 +4443,8 @@ function SwypePaymentInner({
4402
4443
  try {
4403
4444
  const signedTransfer = await transferSigning.signTransfer(polledTransfer.id);
4404
4445
  setTransfer(signedTransfer);
4446
+ clearMobileFlowState();
4447
+ setStep("processing");
4405
4448
  } catch (err) {
4406
4449
  mobileSigningTransferIdRef.current = null;
4407
4450
  const msg = err instanceof Error ? err.message : "Failed to sign transfer";
@@ -4596,6 +4639,12 @@ function SwypePaymentInner({
4596
4639
  polling.startPolling(t.id);
4597
4640
  setDeeplinkUri(uri);
4598
4641
  setStep("open-wallet");
4642
+ persistMobileFlowState({
4643
+ transferId: t.id,
4644
+ deeplinkUri: uri,
4645
+ providerId: selectedProviderId,
4646
+ isSetup: mobileSetupFlowRef.current
4647
+ });
4599
4648
  if (!isInIframe()) {
4600
4649
  window.location.href = uri;
4601
4650
  }
@@ -4712,6 +4761,7 @@ function SwypePaymentInner({
4712
4761
  [accounts]
4713
4762
  );
4714
4763
  const handleNewPayment = useCallback(() => {
4764
+ clearMobileFlowState();
4715
4765
  setStep("deposit");
4716
4766
  setTransfer(null);
4717
4767
  setError(null);
@@ -4730,6 +4780,7 @@ function SwypePaymentInner({
4730
4780
  await logout();
4731
4781
  } catch {
4732
4782
  }
4783
+ clearMobileFlowState();
4733
4784
  if (typeof window !== "undefined") {
4734
4785
  window.localStorage.removeItem(ACTIVE_CREDENTIAL_STORAGE_KEY);
4735
4786
  }