@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 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
  ],
@@ -4010,7 +4010,29 @@ function isInIframe() {
4010
4010
  }
4011
4011
  }
4012
4012
  var ACTIVE_CREDENTIAL_STORAGE_KEY = "swype_active_credential_id";
4013
+ var MOBILE_FLOW_STORAGE_KEY = "swype_mobile_flow";
4013
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
+ }
4014
4036
  function computeSmartDefaults(accts, transferAmount) {
4015
4037
  if (accts.length === 0) return null;
4016
4038
  for (const acct of accts) {
@@ -4253,6 +4275,20 @@ function SwypePaymentInner({
4253
4275
  let cancelled = false;
4254
4276
  setError(null);
4255
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
+ };
4256
4292
  const checkPasskey = async () => {
4257
4293
  try {
4258
4294
  const token = await getAccessToken();
@@ -4268,7 +4304,7 @@ function SwypePaymentInner({
4268
4304
  return;
4269
4305
  }
4270
4306
  if (activeCredentialId && allPasskeys.some((p) => p.credentialId === activeCredentialId)) {
4271
- setStep("deposit");
4307
+ restoreOrDeposit();
4272
4308
  return;
4273
4309
  }
4274
4310
  if (cancelled) return;
@@ -4278,7 +4314,7 @@ function SwypePaymentInner({
4278
4314
  if (matched) {
4279
4315
  setActiveCredentialId(matched);
4280
4316
  window.localStorage.setItem(ACTIVE_CREDENTIAL_STORAGE_KEY, matched);
4281
- setStep("deposit");
4317
+ restoreOrDeposit();
4282
4318
  return;
4283
4319
  }
4284
4320
  setStep("create-passkey");
@@ -4348,10 +4384,12 @@ function SwypePaymentInner({
4348
4384
  react.useEffect(() => {
4349
4385
  if (!polling.transfer) return;
4350
4386
  if (polling.transfer.status === "COMPLETED") {
4387
+ clearMobileFlowState();
4351
4388
  setStep("success");
4352
4389
  setTransfer(polling.transfer);
4353
4390
  onComplete?.(polling.transfer);
4354
4391
  } else if (polling.transfer.status === "FAILED") {
4392
+ clearMobileFlowState();
4355
4393
  setStep("success");
4356
4394
  setTransfer(polling.transfer);
4357
4395
  setError("Transfer failed.");
@@ -4389,6 +4427,7 @@ function SwypePaymentInner({
4389
4427
  if (!polledTransfer || polledTransfer.status !== "AUTHORIZED") return;
4390
4428
  if (mobileSetupFlowRef.current) {
4391
4429
  mobileSetupFlowRef.current = false;
4430
+ clearMobileFlowState();
4392
4431
  setMobileFlow(false);
4393
4432
  setDeeplinkUri(null);
4394
4433
  polling.stopPolling();
@@ -4405,6 +4444,8 @@ function SwypePaymentInner({
4405
4444
  try {
4406
4445
  const signedTransfer = await transferSigning.signTransfer(polledTransfer.id);
4407
4446
  setTransfer(signedTransfer);
4447
+ clearMobileFlowState();
4448
+ setStep("processing");
4408
4449
  } catch (err) {
4409
4450
  mobileSigningTransferIdRef.current = null;
4410
4451
  const msg = err instanceof Error ? err.message : "Failed to sign transfer";
@@ -4599,6 +4640,12 @@ function SwypePaymentInner({
4599
4640
  polling.startPolling(t.id);
4600
4641
  setDeeplinkUri(uri);
4601
4642
  setStep("open-wallet");
4643
+ persistMobileFlowState({
4644
+ transferId: t.id,
4645
+ deeplinkUri: uri,
4646
+ providerId: selectedProviderId,
4647
+ isSetup: mobileSetupFlowRef.current
4648
+ });
4602
4649
  if (!isInIframe()) {
4603
4650
  window.location.href = uri;
4604
4651
  }
@@ -4715,6 +4762,7 @@ function SwypePaymentInner({
4715
4762
  [accounts]
4716
4763
  );
4717
4764
  const handleNewPayment = react.useCallback(() => {
4765
+ clearMobileFlowState();
4718
4766
  setStep("deposit");
4719
4767
  setTransfer(null);
4720
4768
  setError(null);
@@ -4733,6 +4781,7 @@ function SwypePaymentInner({
4733
4781
  await logout();
4734
4782
  } catch {
4735
4783
  }
4784
+ clearMobileFlowState();
4736
4785
  if (typeof window !== "undefined") {
4737
4786
  window.localStorage.removeItem(ACTIVE_CREDENTIAL_STORAGE_KEY);
4738
4787
  }