@swype-org/react-sdk 0.1.52 → 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.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
  ],
@@ -1905,8 +1905,7 @@ var inputStyle = (tokens, filled) => ({
1905
1905
  textAlign: "center",
1906
1906
  outline: "none",
1907
1907
  caretColor: tokens.borderFocus,
1908
- transition: "border-color 0.15s ease",
1909
- flexShrink: 0
1908
+ transition: "border-color 0.15s ease"
1910
1909
  });
1911
1910
  function LimitSlider({
1912
1911
  value,
@@ -4008,7 +4007,29 @@ function isInIframe() {
4008
4007
  }
4009
4008
  }
4010
4009
  var ACTIVE_CREDENTIAL_STORAGE_KEY = "swype_active_credential_id";
4010
+ var MOBILE_FLOW_STORAGE_KEY = "swype_mobile_flow";
4011
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
+ }
4012
4033
  function computeSmartDefaults(accts, transferAmount) {
4013
4034
  if (accts.length === 0) return null;
4014
4035
  for (const acct of accts) {
@@ -4227,6 +4248,11 @@ function SwypePaymentInner({
4227
4248
  setError(err instanceof Error ? err.message : "Failed to verify code");
4228
4249
  }
4229
4250
  }, [verificationTarget, otpCode, loginWithEmailCode, loginWithSmsCode]);
4251
+ useEffect(() => {
4252
+ if (step === "otp-verify" && /^\d{6}$/.test(otpCode.trim()) && activeOtpStatus !== "submitting-code") {
4253
+ handleVerifyLoginCode();
4254
+ }
4255
+ }, [otpCode, step, activeOtpStatus, handleVerifyLoginCode]);
4230
4256
  const handleResendLoginCode = useCallback(async () => {
4231
4257
  if (!verificationTarget) return;
4232
4258
  setError(null);
@@ -4246,6 +4272,20 @@ function SwypePaymentInner({
4246
4272
  let cancelled = false;
4247
4273
  setError(null);
4248
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
+ };
4249
4289
  const checkPasskey = async () => {
4250
4290
  try {
4251
4291
  const token = await getAccessToken();
@@ -4261,7 +4301,7 @@ function SwypePaymentInner({
4261
4301
  return;
4262
4302
  }
4263
4303
  if (activeCredentialId && allPasskeys.some((p) => p.credentialId === activeCredentialId)) {
4264
- setStep("deposit");
4304
+ restoreOrDeposit();
4265
4305
  return;
4266
4306
  }
4267
4307
  if (cancelled) return;
@@ -4271,7 +4311,7 @@ function SwypePaymentInner({
4271
4311
  if (matched) {
4272
4312
  setActiveCredentialId(matched);
4273
4313
  window.localStorage.setItem(ACTIVE_CREDENTIAL_STORAGE_KEY, matched);
4274
- setStep("deposit");
4314
+ restoreOrDeposit();
4275
4315
  return;
4276
4316
  }
4277
4317
  setStep("create-passkey");
@@ -4341,10 +4381,12 @@ function SwypePaymentInner({
4341
4381
  useEffect(() => {
4342
4382
  if (!polling.transfer) return;
4343
4383
  if (polling.transfer.status === "COMPLETED") {
4384
+ clearMobileFlowState();
4344
4385
  setStep("success");
4345
4386
  setTransfer(polling.transfer);
4346
4387
  onComplete?.(polling.transfer);
4347
4388
  } else if (polling.transfer.status === "FAILED") {
4389
+ clearMobileFlowState();
4348
4390
  setStep("success");
4349
4391
  setTransfer(polling.transfer);
4350
4392
  setError("Transfer failed.");
@@ -4382,6 +4424,7 @@ function SwypePaymentInner({
4382
4424
  if (!polledTransfer || polledTransfer.status !== "AUTHORIZED") return;
4383
4425
  if (mobileSetupFlowRef.current) {
4384
4426
  mobileSetupFlowRef.current = false;
4427
+ clearMobileFlowState();
4385
4428
  setMobileFlow(false);
4386
4429
  setDeeplinkUri(null);
4387
4430
  polling.stopPolling();
@@ -4398,6 +4441,8 @@ function SwypePaymentInner({
4398
4441
  try {
4399
4442
  const signedTransfer = await transferSigning.signTransfer(polledTransfer.id);
4400
4443
  setTransfer(signedTransfer);
4444
+ clearMobileFlowState();
4445
+ setStep("processing");
4401
4446
  } catch (err) {
4402
4447
  mobileSigningTransferIdRef.current = null;
4403
4448
  const msg = err instanceof Error ? err.message : "Failed to sign transfer";
@@ -4592,6 +4637,12 @@ function SwypePaymentInner({
4592
4637
  polling.startPolling(t.id);
4593
4638
  setDeeplinkUri(uri);
4594
4639
  setStep("open-wallet");
4640
+ persistMobileFlowState({
4641
+ transferId: t.id,
4642
+ deeplinkUri: uri,
4643
+ providerId: selectedProviderId,
4644
+ isSetup: mobileSetupFlowRef.current
4645
+ });
4595
4646
  if (!isInIframe()) {
4596
4647
  window.location.href = uri;
4597
4648
  }
@@ -4708,6 +4759,7 @@ function SwypePaymentInner({
4708
4759
  [accounts]
4709
4760
  );
4710
4761
  const handleNewPayment = useCallback(() => {
4762
+ clearMobileFlowState();
4711
4763
  setStep("deposit");
4712
4764
  setTransfer(null);
4713
4765
  setError(null);
@@ -4726,6 +4778,7 @@ function SwypePaymentInner({
4726
4778
  await logout();
4727
4779
  } catch {
4728
4780
  }
4781
+ clearMobileFlowState();
4729
4782
  if (typeof window !== "undefined") {
4730
4783
  window.localStorage.removeItem(ACTIVE_CREDENTIAL_STORAGE_KEY);
4731
4784
  }