@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.cjs CHANGED
@@ -215,7 +215,7 @@ async function createTransfer(apiBaseUrl, token, params) {
215
215
  destinations: [
216
216
  {
217
217
  chainId: params.destination.chainId,
218
- token: { symbol: params.destination.token.symbol },
218
+ token: { address: params.destination.token.address },
219
219
  address: params.destination.address
220
220
  }
221
221
  ],
@@ -1908,8 +1908,7 @@ var inputStyle = (tokens, filled) => ({
1908
1908
  textAlign: "center",
1909
1909
  outline: "none",
1910
1910
  caretColor: tokens.borderFocus,
1911
- transition: "border-color 0.15s ease",
1912
- flexShrink: 0
1911
+ transition: "border-color 0.15s ease"
1913
1912
  });
1914
1913
  function LimitSlider({
1915
1914
  value,
@@ -4011,7 +4010,29 @@ function isInIframe() {
4011
4010
  }
4012
4011
  }
4013
4012
  var ACTIVE_CREDENTIAL_STORAGE_KEY = "swype_active_credential_id";
4013
+ var MOBILE_FLOW_STORAGE_KEY = "swype_mobile_flow";
4014
4014
  var MIN_SEND_AMOUNT_USD = 0.25;
4015
+ function persistMobileFlowState(data) {
4016
+ try {
4017
+ sessionStorage.setItem(MOBILE_FLOW_STORAGE_KEY, JSON.stringify(data));
4018
+ } catch {
4019
+ }
4020
+ }
4021
+ function loadMobileFlowState() {
4022
+ try {
4023
+ const raw = sessionStorage.getItem(MOBILE_FLOW_STORAGE_KEY);
4024
+ if (!raw) return null;
4025
+ return JSON.parse(raw);
4026
+ } catch {
4027
+ return null;
4028
+ }
4029
+ }
4030
+ function clearMobileFlowState() {
4031
+ try {
4032
+ sessionStorage.removeItem(MOBILE_FLOW_STORAGE_KEY);
4033
+ } catch {
4034
+ }
4035
+ }
4015
4036
  function computeSmartDefaults(accts, transferAmount) {
4016
4037
  if (accts.length === 0) return null;
4017
4038
  for (const acct of accts) {
@@ -4230,6 +4251,11 @@ function SwypePaymentInner({
4230
4251
  setError(err instanceof Error ? err.message : "Failed to verify code");
4231
4252
  }
4232
4253
  }, [verificationTarget, otpCode, loginWithEmailCode, loginWithSmsCode]);
4254
+ react.useEffect(() => {
4255
+ if (step === "otp-verify" && /^\d{6}$/.test(otpCode.trim()) && activeOtpStatus !== "submitting-code") {
4256
+ handleVerifyLoginCode();
4257
+ }
4258
+ }, [otpCode, step, activeOtpStatus, handleVerifyLoginCode]);
4233
4259
  const handleResendLoginCode = react.useCallback(async () => {
4234
4260
  if (!verificationTarget) return;
4235
4261
  setError(null);
@@ -4249,6 +4275,20 @@ function SwypePaymentInner({
4249
4275
  let cancelled = false;
4250
4276
  setError(null);
4251
4277
  resetHeadlessLogin();
4278
+ const restoreOrDeposit = () => {
4279
+ const persisted = loadMobileFlowState();
4280
+ if (persisted) {
4281
+ setMobileFlow(true);
4282
+ setDeeplinkUri(persisted.deeplinkUri);
4283
+ setSelectedProviderId(persisted.providerId);
4284
+ pollingTransferIdRef.current = persisted.transferId;
4285
+ mobileSetupFlowRef.current = persisted.isSetup;
4286
+ setStep("open-wallet");
4287
+ polling.startPolling(persisted.transferId);
4288
+ } else {
4289
+ setStep("deposit");
4290
+ }
4291
+ };
4252
4292
  const checkPasskey = async () => {
4253
4293
  try {
4254
4294
  const token = await getAccessToken();
@@ -4264,7 +4304,7 @@ function SwypePaymentInner({
4264
4304
  return;
4265
4305
  }
4266
4306
  if (activeCredentialId && allPasskeys.some((p) => p.credentialId === activeCredentialId)) {
4267
- setStep("deposit");
4307
+ restoreOrDeposit();
4268
4308
  return;
4269
4309
  }
4270
4310
  if (cancelled) return;
@@ -4274,7 +4314,7 @@ function SwypePaymentInner({
4274
4314
  if (matched) {
4275
4315
  setActiveCredentialId(matched);
4276
4316
  window.localStorage.setItem(ACTIVE_CREDENTIAL_STORAGE_KEY, matched);
4277
- setStep("deposit");
4317
+ restoreOrDeposit();
4278
4318
  return;
4279
4319
  }
4280
4320
  setStep("create-passkey");
@@ -4344,10 +4384,12 @@ function SwypePaymentInner({
4344
4384
  react.useEffect(() => {
4345
4385
  if (!polling.transfer) return;
4346
4386
  if (polling.transfer.status === "COMPLETED") {
4387
+ clearMobileFlowState();
4347
4388
  setStep("success");
4348
4389
  setTransfer(polling.transfer);
4349
4390
  onComplete?.(polling.transfer);
4350
4391
  } else if (polling.transfer.status === "FAILED") {
4392
+ clearMobileFlowState();
4351
4393
  setStep("success");
4352
4394
  setTransfer(polling.transfer);
4353
4395
  setError("Transfer failed.");
@@ -4385,6 +4427,7 @@ function SwypePaymentInner({
4385
4427
  if (!polledTransfer || polledTransfer.status !== "AUTHORIZED") return;
4386
4428
  if (mobileSetupFlowRef.current) {
4387
4429
  mobileSetupFlowRef.current = false;
4430
+ clearMobileFlowState();
4388
4431
  setMobileFlow(false);
4389
4432
  setDeeplinkUri(null);
4390
4433
  polling.stopPolling();
@@ -4401,6 +4444,8 @@ function SwypePaymentInner({
4401
4444
  try {
4402
4445
  const signedTransfer = await transferSigning.signTransfer(polledTransfer.id);
4403
4446
  setTransfer(signedTransfer);
4447
+ clearMobileFlowState();
4448
+ setStep("processing");
4404
4449
  } catch (err) {
4405
4450
  mobileSigningTransferIdRef.current = null;
4406
4451
  const msg = err instanceof Error ? err.message : "Failed to sign transfer";
@@ -4595,6 +4640,12 @@ function SwypePaymentInner({
4595
4640
  polling.startPolling(t.id);
4596
4641
  setDeeplinkUri(uri);
4597
4642
  setStep("open-wallet");
4643
+ persistMobileFlowState({
4644
+ transferId: t.id,
4645
+ deeplinkUri: uri,
4646
+ providerId: selectedProviderId,
4647
+ isSetup: mobileSetupFlowRef.current
4648
+ });
4598
4649
  if (!isInIframe()) {
4599
4650
  window.location.href = uri;
4600
4651
  }
@@ -4711,6 +4762,7 @@ function SwypePaymentInner({
4711
4762
  [accounts]
4712
4763
  );
4713
4764
  const handleNewPayment = react.useCallback(() => {
4765
+ clearMobileFlowState();
4714
4766
  setStep("deposit");
4715
4767
  setTransfer(null);
4716
4768
  setError(null);
@@ -4729,6 +4781,7 @@ function SwypePaymentInner({
4729
4781
  await logout();
4730
4782
  } catch {
4731
4783
  }
4784
+ clearMobileFlowState();
4732
4785
  if (typeof window !== "undefined") {
4733
4786
  window.localStorage.removeItem(ACTIVE_CREDENTIAL_STORAGE_KEY);
4734
4787
  }