@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.cjs +39 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +39 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1957,13 +1957,16 @@ function computeSmartDefaults(accts, transferAmount) {
|
|
|
1957
1957
|
let bestAccount = null;
|
|
1958
1958
|
let bestWallet = null;
|
|
1959
1959
|
let bestBalance = -1;
|
|
1960
|
+
let bestIsActive = false;
|
|
1960
1961
|
for (const acct of accts) {
|
|
1961
1962
|
for (const wallet of acct.wallets) {
|
|
1962
1963
|
const walletBal = wallet.balance.available.amount;
|
|
1963
|
-
|
|
1964
|
+
const isActive = wallet.status === "ACTIVE";
|
|
1965
|
+
if (walletBal > bestBalance || walletBal === bestBalance && isActive && !bestIsActive) {
|
|
1964
1966
|
bestBalance = walletBal;
|
|
1965
1967
|
bestAccount = acct;
|
|
1966
1968
|
bestWallet = wallet;
|
|
1969
|
+
bestIsActive = isActive;
|
|
1967
1970
|
}
|
|
1968
1971
|
}
|
|
1969
1972
|
}
|
|
@@ -2009,7 +2012,8 @@ function buildSelectSourceChoices(options) {
|
|
|
2009
2012
|
function SwypePayment({
|
|
2010
2013
|
destination,
|
|
2011
2014
|
onComplete,
|
|
2012
|
-
onError
|
|
2015
|
+
onError,
|
|
2016
|
+
useWalletConnector
|
|
2013
2017
|
}) {
|
|
2014
2018
|
const { apiBaseUrl, tokens, depositAmount } = useSwypeConfig();
|
|
2015
2019
|
const { ready, authenticated, login, getAccessToken } = reactAuth.usePrivy();
|
|
@@ -2206,18 +2210,43 @@ function SwypePayment({
|
|
|
2206
2210
|
try {
|
|
2207
2211
|
const token = await getAccessToken();
|
|
2208
2212
|
if (!token) throw new Error("Not authenticated");
|
|
2213
|
+
let effectiveSourceType = sourceType;
|
|
2214
|
+
let effectiveSourceId = sourceId;
|
|
2215
|
+
if (effectiveSourceType === "accountId") {
|
|
2216
|
+
const acct = accounts.find((a) => a.id === effectiveSourceId);
|
|
2217
|
+
const activeWallet = acct?.wallets.find((w) => w.status === "ACTIVE");
|
|
2218
|
+
if (activeWallet) {
|
|
2219
|
+
effectiveSourceType = "walletId";
|
|
2220
|
+
effectiveSourceId = activeWallet.id;
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
const isActiveWallet = effectiveSourceType === "walletId" && accounts.some(
|
|
2224
|
+
(a) => a.wallets.some((w) => w.id === effectiveSourceId && w.status === "ACTIVE")
|
|
2225
|
+
);
|
|
2226
|
+
if (!isActiveWallet) {
|
|
2227
|
+
let found = false;
|
|
2228
|
+
for (const acct of accounts) {
|
|
2229
|
+
for (const wallet of acct.wallets) {
|
|
2230
|
+
if (wallet.status === "ACTIVE" && wallet.sources.some((s) => s.balance.available.amount >= parsedAmount)) {
|
|
2231
|
+
effectiveSourceType = "walletId";
|
|
2232
|
+
effectiveSourceId = wallet.id;
|
|
2233
|
+
found = true;
|
|
2234
|
+
break;
|
|
2235
|
+
}
|
|
2236
|
+
}
|
|
2237
|
+
if (found) break;
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2209
2240
|
const t = await createTransfer(apiBaseUrl, token, {
|
|
2210
|
-
sourceType,
|
|
2211
|
-
sourceId,
|
|
2241
|
+
sourceType: effectiveSourceType,
|
|
2242
|
+
sourceId: effectiveSourceId,
|
|
2212
2243
|
destination,
|
|
2213
2244
|
amount: parsedAmount
|
|
2214
2245
|
});
|
|
2215
2246
|
setTransfer(t);
|
|
2216
2247
|
if (t.authorizationSessions && t.authorizationSessions.length > 0) {
|
|
2217
|
-
const
|
|
2218
|
-
|
|
2219
|
-
const isWalletAuthorized = selectedWallet?.status === "ACTIVE";
|
|
2220
|
-
if (isMobile() && !isWalletAuthorized) {
|
|
2248
|
+
const shouldUseWalletConnector = useWalletConnector ?? !isMobile();
|
|
2249
|
+
if (!shouldUseWalletConnector) {
|
|
2221
2250
|
setMobileFlow(true);
|
|
2222
2251
|
pollingTransferIdRef.current = t.id;
|
|
2223
2252
|
polling.startPolling(t.id);
|
|
@@ -2245,13 +2274,12 @@ function SwypePayment({
|
|
|
2245
2274
|
destination,
|
|
2246
2275
|
apiBaseUrl,
|
|
2247
2276
|
getAccessToken,
|
|
2277
|
+
accounts,
|
|
2248
2278
|
authExecutor,
|
|
2249
2279
|
transferSigning,
|
|
2250
2280
|
polling,
|
|
2251
2281
|
onError,
|
|
2252
|
-
|
|
2253
|
-
selectedAccountId,
|
|
2254
|
-
selectedWalletId
|
|
2282
|
+
useWalletConnector
|
|
2255
2283
|
]);
|
|
2256
2284
|
const handleNewPayment = () => {
|
|
2257
2285
|
setStep("ready");
|