@swype-org/react-sdk 0.1.7 → 0.1.9

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,43 @@ 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
+ }
2220
+ const isActiveWallet = effectiveSourceType === "walletId" && accounts.some(
2221
+ (a) => a.wallets.some((w) => w.id === effectiveSourceId && w.status === "ACTIVE")
2222
+ );
2223
+ if (!isActiveWallet) {
2224
+ let found = false;
2225
+ for (const acct of accounts) {
2226
+ for (const wallet of acct.wallets) {
2227
+ if (wallet.status === "ACTIVE" && wallet.sources.some((s) => s.balance.available.amount >= parsedAmount)) {
2228
+ effectiveSourceType = "walletId";
2229
+ effectiveSourceId = wallet.id;
2230
+ found = true;
2231
+ break;
2232
+ }
2233
+ }
2234
+ if (found) break;
2235
+ }
2236
+ }
2206
2237
  const t = await createTransfer(apiBaseUrl, token, {
2207
- sourceType,
2208
- sourceId,
2238
+ sourceType: effectiveSourceType,
2239
+ sourceId: effectiveSourceId,
2209
2240
  destination,
2210
2241
  amount: parsedAmount
2211
2242
  });
2212
2243
  setTransfer(t);
2213
2244
  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) {
2245
+ const shouldUseWalletConnector = useWalletConnector ?? !isMobile();
2246
+ if (!shouldUseWalletConnector) {
2218
2247
  setMobileFlow(true);
2219
2248
  pollingTransferIdRef.current = t.id;
2220
2249
  polling.startPolling(t.id);
@@ -2242,13 +2271,12 @@ function SwypePayment({
2242
2271
  destination,
2243
2272
  apiBaseUrl,
2244
2273
  getAccessToken,
2274
+ accounts,
2245
2275
  authExecutor,
2246
2276
  transferSigning,
2247
2277
  polling,
2248
2278
  onError,
2249
- accounts,
2250
- selectedAccountId,
2251
- selectedWalletId
2279
+ useWalletConnector
2252
2280
  ]);
2253
2281
  const handleNewPayment = () => {
2254
2282
  setStep("ready");