@swype-org/react-sdk 0.1.132 → 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.cjs CHANGED
@@ -4251,7 +4251,9 @@ function DepositScreen({
4251
4251
  onSelectAccount,
4252
4252
  onAuthorizeAccount,
4253
4253
  onAddProvider,
4254
- onSelectToken
4254
+ onSelectToken,
4255
+ pendingSetup,
4256
+ onStartSetup
4255
4257
  }) {
4256
4258
  const { tokens } = useSwypeConfig();
4257
4259
  const amount = initialAmount;
@@ -4259,6 +4261,29 @@ function DepositScreen({
4259
4261
  const exceedsLimit = amount > remainingLimit && !isLowBalance;
4260
4262
  const canDeposit = amount >= MIN_DEPOSIT && !exceedsLimit && !isLowBalance && !processing;
4261
4263
  const headerTitle = merchantName ? `Deposit to ${merchantName}` : "Deposit";
4264
+ if (pendingSetup) {
4265
+ return /* @__PURE__ */ jsxRuntime.jsxs(
4266
+ ScreenLayout,
4267
+ {
4268
+ footer: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4269
+ /* @__PURE__ */ jsxRuntime.jsx(PrimaryButton, { onClick: onStartSetup, children: "Set up One-Tap" }),
4270
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: setupHintStyle(tokens.textSecondary), children: "Choose your source and set your One-Tap limit to deposit instantly." }),
4271
+ /* @__PURE__ */ jsxRuntime.jsx(PoweredByFooter, {})
4272
+ ] }),
4273
+ children: [
4274
+ /* @__PURE__ */ jsxRuntime.jsx(ScreenHeader, { title: headerTitle, right: /* @__PURE__ */ jsxRuntime.jsx(SettingsMenu, { onLogout }) }),
4275
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: setupContentStyle, children: [
4276
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: amountDisplayStyle, children: /* @__PURE__ */ jsxRuntime.jsxs("span", { style: amountStyle(tokens), children: [
4277
+ "$",
4278
+ amount.toFixed(2)
4279
+ ] }) }),
4280
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: setupDescStyle(tokens.textSecondary), children: "Set up your payment source to deposit with One-Tap \u2014 no approvals needed after setup." })
4281
+ ] }),
4282
+ error && /* @__PURE__ */ jsxRuntime.jsx("div", { style: errorBannerStyle5(tokens), children: error })
4283
+ ]
4284
+ }
4285
+ );
4286
+ }
4262
4287
  if (isLowBalance) {
4263
4288
  return /* @__PURE__ */ jsxRuntime.jsxs(
4264
4289
  ScreenLayout,
@@ -4521,6 +4546,29 @@ var switchHintStyle = (color) => ({
4521
4546
  var outlineBtnWrapStyle = {
4522
4547
  marginBottom: 8
4523
4548
  };
4549
+ var setupContentStyle = {
4550
+ flex: 1,
4551
+ display: "flex",
4552
+ flexDirection: "column",
4553
+ alignItems: "center",
4554
+ justifyContent: "center",
4555
+ textAlign: "center",
4556
+ padding: "0 24px"
4557
+ };
4558
+ var setupDescStyle = (color) => ({
4559
+ fontSize: "0.88rem",
4560
+ color,
4561
+ margin: "8px 0 0",
4562
+ lineHeight: 1.6,
4563
+ maxWidth: 300
4564
+ });
4565
+ var setupHintStyle = (color) => ({
4566
+ textAlign: "center",
4567
+ fontSize: "0.78rem",
4568
+ color,
4569
+ margin: "12px 0 2px",
4570
+ lineHeight: 1.5
4571
+ });
4524
4572
  function SuccessScreen({
4525
4573
  amount,
4526
4574
  currency,
@@ -4728,6 +4776,7 @@ function SelectSourceScreen({
4728
4776
  onChainChange,
4729
4777
  onTokenChange,
4730
4778
  onConfirm,
4779
+ onBack,
4731
4780
  onLogout
4732
4781
  }) {
4733
4782
  const { tokens } = useSwypeConfig();
@@ -4746,6 +4795,7 @@ function SelectSourceScreen({
4746
4795
  ScreenHeader,
4747
4796
  {
4748
4797
  title: "Select Source",
4798
+ onBack,
4749
4799
  right: /* @__PURE__ */ jsxRuntime.jsx(SettingsMenu, { onLogout })
4750
4800
  }
4751
4801
  ),
@@ -5618,6 +5668,7 @@ function StepRenderer({
5618
5668
  selectSourceChainName,
5619
5669
  selectSourceTokenSymbol,
5620
5670
  savingOneTapLimit,
5671
+ pendingSetup,
5621
5672
  merchantName,
5622
5673
  onBack,
5623
5674
  onDismiss,
@@ -5734,6 +5785,8 @@ function StepRenderer({
5734
5785
  );
5735
5786
  }
5736
5787
  if (step === "setup") {
5788
+ const hasPendingSelectSource = selectSourceChoices.length > 0;
5789
+ const setupSourceLabel = hasPendingSelectSource && selectSourceChainName && selectSourceTokenSymbol ? `${selectSourceTokenSymbol} on ${selectSourceChainName}` : selectedSourceLabel;
5737
5790
  return /* @__PURE__ */ jsxRuntime.jsx(
5738
5791
  SetupScreen,
5739
5792
  {
@@ -5743,8 +5796,8 @@ function StepRenderer({
5743
5796
  onSetupOneTap: handlers.onSetupOneTap,
5744
5797
  onBack: () => handlers.onNavigate("deposit"),
5745
5798
  onLogout: handlers.onLogout,
5746
- onAdvanced: handlers.onSelectToken,
5747
- selectedSourceLabel,
5799
+ onAdvanced: hasPendingSelectSource ? () => handlers.onNavigate("select-source") : handlers.onSelectToken,
5800
+ selectedSourceLabel: setupSourceLabel,
5748
5801
  loading: savingOneTapLimit,
5749
5802
  error: state.error
5750
5803
  }
@@ -5792,7 +5845,9 @@ function StepRenderer({
5792
5845
  onSelectAccount: handlers.onSelectAccount,
5793
5846
  onAuthorizeAccount: handlers.onContinueConnection,
5794
5847
  onAddProvider: () => handlers.onNavigate("wallet-picker"),
5795
- onSelectToken: handlers.onSelectToken
5848
+ onSelectToken: handlers.onSelectToken,
5849
+ pendingSetup,
5850
+ onStartSetup: () => handlers.onNavigate("setup")
5796
5851
  }
5797
5852
  );
5798
5853
  }
@@ -5824,6 +5879,7 @@ function StepRenderer({
5824
5879
  );
5825
5880
  }
5826
5881
  if (step === "select-source") {
5882
+ const enteredFromSetup = state.previousStep === "setup";
5827
5883
  return /* @__PURE__ */ jsxRuntime.jsx(
5828
5884
  SelectSourceScreen,
5829
5885
  {
@@ -5833,7 +5889,8 @@ function StepRenderer({
5833
5889
  recommended: selectSourceRecommended,
5834
5890
  onChainChange: handlers.onSelectSourceChainChange,
5835
5891
  onTokenChange: handlers.onSetSelectSourceTokenSymbol,
5836
- onConfirm: handlers.onConfirmSelectSource,
5892
+ onConfirm: enteredFromSetup ? () => handlers.onNavigate("setup") : handlers.onConfirmSelectSource,
5893
+ onBack: enteredFromSetup ? () => handlers.onNavigate("setup") : void 0,
5837
5894
  onLogout: handlers.onLogout
5838
5895
  }
5839
5896
  );
@@ -6663,7 +6720,13 @@ function SwypePaymentInner({
6663
6720
  const token = await getAccessToken();
6664
6721
  if (!token) throw new Error("Not authenticated");
6665
6722
  await updateUserConfig(apiBaseUrl, token, { defaultAllowance: limit });
6666
- if (authExecutor.pendingOneTapSetup) {
6723
+ if (authExecutor.pendingSelectSource) {
6724
+ authExecutor.resolveSelectSource({
6725
+ chainName: selectSourceChainName,
6726
+ tokenSymbol: selectSourceTokenSymbol
6727
+ });
6728
+ dispatch({ type: "NAVIGATE", step: "setup-status" });
6729
+ } else if (authExecutor.pendingOneTapSetup) {
6667
6730
  authExecutor.resolveOneTapSetup();
6668
6731
  } else if (pendingTokenAuthSessionRef.current) {
6669
6732
  const pending = pendingTokenAuthSessionRef.current;
@@ -6703,7 +6766,7 @@ function SwypePaymentInner({
6703
6766
  } finally {
6704
6767
  setSavingOneTapLimit(false);
6705
6768
  }
6706
- }, [getAccessToken, apiBaseUrl, authExecutor, reloadAccounts, onError]);
6769
+ }, [getAccessToken, apiBaseUrl, authExecutor, reloadAccounts, onError, selectSourceChainName, selectSourceTokenSymbol]);
6707
6770
  const handleNewPayment = react.useCallback(() => {
6708
6771
  clearMobileFlowState();
6709
6772
  processingStartedAtRef.current = null;
@@ -7234,24 +7297,9 @@ function SwypePaymentInner({
7234
7297
  userAgent: typeof navigator === "undefined" ? void 0 : navigator.userAgent
7235
7298
  });
7236
7299
  if (isDesktop && state.step === "setup-status") {
7237
- const recommended = pendingSelectSourceAction.metadata?.recommended;
7238
- const options = pendingSelectSourceAction.metadata?.options ?? [];
7239
- let chainName;
7240
- let tokenSymbol;
7241
- if (pendingTokenAuthRef.current) {
7242
- const { tokenAddress, chainId } = pendingTokenAuthRef.current;
7243
- const chainIdHex = `0x${chainId.toString(16)}`;
7244
- const match = options.find(
7245
- (opt) => opt.tokenAddress.toLowerCase() === tokenAddress.toLowerCase() && opt.chainId.toLowerCase() === chainIdHex.toLowerCase()
7246
- );
7247
- chainName = match?.chainName ?? recommended?.chainName ?? "Base";
7248
- tokenSymbol = match?.tokenSymbol ?? recommended?.tokenSymbol ?? "USDC";
7249
- } else {
7250
- const choices = buildSelectSourceChoices(options);
7251
- chainName = recommended?.chainName ?? choices[0]?.chainName ?? "Base";
7252
- tokenSymbol = recommended?.tokenSymbol ?? choices[0]?.tokens[0]?.tokenSymbol ?? "USDC";
7253
- }
7254
- authExecutor.resolveSelectSource({ chainName, tokenSymbol });
7300
+ reloadAccounts().then(() => {
7301
+ dispatch({ type: "NAVIGATE", step: "deposit" });
7302
+ });
7255
7303
  return;
7256
7304
  }
7257
7305
  preSelectSourceStepRef.current = state.step;
@@ -7260,7 +7308,7 @@ function SwypePaymentInner({
7260
7308
  dispatch({ type: "NAVIGATE", step: preSelectSourceStepRef.current ?? "processing" });
7261
7309
  preSelectSourceStepRef.current = null;
7262
7310
  }
7263
- }, [pendingSelectSourceAction, state.step, authExecutor, useWalletConnectorProp]);
7311
+ }, [pendingSelectSourceAction, state.step, authExecutor, useWalletConnectorProp, reloadAccounts]);
7264
7312
  const pendingOneTapSetupAction = authExecutor.pendingOneTapSetup;
7265
7313
  const preOneTapSetupStepRef = react.useRef(null);
7266
7314
  react.useEffect(() => {
@@ -7358,6 +7406,7 @@ function SwypePaymentInner({
7358
7406
  selectSourceChainName,
7359
7407
  selectSourceTokenSymbol,
7360
7408
  savingOneTapLimit,
7409
+ pendingSetup: !!pendingSelectSourceAction || !!pendingOneTapSetupAction,
7361
7410
  merchantName,
7362
7411
  onBack,
7363
7412
  onDismiss,