@swype-org/react-sdk 0.1.7 → 0.1.8

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
@@ -281,8 +281,19 @@ interface SwypePaymentProps {
281
281
  onComplete?: (transfer: Transfer) => void;
282
282
  /** Called on unrecoverable error */
283
283
  onError?: (error: string) => void;
284
+ /**
285
+ * Whether to use in-browser wallet connectors (wagmi) for authorization.
286
+ *
287
+ * - `true` — always use in-browser wallet connectors (desktop flow).
288
+ * - `false` — always use deeplink redirects (webview / mobile flow).
289
+ * - `undefined` (default) — auto-detect via user-agent (`isMobile()`).
290
+ *
291
+ * Set to `false` when rendering inside a WebView where browser-based
292
+ * wallet extensions are unavailable.
293
+ */
294
+ useWalletConnector?: boolean;
284
295
  }
285
- declare function SwypePayment({ destination, onComplete, onError, }: SwypePaymentProps): react_jsx_runtime.JSX.Element | null;
296
+ declare function SwypePayment({ destination, onComplete, onError, useWalletConnector, }: SwypePaymentProps): react_jsx_runtime.JSX.Element | null;
286
297
 
287
298
  type AccessTokenGetter = () => Promise<string | null | undefined>;
288
299
  /**
package/dist/index.d.ts CHANGED
@@ -281,8 +281,19 @@ interface SwypePaymentProps {
281
281
  onComplete?: (transfer: Transfer) => void;
282
282
  /** Called on unrecoverable error */
283
283
  onError?: (error: string) => void;
284
+ /**
285
+ * Whether to use in-browser wallet connectors (wagmi) for authorization.
286
+ *
287
+ * - `true` — always use in-browser wallet connectors (desktop flow).
288
+ * - `false` — always use deeplink redirects (webview / mobile flow).
289
+ * - `undefined` (default) — auto-detect via user-agent (`isMobile()`).
290
+ *
291
+ * Set to `false` when rendering inside a WebView where browser-based
292
+ * wallet extensions are unavailable.
293
+ */
294
+ useWalletConnector?: boolean;
284
295
  }
285
- declare function SwypePayment({ destination, onComplete, onError, }: SwypePaymentProps): react_jsx_runtime.JSX.Element | null;
296
+ declare function SwypePayment({ destination, onComplete, onError, useWalletConnector, }: SwypePaymentProps): react_jsx_runtime.JSX.Element | null;
286
297
 
287
298
  type AccessTokenGetter = () => Promise<string | null | undefined>;
288
299
  /**
package/dist/index.js CHANGED
@@ -1954,13 +1954,16 @@ function computeSmartDefaults(accts, transferAmount) {
1954
1954
  let bestAccount = null;
1955
1955
  let bestWallet = null;
1956
1956
  let bestBalance = -1;
1957
+ let bestIsActive = false;
1957
1958
  for (const acct of accts) {
1958
1959
  for (const wallet of acct.wallets) {
1959
1960
  const walletBal = wallet.balance.available.amount;
1960
- if (walletBal > bestBalance) {
1961
+ const isActive = wallet.status === "ACTIVE";
1962
+ if (walletBal > bestBalance || walletBal === bestBalance && isActive && !bestIsActive) {
1961
1963
  bestBalance = walletBal;
1962
1964
  bestAccount = acct;
1963
1965
  bestWallet = wallet;
1966
+ bestIsActive = isActive;
1964
1967
  }
1965
1968
  }
1966
1969
  }
@@ -2006,7 +2009,8 @@ function buildSelectSourceChoices(options) {
2006
2009
  function SwypePayment({
2007
2010
  destination,
2008
2011
  onComplete,
2009
- onError
2012
+ onError,
2013
+ useWalletConnector
2010
2014
  }) {
2011
2015
  const { apiBaseUrl, tokens, depositAmount } = useSwypeConfig();
2012
2016
  const { ready, authenticated, login, getAccessToken } = usePrivy();
@@ -2203,18 +2207,26 @@ function SwypePayment({
2203
2207
  try {
2204
2208
  const token = await getAccessToken();
2205
2209
  if (!token) throw new Error("Not authenticated");
2210
+ let effectiveSourceType = sourceType;
2211
+ let effectiveSourceId = sourceId;
2212
+ if (effectiveSourceType === "accountId") {
2213
+ const acct = accounts.find((a) => a.id === effectiveSourceId);
2214
+ const activeWallet = acct?.wallets.find((w) => w.status === "ACTIVE");
2215
+ if (activeWallet) {
2216
+ effectiveSourceType = "walletId";
2217
+ effectiveSourceId = activeWallet.id;
2218
+ }
2219
+ }
2206
2220
  const t = await createTransfer(apiBaseUrl, token, {
2207
- sourceType,
2208
- sourceId,
2221
+ sourceType: effectiveSourceType,
2222
+ sourceId: effectiveSourceId,
2209
2223
  destination,
2210
2224
  amount: parsedAmount
2211
2225
  });
2212
2226
  setTransfer(t);
2213
2227
  if (t.authorizationSessions && t.authorizationSessions.length > 0) {
2214
- const selectedAccount = accounts.find((a) => a.id === selectedAccountId);
2215
- const selectedWallet = selectedWalletId ? selectedAccount?.wallets.find((w) => w.id === selectedWalletId) : null;
2216
- const isWalletAuthorized = selectedWallet?.status === "ACTIVE";
2217
- if (isMobile() && !isWalletAuthorized) {
2228
+ const shouldUseWalletConnector = useWalletConnector ?? !isMobile();
2229
+ if (!shouldUseWalletConnector) {
2218
2230
  setMobileFlow(true);
2219
2231
  pollingTransferIdRef.current = t.id;
2220
2232
  polling.startPolling(t.id);
@@ -2242,13 +2254,12 @@ function SwypePayment({
2242
2254
  destination,
2243
2255
  apiBaseUrl,
2244
2256
  getAccessToken,
2257
+ accounts,
2245
2258
  authExecutor,
2246
2259
  transferSigning,
2247
2260
  polling,
2248
2261
  onError,
2249
- accounts,
2250
- selectedAccountId,
2251
- selectedWalletId
2262
+ useWalletConnector
2252
2263
  ]);
2253
2264
  const handleNewPayment = () => {
2254
2265
  setStep("ready");