@swype-org/react-sdk 0.1.142 → 0.1.143
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 +43 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +43 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1678,24 +1678,34 @@ function hasActiveDepositWallet(account) {
|
|
|
1678
1678
|
function getPreferredDepositWallet(account, transferAmount) {
|
|
1679
1679
|
const wallets = getAddressableWallets(account);
|
|
1680
1680
|
if (wallets.length === 0) return null;
|
|
1681
|
+
let bestWithAllowance = null;
|
|
1682
|
+
let bestWithAllowanceBal = -1;
|
|
1683
|
+
let bestActive = null;
|
|
1684
|
+
let bestActiveBal = -1;
|
|
1685
|
+
let bestAny = null;
|
|
1686
|
+
let bestAnyBal = -1;
|
|
1681
1687
|
for (const wallet of wallets) {
|
|
1682
|
-
if (wallet.status === "ACTIVE" && wallet.sources.some((source) => source.balance.available.amount >= transferAmount)) {
|
|
1683
|
-
return wallet;
|
|
1684
|
-
}
|
|
1685
|
-
}
|
|
1686
|
-
let bestWallet = null;
|
|
1687
|
-
let bestBalance = -1;
|
|
1688
|
-
let bestIsActive = false;
|
|
1689
|
-
for (const wallet of wallets) {
|
|
1690
|
-
const walletBal = wallet.balance.available.amount;
|
|
1691
1688
|
const isActive = wallet.status === "ACTIVE";
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1689
|
+
const walletBal = wallet.balance.available.amount;
|
|
1690
|
+
if (isActive) {
|
|
1691
|
+
const hasFullyEligibleSource = wallet.sources.some(
|
|
1692
|
+
(s) => s.balance.available.amount >= transferAmount && s.remainingAllowance != null && s.remainingAllowance >= transferAmount
|
|
1693
|
+
);
|
|
1694
|
+
if (hasFullyEligibleSource && walletBal > bestWithAllowanceBal) {
|
|
1695
|
+
bestWithAllowance = wallet;
|
|
1696
|
+
bestWithAllowanceBal = walletBal;
|
|
1697
|
+
}
|
|
1698
|
+
if (walletBal > bestActiveBal) {
|
|
1699
|
+
bestActive = wallet;
|
|
1700
|
+
bestActiveBal = walletBal;
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
if (walletBal > bestAnyBal) {
|
|
1704
|
+
bestAny = wallet;
|
|
1705
|
+
bestAnyBal = walletBal;
|
|
1696
1706
|
}
|
|
1697
1707
|
}
|
|
1698
|
-
return
|
|
1708
|
+
return bestWithAllowance ?? bestActive ?? bestAny ?? wallets[0];
|
|
1699
1709
|
}
|
|
1700
1710
|
function getDepositEligibleAccounts(accounts) {
|
|
1701
1711
|
return accounts.filter((account) => getAddressableWallets(account).length > 0);
|
|
@@ -1715,7 +1725,9 @@ function resolveDepositSelection(accounts, transferAmount, selectedAccountId) {
|
|
|
1715
1725
|
}
|
|
1716
1726
|
for (const account of eligibleAccounts) {
|
|
1717
1727
|
const fullyEligibleWallet = getAddressableWallets(account).find(
|
|
1718
|
-
(wallet) => wallet.status === "ACTIVE" && wallet.sources.some(
|
|
1728
|
+
(wallet) => wallet.status === "ACTIVE" && wallet.sources.some(
|
|
1729
|
+
(source) => source.balance.available.amount >= transferAmount && source.remainingAllowance != null && source.remainingAllowance >= transferAmount
|
|
1730
|
+
)
|
|
1719
1731
|
);
|
|
1720
1732
|
if (fullyEligibleWallet) {
|
|
1721
1733
|
return {
|
|
@@ -6471,6 +6483,9 @@ function useProviderHandlers(deps) {
|
|
|
6471
6483
|
useWalletConnectorProp,
|
|
6472
6484
|
activeCredentialId,
|
|
6473
6485
|
selectedAccountId,
|
|
6486
|
+
selectedWalletId,
|
|
6487
|
+
selectedTokenSymbol,
|
|
6488
|
+
chains,
|
|
6474
6489
|
accounts,
|
|
6475
6490
|
providers,
|
|
6476
6491
|
authExecutor,
|
|
@@ -6597,11 +6612,17 @@ function useProviderHandlers(deps) {
|
|
|
6597
6612
|
try {
|
|
6598
6613
|
const token = await getAccessToken();
|
|
6599
6614
|
if (!token) throw new Error("Not authenticated");
|
|
6615
|
+
const wallet = acct?.wallets.find((w) => w.id === selectedWalletId);
|
|
6616
|
+
const source = wallet?.sources.find(
|
|
6617
|
+
(s) => selectedTokenSymbol ? s.token.symbol === selectedTokenSymbol : s.token.status === "AUTHORIZED"
|
|
6618
|
+
);
|
|
6619
|
+
const evmChainId = chains.find((c) => c.name === wallet?.chain.name)?.commonId ?? void 0;
|
|
6600
6620
|
const session = await createAccountAuthorizationSession(
|
|
6601
6621
|
apiBaseUrl,
|
|
6602
6622
|
token,
|
|
6603
6623
|
selectedAccountId,
|
|
6604
|
-
activeCredentialId
|
|
6624
|
+
activeCredentialId,
|
|
6625
|
+
{ tokenAddress: source?.address, chainId: evmChainId }
|
|
6605
6626
|
);
|
|
6606
6627
|
const isMobile = !shouldUseWalletConnector({
|
|
6607
6628
|
useWalletConnector: useWalletConnectorProp,
|
|
@@ -6639,6 +6660,9 @@ function useProviderHandlers(deps) {
|
|
|
6639
6660
|
}
|
|
6640
6661
|
}, [
|
|
6641
6662
|
selectedAccountId,
|
|
6663
|
+
selectedWalletId,
|
|
6664
|
+
selectedTokenSymbol,
|
|
6665
|
+
chains,
|
|
6642
6666
|
activeCredentialId,
|
|
6643
6667
|
accounts,
|
|
6644
6668
|
providers,
|
|
@@ -7504,6 +7528,9 @@ function SwypePaymentInner({
|
|
|
7504
7528
|
useWalletConnectorProp,
|
|
7505
7529
|
activeCredentialId: state.activeCredentialId,
|
|
7506
7530
|
selectedAccountId: state.selectedAccountId,
|
|
7531
|
+
selectedWalletId: state.selectedWalletId,
|
|
7532
|
+
selectedTokenSymbol: state.selectedTokenSymbol,
|
|
7533
|
+
chains: state.chains,
|
|
7507
7534
|
accounts: state.accounts,
|
|
7508
7535
|
providers: state.providers,
|
|
7509
7536
|
authExecutor,
|