@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.cjs +22 -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 +22 -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,26 @@ 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
|
+
}
|
|
2209
2223
|
const t = await createTransfer(apiBaseUrl, token, {
|
|
2210
|
-
sourceType,
|
|
2211
|
-
sourceId,
|
|
2224
|
+
sourceType: effectiveSourceType,
|
|
2225
|
+
sourceId: effectiveSourceId,
|
|
2212
2226
|
destination,
|
|
2213
2227
|
amount: parsedAmount
|
|
2214
2228
|
});
|
|
2215
2229
|
setTransfer(t);
|
|
2216
2230
|
if (t.authorizationSessions && t.authorizationSessions.length > 0) {
|
|
2217
|
-
const
|
|
2218
|
-
|
|
2219
|
-
const isWalletAuthorized = selectedWallet?.status === "ACTIVE";
|
|
2220
|
-
if (isMobile() && !isWalletAuthorized) {
|
|
2231
|
+
const shouldUseWalletConnector = useWalletConnector ?? !isMobile();
|
|
2232
|
+
if (!shouldUseWalletConnector) {
|
|
2221
2233
|
setMobileFlow(true);
|
|
2222
2234
|
pollingTransferIdRef.current = t.id;
|
|
2223
2235
|
polling.startPolling(t.id);
|
|
@@ -2245,13 +2257,12 @@ function SwypePayment({
|
|
|
2245
2257
|
destination,
|
|
2246
2258
|
apiBaseUrl,
|
|
2247
2259
|
getAccessToken,
|
|
2260
|
+
accounts,
|
|
2248
2261
|
authExecutor,
|
|
2249
2262
|
transferSigning,
|
|
2250
2263
|
polling,
|
|
2251
2264
|
onError,
|
|
2252
|
-
|
|
2253
|
-
selectedAccountId,
|
|
2254
|
-
selectedWalletId
|
|
2265
|
+
useWalletConnector
|
|
2255
2266
|
]);
|
|
2256
2267
|
const handleNewPayment = () => {
|
|
2257
2268
|
setStep("ready");
|