@swype-org/react-sdk 0.1.128 → 0.1.130

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
@@ -7161,6 +7161,20 @@ function SwypePaymentInner({
7161
7161
  return;
7162
7162
  }
7163
7163
  if (initializedSelectSourceActionRef.current === pendingSelectSourceAction.id) return;
7164
+ const options = pendingSelectSourceAction.metadata?.options ?? [];
7165
+ if (pendingTokenAuthRef.current) {
7166
+ const { tokenAddress, chainId } = pendingTokenAuthRef.current;
7167
+ const chainIdHex = `0x${chainId.toString(16)}`;
7168
+ const match = options.find(
7169
+ (opt) => opt.tokenAddress.toLowerCase() === tokenAddress.toLowerCase() && opt.chainId.toLowerCase() === chainIdHex.toLowerCase()
7170
+ );
7171
+ if (match) {
7172
+ setSelectSourceChainName(match.chainName);
7173
+ setSelectSourceTokenSymbol(match.tokenSymbol);
7174
+ initializedSelectSourceActionRef.current = pendingSelectSourceAction.id;
7175
+ return;
7176
+ }
7177
+ }
7164
7178
  const hasRecommended = !!selectSourceRecommended && selectSourceChoices.some(
7165
7179
  (chain) => chain.chainName === selectSourceRecommended.chainName && chain.tokens.some((t) => t.tokenSymbol === selectSourceRecommended.tokenSymbol)
7166
7180
  );
@@ -7178,37 +7192,38 @@ function SwypePaymentInner({
7178
7192
  }, [pendingSelectSourceAction, selectSourceChoices, selectSourceRecommended]);
7179
7193
  react.useEffect(() => {
7180
7194
  if (pendingSelectSourceAction && (state.step === "processing" || state.step === "open-wallet" || state.step === "setup-status")) {
7181
- if (state.step === "setup-status") {
7182
- const recommended = selectSourceRecommended;
7183
- if (recommended) {
7184
- authExecutor.resolveSelectSource(recommended);
7195
+ const isDesktop = shouldUseWalletConnector({
7196
+ useWalletConnector: useWalletConnectorProp,
7197
+ userAgent: typeof navigator === "undefined" ? void 0 : navigator.userAgent
7198
+ });
7199
+ if (isDesktop && state.step === "setup-status") {
7200
+ const recommended = pendingSelectSourceAction.metadata?.recommended;
7201
+ const options = pendingSelectSourceAction.metadata?.options ?? [];
7202
+ let chainName;
7203
+ let tokenSymbol;
7204
+ if (pendingTokenAuthRef.current) {
7205
+ const { tokenAddress, chainId } = pendingTokenAuthRef.current;
7206
+ const chainIdHex = `0x${chainId.toString(16)}`;
7207
+ const match = options.find(
7208
+ (opt) => opt.tokenAddress.toLowerCase() === tokenAddress.toLowerCase() && opt.chainId.toLowerCase() === chainIdHex.toLowerCase()
7209
+ );
7210
+ chainName = match?.chainName ?? recommended?.chainName ?? "Base";
7211
+ tokenSymbol = match?.tokenSymbol ?? recommended?.tokenSymbol ?? "USDC";
7185
7212
  } else {
7186
- authExecutor.resolveSelectSource({ chainName: "Base", tokenSymbol: "USDC" });
7213
+ const choices = buildSelectSourceChoices(options);
7214
+ chainName = recommended?.chainName ?? choices[0]?.chainName ?? "Base";
7215
+ tokenSymbol = recommended?.tokenSymbol ?? choices[0]?.tokens[0]?.tokenSymbol ?? "USDC";
7187
7216
  }
7188
- } else {
7189
- preSelectSourceStepRef.current = state.step;
7190
- dispatch({ type: "NAVIGATE", step: "select-source" });
7217
+ authExecutor.resolveSelectSource({ chainName, tokenSymbol });
7218
+ return;
7191
7219
  }
7220
+ preSelectSourceStepRef.current = state.step;
7221
+ dispatch({ type: "NAVIGATE", step: "select-source" });
7192
7222
  } else if (!pendingSelectSourceAction && state.step === "select-source") {
7193
7223
  dispatch({ type: "NAVIGATE", step: preSelectSourceStepRef.current ?? "processing" });
7194
7224
  preSelectSourceStepRef.current = null;
7195
7225
  }
7196
- }, [pendingSelectSourceAction, state.step, selectSourceRecommended, authExecutor]);
7197
- react.useEffect(() => {
7198
- if (!pendingSelectSourceAction || !pendingTokenAuthRef.current) return;
7199
- const { tokenAddress, chainId } = pendingTokenAuthRef.current;
7200
- const chainIdHex = `0x${chainId.toString(16)}`;
7201
- const options = pendingSelectSourceAction.metadata?.options ?? [];
7202
- const match = options.find(
7203
- (opt) => opt.tokenAddress.toLowerCase() === tokenAddress.toLowerCase() && opt.chainId.toLowerCase() === chainIdHex.toLowerCase()
7204
- );
7205
- if (match) {
7206
- authExecutor.resolveSelectSource({
7207
- chainName: match.chainName,
7208
- tokenSymbol: match.tokenSymbol
7209
- });
7210
- }
7211
- }, [pendingSelectSourceAction, authExecutor]);
7226
+ }, [pendingSelectSourceAction, state.step, authExecutor, useWalletConnectorProp]);
7212
7227
  const pendingOneTapSetupAction = authExecutor.pendingOneTapSetup;
7213
7228
  const preOneTapSetupStepRef = react.useRef(null);
7214
7229
  react.useEffect(() => {