@swype-org/react-sdk 0.1.131 → 0.1.133

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
@@ -767,9 +767,10 @@ interface SelectSourceScreenProps {
767
767
  onChainChange: (chainName: string) => void;
768
768
  onTokenChange: (tokenSymbol: string) => void;
769
769
  onConfirm: () => void;
770
+ onBack?: () => void;
770
771
  onLogout: () => void;
771
772
  }
772
- declare function SelectSourceScreen({ choices, selectedChainName, selectedTokenSymbol, recommended, onChainChange, onTokenChange, onConfirm, onLogout, }: SelectSourceScreenProps): react_jsx_runtime.JSX.Element;
773
+ declare function SelectSourceScreen({ choices, selectedChainName, selectedTokenSymbol, recommended, onChainChange, onTokenChange, onConfirm, onBack, onLogout, }: SelectSourceScreenProps): react_jsx_runtime.JSX.Element;
773
774
 
774
775
  interface ChainChoice {
775
776
  chainName: string;
package/dist/index.d.ts CHANGED
@@ -767,9 +767,10 @@ interface SelectSourceScreenProps {
767
767
  onChainChange: (chainName: string) => void;
768
768
  onTokenChange: (tokenSymbol: string) => void;
769
769
  onConfirm: () => void;
770
+ onBack?: () => void;
770
771
  onLogout: () => void;
771
772
  }
772
- declare function SelectSourceScreen({ choices, selectedChainName, selectedTokenSymbol, recommended, onChainChange, onTokenChange, onConfirm, onLogout, }: SelectSourceScreenProps): react_jsx_runtime.JSX.Element;
773
+ declare function SelectSourceScreen({ choices, selectedChainName, selectedTokenSymbol, recommended, onChainChange, onTokenChange, onConfirm, onBack, onLogout, }: SelectSourceScreenProps): react_jsx_runtime.JSX.Element;
773
774
 
774
775
  interface ChainChoice {
775
776
  chainName: string;
package/dist/index.js CHANGED
@@ -4248,7 +4248,9 @@ function DepositScreen({
4248
4248
  onSelectAccount,
4249
4249
  onAuthorizeAccount,
4250
4250
  onAddProvider,
4251
- onSelectToken
4251
+ onSelectToken,
4252
+ pendingSetup,
4253
+ onStartSetup
4252
4254
  }) {
4253
4255
  const { tokens } = useSwypeConfig();
4254
4256
  const amount = initialAmount;
@@ -4256,6 +4258,29 @@ function DepositScreen({
4256
4258
  const exceedsLimit = amount > remainingLimit && !isLowBalance;
4257
4259
  const canDeposit = amount >= MIN_DEPOSIT && !exceedsLimit && !isLowBalance && !processing;
4258
4260
  const headerTitle = merchantName ? `Deposit to ${merchantName}` : "Deposit";
4261
+ if (pendingSetup) {
4262
+ return /* @__PURE__ */ jsxs(
4263
+ ScreenLayout,
4264
+ {
4265
+ footer: /* @__PURE__ */ jsxs(Fragment, { children: [
4266
+ /* @__PURE__ */ jsx(PrimaryButton, { onClick: onStartSetup, children: "Set up One-Tap" }),
4267
+ /* @__PURE__ */ jsx("p", { style: setupHintStyle(tokens.textSecondary), children: "Choose your source and set your One-Tap limit to deposit instantly." }),
4268
+ /* @__PURE__ */ jsx(PoweredByFooter, {})
4269
+ ] }),
4270
+ children: [
4271
+ /* @__PURE__ */ jsx(ScreenHeader, { title: headerTitle, right: /* @__PURE__ */ jsx(SettingsMenu, { onLogout }) }),
4272
+ /* @__PURE__ */ jsxs("div", { style: setupContentStyle, children: [
4273
+ /* @__PURE__ */ jsx("div", { style: amountDisplayStyle, children: /* @__PURE__ */ jsxs("span", { style: amountStyle(tokens), children: [
4274
+ "$",
4275
+ amount.toFixed(2)
4276
+ ] }) }),
4277
+ /* @__PURE__ */ jsx("p", { style: setupDescStyle(tokens.textSecondary), children: "Set up your payment source to deposit with One-Tap \u2014 no approvals needed after setup." })
4278
+ ] }),
4279
+ error && /* @__PURE__ */ jsx("div", { style: errorBannerStyle5(tokens), children: error })
4280
+ ]
4281
+ }
4282
+ );
4283
+ }
4259
4284
  if (isLowBalance) {
4260
4285
  return /* @__PURE__ */ jsxs(
4261
4286
  ScreenLayout,
@@ -4518,6 +4543,29 @@ var switchHintStyle = (color) => ({
4518
4543
  var outlineBtnWrapStyle = {
4519
4544
  marginBottom: 8
4520
4545
  };
4546
+ var setupContentStyle = {
4547
+ flex: 1,
4548
+ display: "flex",
4549
+ flexDirection: "column",
4550
+ alignItems: "center",
4551
+ justifyContent: "center",
4552
+ textAlign: "center",
4553
+ padding: "0 24px"
4554
+ };
4555
+ var setupDescStyle = (color) => ({
4556
+ fontSize: "0.88rem",
4557
+ color,
4558
+ margin: "8px 0 0",
4559
+ lineHeight: 1.6,
4560
+ maxWidth: 300
4561
+ });
4562
+ var setupHintStyle = (color) => ({
4563
+ textAlign: "center",
4564
+ fontSize: "0.78rem",
4565
+ color,
4566
+ margin: "12px 0 2px",
4567
+ lineHeight: 1.5
4568
+ });
4521
4569
  function SuccessScreen({
4522
4570
  amount,
4523
4571
  currency,
@@ -4725,6 +4773,7 @@ function SelectSourceScreen({
4725
4773
  onChainChange,
4726
4774
  onTokenChange,
4727
4775
  onConfirm,
4776
+ onBack,
4728
4777
  onLogout
4729
4778
  }) {
4730
4779
  const { tokens } = useSwypeConfig();
@@ -4743,6 +4792,7 @@ function SelectSourceScreen({
4743
4792
  ScreenHeader,
4744
4793
  {
4745
4794
  title: "Select Source",
4795
+ onBack,
4746
4796
  right: /* @__PURE__ */ jsx(SettingsMenu, { onLogout })
4747
4797
  }
4748
4798
  ),
@@ -5615,6 +5665,7 @@ function StepRenderer({
5615
5665
  selectSourceChainName,
5616
5666
  selectSourceTokenSymbol,
5617
5667
  savingOneTapLimit,
5668
+ pendingSetup,
5618
5669
  merchantName,
5619
5670
  onBack,
5620
5671
  onDismiss,
@@ -5731,6 +5782,8 @@ function StepRenderer({
5731
5782
  );
5732
5783
  }
5733
5784
  if (step === "setup") {
5785
+ const hasPendingSelectSource = selectSourceChoices.length > 0;
5786
+ const setupSourceLabel = hasPendingSelectSource && selectSourceChainName && selectSourceTokenSymbol ? `${selectSourceTokenSymbol} on ${selectSourceChainName}` : selectedSourceLabel;
5734
5787
  return /* @__PURE__ */ jsx(
5735
5788
  SetupScreen,
5736
5789
  {
@@ -5740,8 +5793,8 @@ function StepRenderer({
5740
5793
  onSetupOneTap: handlers.onSetupOneTap,
5741
5794
  onBack: () => handlers.onNavigate("deposit"),
5742
5795
  onLogout: handlers.onLogout,
5743
- onAdvanced: handlers.onSelectToken,
5744
- selectedSourceLabel,
5796
+ onAdvanced: hasPendingSelectSource ? () => handlers.onNavigate("select-source") : handlers.onSelectToken,
5797
+ selectedSourceLabel: setupSourceLabel,
5745
5798
  loading: savingOneTapLimit,
5746
5799
  error: state.error
5747
5800
  }
@@ -5789,7 +5842,9 @@ function StepRenderer({
5789
5842
  onSelectAccount: handlers.onSelectAccount,
5790
5843
  onAuthorizeAccount: handlers.onContinueConnection,
5791
5844
  onAddProvider: () => handlers.onNavigate("wallet-picker"),
5792
- onSelectToken: handlers.onSelectToken
5845
+ onSelectToken: handlers.onSelectToken,
5846
+ pendingSetup,
5847
+ onStartSetup: () => handlers.onNavigate("setup")
5793
5848
  }
5794
5849
  );
5795
5850
  }
@@ -5821,6 +5876,7 @@ function StepRenderer({
5821
5876
  );
5822
5877
  }
5823
5878
  if (step === "select-source") {
5879
+ const enteredFromSetup = state.previousStep === "setup";
5824
5880
  return /* @__PURE__ */ jsx(
5825
5881
  SelectSourceScreen,
5826
5882
  {
@@ -5830,7 +5886,8 @@ function StepRenderer({
5830
5886
  recommended: selectSourceRecommended,
5831
5887
  onChainChange: handlers.onSelectSourceChainChange,
5832
5888
  onTokenChange: handlers.onSetSelectSourceTokenSymbol,
5833
- onConfirm: handlers.onConfirmSelectSource,
5889
+ onConfirm: enteredFromSetup ? () => handlers.onNavigate("setup") : handlers.onConfirmSelectSource,
5890
+ onBack: enteredFromSetup ? () => handlers.onNavigate("setup") : void 0,
5834
5891
  onLogout: handlers.onLogout
5835
5892
  }
5836
5893
  );
@@ -6005,6 +6062,7 @@ function SwypePaymentInner({
6005
6062
  const preSelectSourceStepRef = useRef(null);
6006
6063
  const pendingTokenAuthRef = useRef(null);
6007
6064
  const pendingTokenSelectionRef = useRef(null);
6065
+ const pendingTokenAuthSessionRef = useRef(null);
6008
6066
  const reauthSessionIdRef = useRef(null);
6009
6067
  const reauthTokenRef = useRef(null);
6010
6068
  const checkingPasskeyRef = useRef(false);
@@ -6503,10 +6561,14 @@ function SwypePaymentInner({
6503
6561
  dispatch({ type: "MOBILE_DEEPLINK_READY", deeplinkUri: session.uri });
6504
6562
  triggerDeeplink(session.uri);
6505
6563
  } else {
6506
- dispatch({ type: "NAVIGATE", step: "setup-status" });
6507
- await authExecutor.executeSessionById(session.id);
6508
- await reloadAccounts();
6509
- pendingTokenSelectionRef.current = { walletId: _walletId, tokenSymbol };
6564
+ pendingTokenAuthSessionRef.current = {
6565
+ sessionId: session.id,
6566
+ walletId: _walletId,
6567
+ tokenSymbol,
6568
+ tokenAddress,
6569
+ chainId
6570
+ };
6571
+ dispatch({ type: "SELECT_TOKEN", walletId: _walletId, tokenSymbol });
6510
6572
  dispatch({ type: "NAVIGATE", step: "setup" });
6511
6573
  }
6512
6574
  } catch (err) {
@@ -6655,12 +6717,40 @@ function SwypePaymentInner({
6655
6717
  const token = await getAccessToken();
6656
6718
  if (!token) throw new Error("Not authenticated");
6657
6719
  await updateUserConfig(apiBaseUrl, token, { defaultAllowance: limit });
6658
- if (authExecutor.pendingOneTapSetup) {
6720
+ if (authExecutor.pendingSelectSource) {
6721
+ authExecutor.resolveSelectSource({
6722
+ chainName: selectSourceChainName,
6723
+ tokenSymbol: selectSourceTokenSymbol
6724
+ });
6725
+ dispatch({ type: "NAVIGATE", step: "setup-status" });
6726
+ } else if (authExecutor.pendingOneTapSetup) {
6659
6727
  authExecutor.resolveOneTapSetup();
6660
- } else if (pendingTokenSelectionRef.current) {
6661
- const sel = pendingTokenSelectionRef.current;
6662
- pendingTokenSelectionRef.current = null;
6663
- dispatch({ type: "SELECT_TOKEN", walletId: sel.walletId, tokenSymbol: sel.tokenSymbol });
6728
+ } else if (pendingTokenAuthSessionRef.current) {
6729
+ const pending = pendingTokenAuthSessionRef.current;
6730
+ pendingTokenAuthSessionRef.current = null;
6731
+ pendingTokenAuthRef.current = {
6732
+ tokenAddress: pending.tokenAddress,
6733
+ chainId: pending.chainId,
6734
+ tokenSymbol: pending.tokenSymbol,
6735
+ walletId: pending.walletId
6736
+ };
6737
+ dispatch({ type: "SET_INCREASING_LIMIT", value: true });
6738
+ dispatch({ type: "NAVIGATE", step: "setup-status" });
6739
+ try {
6740
+ await authExecutor.executeSessionById(pending.sessionId);
6741
+ await reloadAccounts();
6742
+ dispatch({ type: "SELECT_TOKEN", walletId: pending.walletId, tokenSymbol: pending.tokenSymbol });
6743
+ } catch (authErr) {
6744
+ captureException(authErr);
6745
+ dispatch({
6746
+ type: "SET_ERROR",
6747
+ error: authErr instanceof Error ? authErr.message : "Failed to authorize token"
6748
+ });
6749
+ dispatch({ type: "NAVIGATE", step: "deposit" });
6750
+ } finally {
6751
+ pendingTokenAuthRef.current = null;
6752
+ dispatch({ type: "SET_INCREASING_LIMIT", value: false });
6753
+ }
6664
6754
  } else {
6665
6755
  dispatch({ type: "NAVIGATE", step: "deposit" });
6666
6756
  }
@@ -6673,13 +6763,14 @@ function SwypePaymentInner({
6673
6763
  } finally {
6674
6764
  setSavingOneTapLimit(false);
6675
6765
  }
6676
- }, [getAccessToken, apiBaseUrl, authExecutor]);
6766
+ }, [getAccessToken, apiBaseUrl, authExecutor, reloadAccounts, onError, selectSourceChainName, selectSourceTokenSymbol]);
6677
6767
  const handleNewPayment = useCallback(() => {
6678
6768
  clearMobileFlowState();
6679
6769
  processingStartedAtRef.current = null;
6680
6770
  pollingTransferIdRef.current = null;
6681
6771
  preSelectSourceStepRef.current = null;
6682
6772
  pendingTokenSelectionRef.current = null;
6773
+ pendingTokenAuthSessionRef.current = null;
6683
6774
  dispatch({
6684
6775
  type: "NEW_PAYMENT",
6685
6776
  depositAmount,
@@ -6698,6 +6789,7 @@ function SwypePaymentInner({
6698
6789
  polling.stopPolling();
6699
6790
  preSelectSourceStepRef.current = null;
6700
6791
  pendingTokenSelectionRef.current = null;
6792
+ pendingTokenAuthSessionRef.current = null;
6701
6793
  checkingPasskeyRef.current = false;
6702
6794
  setAuthInput("");
6703
6795
  setOtpCode("");
@@ -7202,24 +7294,9 @@ function SwypePaymentInner({
7202
7294
  userAgent: typeof navigator === "undefined" ? void 0 : navigator.userAgent
7203
7295
  });
7204
7296
  if (isDesktop && state.step === "setup-status") {
7205
- const recommended = pendingSelectSourceAction.metadata?.recommended;
7206
- const options = pendingSelectSourceAction.metadata?.options ?? [];
7207
- let chainName;
7208
- let tokenSymbol;
7209
- if (pendingTokenAuthRef.current) {
7210
- const { tokenAddress, chainId } = pendingTokenAuthRef.current;
7211
- const chainIdHex = `0x${chainId.toString(16)}`;
7212
- const match = options.find(
7213
- (opt) => opt.tokenAddress.toLowerCase() === tokenAddress.toLowerCase() && opt.chainId.toLowerCase() === chainIdHex.toLowerCase()
7214
- );
7215
- chainName = match?.chainName ?? recommended?.chainName ?? "Base";
7216
- tokenSymbol = match?.tokenSymbol ?? recommended?.tokenSymbol ?? "USDC";
7217
- } else {
7218
- const choices = buildSelectSourceChoices(options);
7219
- chainName = recommended?.chainName ?? choices[0]?.chainName ?? "Base";
7220
- tokenSymbol = recommended?.tokenSymbol ?? choices[0]?.tokens[0]?.tokenSymbol ?? "USDC";
7221
- }
7222
- authExecutor.resolveSelectSource({ chainName, tokenSymbol });
7297
+ reloadAccounts().then(() => {
7298
+ dispatch({ type: "NAVIGATE", step: "deposit" });
7299
+ });
7223
7300
  return;
7224
7301
  }
7225
7302
  preSelectSourceStepRef.current = state.step;
@@ -7228,7 +7305,7 @@ function SwypePaymentInner({
7228
7305
  dispatch({ type: "NAVIGATE", step: preSelectSourceStepRef.current ?? "processing" });
7229
7306
  preSelectSourceStepRef.current = null;
7230
7307
  }
7231
- }, [pendingSelectSourceAction, state.step, authExecutor, useWalletConnectorProp]);
7308
+ }, [pendingSelectSourceAction, state.step, authExecutor, useWalletConnectorProp, reloadAccounts]);
7232
7309
  const pendingOneTapSetupAction = authExecutor.pendingOneTapSetup;
7233
7310
  const preOneTapSetupStepRef = useRef(null);
7234
7311
  useEffect(() => {
@@ -7326,6 +7403,7 @@ function SwypePaymentInner({
7326
7403
  selectSourceChainName,
7327
7404
  selectSourceTokenSymbol,
7328
7405
  savingOneTapLimit,
7406
+ pendingSetup: !!pendingSelectSourceAction || !!pendingOneTapSetupAction,
7329
7407
  merchantName,
7330
7408
  onBack,
7331
7409
  onDismiss,