@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.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
  ],
@@ -1895,6 +1895,7 @@ var containerStyle5 = {
1895
1895
  width: "100%"
1896
1896
  };
1897
1897
  var inputStyle = (tokens, filled) => ({
1898
+ boxSizing: "border-box",
1898
1899
  width: 44,
1899
1900
  maxWidth: "calc((100% - 40px) / 6)",
1900
1901
  height: 52,
@@ -4010,7 +4011,29 @@ function isInIframe() {
4010
4011
  }
4011
4012
  }
4012
4013
  var ACTIVE_CREDENTIAL_STORAGE_KEY = "swype_active_credential_id";
4014
+ var MOBILE_FLOW_STORAGE_KEY = "swype_mobile_flow";
4013
4015
  var MIN_SEND_AMOUNT_USD = 0.25;
4016
+ function persistMobileFlowState(data) {
4017
+ try {
4018
+ sessionStorage.setItem(MOBILE_FLOW_STORAGE_KEY, JSON.stringify(data));
4019
+ } catch {
4020
+ }
4021
+ }
4022
+ function loadMobileFlowState() {
4023
+ try {
4024
+ const raw = sessionStorage.getItem(MOBILE_FLOW_STORAGE_KEY);
4025
+ if (!raw) return null;
4026
+ return JSON.parse(raw);
4027
+ } catch {
4028
+ return null;
4029
+ }
4030
+ }
4031
+ function clearMobileFlowState() {
4032
+ try {
4033
+ sessionStorage.removeItem(MOBILE_FLOW_STORAGE_KEY);
4034
+ } catch {
4035
+ }
4036
+ }
4014
4037
  function computeSmartDefaults(accts, transferAmount) {
4015
4038
  if (accts.length === 0) return null;
4016
4039
  for (const acct of accts) {
@@ -4253,6 +4276,20 @@ function SwypePaymentInner({
4253
4276
  let cancelled = false;
4254
4277
  setError(null);
4255
4278
  resetHeadlessLogin();
4279
+ const restoreOrDeposit = () => {
4280
+ const persisted = loadMobileFlowState();
4281
+ if (persisted) {
4282
+ setMobileFlow(true);
4283
+ setDeeplinkUri(persisted.deeplinkUri);
4284
+ setSelectedProviderId(persisted.providerId);
4285
+ pollingTransferIdRef.current = persisted.transferId;
4286
+ mobileSetupFlowRef.current = persisted.isSetup;
4287
+ setStep("open-wallet");
4288
+ polling.startPolling(persisted.transferId);
4289
+ } else {
4290
+ setStep("deposit");
4291
+ }
4292
+ };
4256
4293
  const checkPasskey = async () => {
4257
4294
  try {
4258
4295
  const token = await getAccessToken();
@@ -4268,7 +4305,7 @@ function SwypePaymentInner({
4268
4305
  return;
4269
4306
  }
4270
4307
  if (activeCredentialId && allPasskeys.some((p) => p.credentialId === activeCredentialId)) {
4271
- setStep("deposit");
4308
+ restoreOrDeposit();
4272
4309
  return;
4273
4310
  }
4274
4311
  if (cancelled) return;
@@ -4278,7 +4315,7 @@ function SwypePaymentInner({
4278
4315
  if (matched) {
4279
4316
  setActiveCredentialId(matched);
4280
4317
  window.localStorage.setItem(ACTIVE_CREDENTIAL_STORAGE_KEY, matched);
4281
- setStep("deposit");
4318
+ restoreOrDeposit();
4282
4319
  return;
4283
4320
  }
4284
4321
  setStep("create-passkey");
@@ -4348,10 +4385,12 @@ function SwypePaymentInner({
4348
4385
  react.useEffect(() => {
4349
4386
  if (!polling.transfer) return;
4350
4387
  if (polling.transfer.status === "COMPLETED") {
4388
+ clearMobileFlowState();
4351
4389
  setStep("success");
4352
4390
  setTransfer(polling.transfer);
4353
4391
  onComplete?.(polling.transfer);
4354
4392
  } else if (polling.transfer.status === "FAILED") {
4393
+ clearMobileFlowState();
4355
4394
  setStep("success");
4356
4395
  setTransfer(polling.transfer);
4357
4396
  setError("Transfer failed.");
@@ -4389,13 +4428,15 @@ function SwypePaymentInner({
4389
4428
  if (!polledTransfer || polledTransfer.status !== "AUTHORIZED") return;
4390
4429
  if (mobileSetupFlowRef.current) {
4391
4430
  mobileSetupFlowRef.current = false;
4392
- setMobileFlow(false);
4431
+ clearMobileFlowState();
4393
4432
  setDeeplinkUri(null);
4394
4433
  polling.stopPolling();
4395
4434
  setTransfer(polledTransfer);
4396
4435
  reloadAccounts().catch(() => {
4436
+ }).then(() => {
4437
+ setMobileFlow(false);
4438
+ setStep("deposit");
4397
4439
  });
4398
- setStep("deposit");
4399
4440
  return;
4400
4441
  }
4401
4442
  if (transferSigning.signing) return;
@@ -4405,6 +4446,8 @@ function SwypePaymentInner({
4405
4446
  try {
4406
4447
  const signedTransfer = await transferSigning.signTransfer(polledTransfer.id);
4407
4448
  setTransfer(signedTransfer);
4449
+ clearMobileFlowState();
4450
+ setStep("processing");
4408
4451
  } catch (err) {
4409
4452
  mobileSigningTransferIdRef.current = null;
4410
4453
  const msg = err instanceof Error ? err.message : "Failed to sign transfer";
@@ -4599,6 +4642,12 @@ function SwypePaymentInner({
4599
4642
  polling.startPolling(t.id);
4600
4643
  setDeeplinkUri(uri);
4601
4644
  setStep("open-wallet");
4645
+ persistMobileFlowState({
4646
+ transferId: t.id,
4647
+ deeplinkUri: uri,
4648
+ providerId: selectedProviderId,
4649
+ isSetup: mobileSetupFlowRef.current
4650
+ });
4602
4651
  if (!isInIframe()) {
4603
4652
  window.location.href = uri;
4604
4653
  }
@@ -4715,6 +4764,7 @@ function SwypePaymentInner({
4715
4764
  [accounts]
4716
4765
  );
4717
4766
  const handleNewPayment = react.useCallback(() => {
4767
+ clearMobileFlowState();
4718
4768
  setStep("deposit");
4719
4769
  setTransfer(null);
4720
4770
  setError(null);
@@ -4733,6 +4783,7 @@ function SwypePaymentInner({
4733
4783
  await logout();
4734
4784
  } catch {
4735
4785
  }
4786
+ clearMobileFlowState();
4736
4787
  if (typeof window !== "undefined") {
4737
4788
  window.localStorage.removeItem(ACTIVE_CREDENTIAL_STORAGE_KEY);
4738
4789
  }