Skip to content

Commit

Permalink
Merge pull request #3548 from EdgeApp/jon/patch/sweep-token-filter-v2
Browse files Browse the repository at this point in the history
Update sweep private key filtering
  • Loading branch information
thehobbit85 authored Jul 29, 2022
2 parents dcbae90 + e18b99f commit 65ddd05
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/components/themed/ControlPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { config } from '../../theme/appConfig.js'
import { useEffect, useMemo, useState } from '../../types/reactHooks.js'
import { useDispatch, useSelector } from '../../types/reactRedux'
import { type NavigationProp, type ParamList, Actions } from '../../types/routerTypes.js'
import { type EdgeTokenId } from '../../types/types'
import { SceneWrapper } from '../common/SceneWrapper.js'
import { ButtonsModal } from '../modals/ButtonsModal.js'
import { ScanModal } from '../modals/ScanModal'
Expand Down Expand Up @@ -53,7 +54,6 @@ export function ControlPanel(props: Props) {
// ---- Redux State ----

const account = useSelector(state => state.core.account)
const wallets = useWatch(account, 'currencyWallets')
const activeUsername = useSelector(state => state.core.account.username)
const context = useSelector(state => state.core.context)
const selectedWallet = useSelectedWallet()
Expand Down Expand Up @@ -106,16 +106,26 @@ export function ControlPanel(props: Props) {
}

const handleSweep = () => {
const excludeWalletIds = Object.keys(wallets).filter(
walletId => !SWEEPABLE_CURRENCY_CODES.some(currencyCode => currencyCode === wallets[walletId].currencyInfo.currencyCode)
)
// Only allow native assets, filtered by sweepable currency codes
const allowedAssets: EdgeTokenId[] = Object.keys(account.currencyConfig)
.filter(pluginId => {
const currencyConfig = account.currencyConfig[pluginId]
return SWEEPABLE_CURRENCY_CODES.some(
sweepableCurrencyCode => currencyConfig.currencyInfo.currencyCode.toLowerCase() === sweepableCurrencyCode.toLowerCase()
)
})
.map(pluginId =>
// Return an "EdgeTokenId" specifying that this must NOT be a token
// (implies it must be a supported native asset)
({ pluginId, tokenId: undefined })
)

Airship.show(bridge => (
<WalletListModal
bridge={bridge}
headerTitle={s.strings.select_wallet}
allowedAssets={allowedAssets}
allowedCurrencyCodes={SWEEPABLE_CURRENCY_CODES}
excludeWalletIds={excludeWalletIds}
showCreateWallet
/>
)).then(({ walletId, currencyCode }: WalletListResult) => {
Expand Down

0 comments on commit 65ddd05

Please sign in to comment.