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