@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.cjs
CHANGED
|
@@ -1681,24 +1681,34 @@ function hasActiveDepositWallet(account) {
|
|
|
1681
1681
|
function getPreferredDepositWallet(account, transferAmount) {
|
|
1682
1682
|
const wallets = getAddressableWallets(account);
|
|
1683
1683
|
if (wallets.length === 0) return null;
|
|
1684
|
+
let bestWithAllowance = null;
|
|
1685
|
+
let bestWithAllowanceBal = -1;
|
|
1686
|
+
let bestActive = null;
|
|
1687
|
+
let bestActiveBal = -1;
|
|
1688
|
+
let bestAny = null;
|
|
1689
|
+
let bestAnyBal = -1;
|
|
1684
1690
|
for (const wallet of wallets) {
|
|
1685
|
-
if (wallet.status === "ACTIVE" && wallet.sources.some((source) => source.balance.available.amount >= transferAmount)) {
|
|
1686
|
-
return wallet;
|
|
1687
|
-
}
|
|
1688
|
-
}
|
|
1689
|
-
let bestWallet = null;
|
|
1690
|
-
let bestBalance = -1;
|
|
1691
|
-
let bestIsActive = false;
|
|
1692
|
-
for (const wallet of wallets) {
|
|
1693
|
-
const walletBal = wallet.balance.available.amount;
|
|
1694
1691
|
const isActive = wallet.status === "ACTIVE";
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1692
|
+
const walletBal = wallet.balance.available.amount;
|
|
1693
|
+
if (isActive) {
|
|
1694
|
+
const hasFullyEligibleSource = wallet.sources.some(
|
|
1695
|
+
(s) => s.balance.available.amount >= transferAmount && s.remainingAllowance != null && s.remainingAllowance >= transferAmount
|
|
1696
|
+
);
|
|
1697
|
+
if (hasFullyEligibleSource && walletBal > bestWithAllowanceBal) {
|
|
1698
|
+
bestWithAllowance = wallet;
|
|
1699
|
+
bestWithAllowanceBal = walletBal;
|
|
1700
|
+
}
|
|
1701
|
+
if (walletBal > bestActiveBal) {
|
|
1702
|
+
bestActive = wallet;
|
|
1703
|
+
bestActiveBal = walletBal;
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
if (walletBal > bestAnyBal) {
|
|
1707
|
+
bestAny = wallet;
|
|
1708
|
+
bestAnyBal = walletBal;
|
|
1699
1709
|
}
|
|
1700
1710
|
}
|
|
1701
|
-
return
|
|
1711
|
+
return bestWithAllowance ?? bestActive ?? bestAny ?? wallets[0];
|
|
1702
1712
|
}
|
|
1703
1713
|
function getDepositEligibleAccounts(accounts) {
|
|
1704
1714
|
return accounts.filter((account) => getAddressableWallets(account).length > 0);
|
|
@@ -1718,7 +1728,9 @@ function resolveDepositSelection(accounts, transferAmount, selectedAccountId) {
|
|
|
1718
1728
|
}
|
|
1719
1729
|
for (const account of eligibleAccounts) {
|
|
1720
1730
|
const fullyEligibleWallet = getAddressableWallets(account).find(
|
|
1721
|
-
(wallet) => wallet.status === "ACTIVE" && wallet.sources.some(
|
|
1731
|
+
(wallet) => wallet.status === "ACTIVE" && wallet.sources.some(
|
|
1732
|
+
(source) => source.balance.available.amount >= transferAmount && source.remainingAllowance != null && source.remainingAllowance >= transferAmount
|
|
1733
|
+
)
|
|
1722
1734
|
);
|
|
1723
1735
|
if (fullyEligibleWallet) {
|
|
1724
1736
|
return {
|
|
@@ -6474,6 +6486,9 @@ function useProviderHandlers(deps) {
|
|
|
6474
6486
|
useWalletConnectorProp,
|
|
6475
6487
|
activeCredentialId,
|
|
6476
6488
|
selectedAccountId,
|
|
6489
|
+
selectedWalletId,
|
|
6490
|
+
selectedTokenSymbol,
|
|
6491
|
+
chains,
|
|
6477
6492
|
accounts,
|
|
6478
6493
|
providers,
|
|
6479
6494
|
authExecutor,
|
|
@@ -6600,11 +6615,17 @@ function useProviderHandlers(deps) {
|
|
|
6600
6615
|
try {
|
|
6601
6616
|
const token = await getAccessToken();
|
|
6602
6617
|
if (!token) throw new Error("Not authenticated");
|
|
6618
|
+
const wallet = acct?.wallets.find((w) => w.id === selectedWalletId);
|
|
6619
|
+
const source = wallet?.sources.find(
|
|
6620
|
+
(s) => selectedTokenSymbol ? s.token.symbol === selectedTokenSymbol : s.token.status === "AUTHORIZED"
|
|
6621
|
+
);
|
|
6622
|
+
const evmChainId = chains.find((c) => c.name === wallet?.chain.name)?.commonId ?? void 0;
|
|
6603
6623
|
const session = await createAccountAuthorizationSession(
|
|
6604
6624
|
apiBaseUrl,
|
|
6605
6625
|
token,
|
|
6606
6626
|
selectedAccountId,
|
|
6607
|
-
activeCredentialId
|
|
6627
|
+
activeCredentialId,
|
|
6628
|
+
{ tokenAddress: source?.address, chainId: evmChainId }
|
|
6608
6629
|
);
|
|
6609
6630
|
const isMobile = !shouldUseWalletConnector({
|
|
6610
6631
|
useWalletConnector: useWalletConnectorProp,
|
|
@@ -6642,6 +6663,9 @@ function useProviderHandlers(deps) {
|
|
|
6642
6663
|
}
|
|
6643
6664
|
}, [
|
|
6644
6665
|
selectedAccountId,
|
|
6666
|
+
selectedWalletId,
|
|
6667
|
+
selectedTokenSymbol,
|
|
6668
|
+
chains,
|
|
6645
6669
|
activeCredentialId,
|
|
6646
6670
|
accounts,
|
|
6647
6671
|
providers,
|
|
@@ -7507,6 +7531,9 @@ function SwypePaymentInner({
|
|
|
7507
7531
|
useWalletConnectorProp,
|
|
7508
7532
|
activeCredentialId: state.activeCredentialId,
|
|
7509
7533
|
selectedAccountId: state.selectedAccountId,
|
|
7534
|
+
selectedWalletId: state.selectedWalletId,
|
|
7535
|
+
selectedTokenSymbol: state.selectedTokenSymbol,
|
|
7536
|
+
chains: state.chains,
|
|
7510
7537
|
accounts: state.accounts,
|
|
7511
7538
|
providers: state.providers,
|
|
7512
7539
|
authExecutor,
|