From 49a45bb68f15917bb8a9aeb34b106cd38bb66627 Mon Sep 17 00:00:00 2001 From: Sam Holmes Date: Fri, 6 Sep 2024 17:37:09 -0700 Subject: [PATCH] Finish check for $50 maximum sweep amount for light accounts --- CHANGELOG.md | 1 + src/actions/ScanActions.tsx | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 842e4c17ff1..7a71e644d13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - changed: Some unecessary `showError` dropdowns demoted to hidden `showDevError` - changed: Restrict Bity buy/sell to no-KYC asset - changed: Determine Moonpay asset support using chainCode/contractAddress +- changed: Allow private key sweep in light accounts for amounts less than $50 - changed: Allow reverse quotes for Kado - changed: Credit card allowed countries to add Botswana, Cambodia, Panama, and Sri Lanka - fixed: Default swap pair logic from the trade modal was not prioritizing mainnet assets diff --git a/src/actions/ScanActions.tsx b/src/actions/ScanActions.tsx index e6426c32a7d..b7b75c1da22 100644 --- a/src/actions/ScanActions.tsx +++ b/src/actions/ScanActions.tsx @@ -1,4 +1,4 @@ -import { gt } from 'biggystring' +import { abs, eq, gt, mul } from 'biggystring' import { asMaybeInsufficientFundsError, EdgeAccount, EdgeCurrencyWallet, EdgeParsedUri, EdgeSpendInfo, EdgeTokenId } from 'edge-core-js' import * as React from 'react' import { sprintf } from 'sprintf-js' @@ -10,7 +10,7 @@ import { WalletListModal, WalletListResult } from '../components/modals/WalletLi import { Airship, showError, showWarning } from '../components/services/AirshipInstance' import { getSpecialCurrencyInfo } from '../constants/WalletAndCurrencyConstants' import { lstrings } from '../locales/strings' -import { convertCurrency } from '../selectors/WalletSelectors' +import { getExchangeRate } from '../selectors/WalletSelectors' import { config } from '../theme/appConfig' import { RequestAddressLink } from '../types/DeepLinkTypes' import { Dispatch, RootState, ThunkAction } from '../types/reduxTypes' @@ -278,17 +278,22 @@ async function privateKeyModalActivated( } async function sweepPrivateKeys(state: RootState, account: EdgeAccount, navigation: NavigationBase, wallet: EdgeCurrencyWallet, privateKeys: string[]) { - if (checkAndShowLightBackupModal(account, navigation)) return - try { const unsignedTx = await wallet.sweepPrivateKeys({ tokenId: null, privateKeys, spendTargets: [] }) - // Check for a $50 maximum sweep for light accounts - const sweepAmountFiat = convertCurrency(state, wallet.currencyInfo.currencyCode, 'USD', unsignedTx.nativeAmount) - if (gt(sweepAmountFiat, 50) && checkAndShowLightBackupModal(account, navigation)) return + + // Check for a $50 maximum sweep for light accounts: + const sendNativeAmount = abs(unsignedTx.nativeAmount) + const sendExchangeAmount = await wallet.nativeToDenomination(sendNativeAmount, wallet.currencyInfo.currencyCode) + const exchangeRate = getExchangeRate(state, wallet.currencyInfo.currencyCode, 'iso:USD') + const sweepAmountFiat = mul(sendExchangeAmount, exchangeRate) + if (eq(exchangeRate, '0') || gt(sweepAmountFiat, '50')) { + const modalShown = checkAndShowLightBackupModal(account, navigation) + if (modalShown) return + } // Continue with sweep if above requirements met const signedTx = await wallet.signTx(unsignedTx)