Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ PODS:
- disklet (0.5.2):
- React
- DoubleConversion (1.1.6)
- edge-core-js (2.35.0):
- edge-core-js (2.37.0):
- React-Core
- edge-currency-accountbased (4.66.0):
- React-Core
Expand Down Expand Up @@ -3333,7 +3333,7 @@ SPEC CHECKSUMS:
CNIOWindows: 3047f2d8165848a3936a0a755fee27c6b5ee479b
disklet: 8a20bf8a568635b6e6bb8f93297dac13ee5cef98
DoubleConversion: cb417026b2400c8f53ae97020b2be961b59470cb
edge-core-js: 2e9266c5197e8f556058acf4874e5e554985e590
edge-core-js: 248f7d28942a5ea6c9835eca6f9f16969c89476c
edge-currency-accountbased: 434044274f205514017b18fe3dd3cb942231e233
edge-currency-plugins: 0d8a1a8da63672342cbc9bd5055feb4b397544e7
edge-exchange-plugins: a97b9ea3ede379b8aad026c5bd3f67d042b09983
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"deprecated-react-native-prop-types": "^5.0.0",
"detect-bundler": "^1.1.0",
"disklet": "^0.5.2",
"edge-core-js": "^2.35.0",
"edge-core-js": "^2.37.0",
"edge-currency-accountbased": "^4.66.0",
"edge-currency-monero": "^2.0.1",
"edge-currency-plugins": "^3.8.9",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ exports[`initialState 1`] = `
},
"fio": {
"connectedWalletsByFioAddress": {},
"fioWallets": [],
},
"fioAddress": {
"fioAddresses": [],
Expand Down Expand Up @@ -156,11 +157,6 @@ exports[`initialState 1`] = `
"walletsSort": "manual",
},
"subcategories": [],
"wallets": {
"fioWallets": [],
"selectedCurrencyCode": "",
"selectedWalletId": "",
},
},
}
`;
15 changes: 9 additions & 6 deletions src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, test } from '@jest/globals'
import { log10 } from 'biggystring'

import { selectDisplayDenomByCurrencyCode } from '../selectors/DenominationSelectors'
import { selectDisplayDenom } from '../selectors/DenominationSelectors'
import { btcCurrencyInfo } from '../util/fake/fakeBtcInfo'
import { makeFakeCurrencyConfig } from '../util/fake/fakeCurrencyConfig'
import { ethCurrencyInfo } from '../util/fake/fakeEthInfo'
Expand Down Expand Up @@ -393,15 +393,18 @@ describe('getDisplayDenomination', function () {
const input = [
{
pluginId: 'bitcoin',
currencyCode: 'BTC'
currencyCode: 'BTC',
tokenId: null
},
{
pluginId: 'ethereum',
currencyCode: 'ETH'
currencyCode: 'ETH',
tokenId: null
},
{
pluginId: 'ethereum',
currencyCode: 'TKN'
currencyCode: 'TKN',
tokenId: '1985365e9f78359a9B6AD760e32412f4a445E862'
}
] as const
const output = [
Expand All @@ -425,10 +428,10 @@ describe('getDisplayDenomination', function () {
const currencyConfig =
state.core.account.currencyConfig[currency.pluginId]
expect(
selectDisplayDenomByCurrencyCode(
selectDisplayDenom(
state as any,
currencyConfig as any,
currency.currencyCode
currency.tokenId
)
).toMatchObject(output[index])
})
Expand Down
11 changes: 3 additions & 8 deletions src/actions/CreateWalletActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ import type {
import { Airship } from '../components/services/AirshipInstance'
import { SPECIAL_CURRENCY_INFO } from '../constants/WalletAndCurrencyConstants'
import { lstrings } from '../locales/strings'
import { getExchangeDenomByCurrencyCode } from '../selectors/DenominationSelectors'
import { getExchangeDenom } from '../selectors/DenominationSelectors'
import type { TokenWalletCreateItem } from '../selectors/getCreateWalletList'
import { config } from '../theme/appConfig'
import type { ThunkAction } from '../types/reduxTypes'
import type { NavigationBase } from '../types/routerTypes'
import type { EdgeAsset } from '../types/types'
import { getWalletTokenId } from '../util/CurrencyInfoHelpers'
import { logActivity } from '../util/logger'
import { filterNull } from '../util/safeFilters'
import { logEvent } from '../util/tracking'
Expand Down Expand Up @@ -155,16 +154,12 @@ export function createAccountTransaction(
createdCurrencyWallet.currencyInfo.currencyCode
const currencyPlugin =
account.currencyConfig[createdCurrencyWallet.currencyInfo.pluginId]
const { paymentAddress, amount, currencyCode } = activationPaymentInfo
const { paymentAddress, amount, tokenId } = activationPaymentInfo
const handleAvailability =
await currencyPlugin.otherMethods.validateAccount(accountName)
const paymentDenom = getExchangeDenomByCurrencyCode(
paymentWallet.currencyConfig,
currencyCode
)
const paymentDenom = getExchangeDenom(paymentWallet.currencyConfig, tokenId)
let nativeAmount = mul(amount, paymentDenom.multiplier)
nativeAmount = toFixed(nativeAmount, 0, 0)
const tokenId = getWalletTokenId(paymentWallet, currencyCode)

if (handleAvailability.result === 'AccountAvailable') {
navigation.push('send2', {
Expand Down
4 changes: 2 additions & 2 deletions src/actions/FioActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const refreshConnectedWallets = async (
getState: GetState
) => {
const wallets: EdgeCurrencyWallet[] = []
const fioWallets: EdgeCurrencyWallet[] = getState().ui.wallets.fioWallets
const fioWallets: EdgeCurrencyWallet[] = getState().ui.fio.fioWallets
const currencyWallets = getState().core.account.currencyWallets
for (const walletId of Object.keys(currencyWallets)) {
wallets.push(currencyWallets[walletId])
Expand Down Expand Up @@ -69,7 +69,7 @@ export function checkFioObtData(
let loopCount = 0
while (true) {
account = state.core.account
fioWallets = state.ui.wallets.fioWallets
fioWallets = state.ui.fio.fioWallets
if (account?.currencyConfig != null && fioWallets.length > 0) break
if (loopCount++ > MAX_OBT_DATA_CHECKS) return
await snooze(400)
Expand Down
2 changes: 1 addition & 1 deletion src/actions/FioAddressActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function refreshAllFioAddresses(): ThunkAction<Promise<void>> {
})
const state = getState()
const { currencyWallets } = state.core.account
const fioWallets: EdgeCurrencyWallet[] = state.ui.wallets.fioWallets
const fioWallets: EdgeCurrencyWallet[] = state.ui.fio.fioWallets

const { fioAddresses, fioDomains, fioWalletsById } = await refreshFioNames(
fioWallets
Expand Down
18 changes: 11 additions & 7 deletions src/actions/LoginActions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { EdgeAccount, EdgeCreateCurrencyWallet } from 'edge-core-js/types'
import type {
EdgeAccount,
EdgeCreateCurrencyWallet,
EdgeTokenId
} from 'edge-core-js/types'
import {
getSupportedBiometryType,
hasSecurityAlerts,
Expand Down Expand Up @@ -53,7 +57,7 @@ const MIN_CREATE_WALLET_TIMEOUT = 20000

function getFirstActiveWalletInfo(account: EdgeAccount): {
walletId: string
currencyCode: string
tokenId: EdgeTokenId
} {
// Find the first wallet:
const [walletId] = account.activeWalletIds
Expand All @@ -64,13 +68,13 @@ function getFirstActiveWalletInfo(account: EdgeAccount): {
for (const pluginId of Object.keys(account.currencyConfig)) {
const { currencyInfo } = account.currencyConfig[pluginId]
if (currencyInfo.walletType === walletKey.type) {
return { walletId, currencyCode: currencyInfo.currencyCode }
return { walletId, tokenId: null }
}
}
}

// The user has no wallets:
return { walletId: '', currencyCode: '' }
return { walletId: '', tokenId: null }
}

export function initializeAccount(
Expand Down Expand Up @@ -257,7 +261,7 @@ export function initializeAccount(
let accountInitObject: AccountInitPayload = {
...initialState,
account,
currencyCode: '',
tokenId: null,
pinLoginEnabled: false,
isTouchEnabled: await isTouchEnabled(account),
isTouchSupported: (await getSupportedBiometryType()) !== false,
Expand All @@ -267,9 +271,9 @@ export function initializeAccount(
try {
if (!newAccount) {
// We have a wallet
const { walletId, currencyCode } = getFirstActiveWalletInfo(account)
const { walletId, tokenId } = getFirstActiveWalletInfo(account)
accountInitObject.walletId = walletId
accountInitObject.currencyCode = currencyCode
accountInitObject.tokenId = tokenId
}

accountInitObject = { ...accountInitObject, ...syncedSettings }
Expand Down
11 changes: 3 additions & 8 deletions src/actions/ScanActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ import {
} from '../components/services/AirshipInstance'
import { getSpecialCurrencyInfo } from '../constants/WalletAndCurrencyConstants'
import { lstrings } from '../locales/strings'
import { getExchangeDenom } from '../selectors/DenominationSelectors'
import { getExchangeRate } from '../selectors/WalletSelectors'
import { config } from '../theme/appConfig'
import type { RequestAddressLink } from '../types/DeepLinkTypes'
import type { Dispatch, RootState, ThunkAction } from '../types/reduxTypes'
import type { NavigationBase } from '../types/routerTypes'
import {
getCurrencyCode,
getCurrencyCodeMultiplier
} from '../util/CurrencyInfoHelpers'
import { getCurrencyCode } from '../util/CurrencyInfoHelpers'
import { parseDeepLink } from '../util/DeepLinkParser'
import { logActivity } from '../util/logger'
import { runOnce } from '../util/runOnce'
Expand Down Expand Up @@ -401,10 +399,7 @@ async function sweepPrivateKeys(

// Check for a $50 maximum sweep for light accounts:
const sendNativeAmount = abs(unsignedTx.nativeAmount)
const multiplier = getCurrencyCodeMultiplier(
wallet.currencyConfig,
wallet.currencyInfo.currencyCode
)
const { multiplier } = getExchangeDenom(wallet.currencyConfig, null)
const sendExchangeAmount = div(
sendNativeAmount,
multiplier,
Expand Down
60 changes: 12 additions & 48 deletions src/actions/WalletActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@ import {
SPECIAL_CURRENCY_INFO
} from '../constants/WalletAndCurrencyConstants'
import { lstrings } from '../locales/strings'
import { selectDisplayDenomByCurrencyCode } from '../selectors/DenominationSelectors'
import {
getExchangeDenom,
selectDisplayDenom
} from '../selectors/DenominationSelectors'
import { convertCurrency } from '../selectors/WalletSelectors'
import type { ThunkAction } from '../types/reduxTypes'
import type { NavigationBase } from '../types/routerTypes'
import type { MapObject } from '../types/types'
import {
getCurrencyCode,
getCurrencyCodeMultiplier,
isKeysOnlyPlugin
} from '../util/CurrencyInfoHelpers'
import { getCurrencyCode, isKeysOnlyPlugin } from '../util/CurrencyInfoHelpers'
import { getWalletName } from '../util/CurrencyWalletHelpers'
import { fetchInfo } from '../util/network'

Expand Down Expand Up @@ -77,9 +76,6 @@ export function selectWalletToken({
const currencyCode = getCurrencyCode(wallet, tokenId)
dispatch(updateMostRecentWalletsSelected(walletId, tokenId))

const currentWalletId = state.ui.wallets.selectedWalletId
const currentWalletCurrencyCode = state.ui.wallets.selectedCurrencyCode

if (tokenId != null) {
const { unactivatedTokenIds } = wallet
if (
Expand All @@ -90,15 +86,7 @@ export function selectWalletToken({
await dispatch(activateWalletTokens(navigation, wallet, [tokenId]))
return false
}
if (
walletId !== currentWalletId ||
currencyCode !== currentWalletCurrencyCode
) {
dispatch({
type: 'UI/WALLETS/SELECT_WALLET',
data: { walletId, currencyCode }
})
}

return true
}

Expand All @@ -107,27 +95,14 @@ export function selectWalletToken({
)
if (isAccountActivationRequired) {
// activation-required wallets need different path in case not activated yet
if (
alwaysActivate ||
walletId !== currentWalletId ||
currencyCode !== currentWalletCurrencyCode
) {
if (alwaysActivate) {
return await dispatch(
selectActivationRequiredWallet(navigation, walletId, currencyCode)
)
}
return true
}

if (
walletId !== currentWalletId ||
currencyCode !== currentWalletCurrencyCode
) {
dispatch({
type: 'UI/WALLETS/SELECT_WALLET',
data: { walletId, currencyCode }
})
}
return true
}
}
Expand All @@ -146,10 +121,6 @@ function selectActivationRequiredWallet(

if (publicAddress !== '') {
// already activated
dispatch({
type: 'UI/WALLETS/SELECT_WALLET',
data: { walletId, currencyCode }
})
return true
} else {
// not activated yet
Expand Down Expand Up @@ -185,16 +156,14 @@ export function updateMostRecentWalletsSelected(
return (dispatch, getState) => {
const state = getState()
const { account } = state.core
const wallet = account.currencyWallets[walletId]
const currencyCode = getCurrencyCode(wallet, tokenId)
const { mostRecentWallets } = state.ui.settings
const currentMostRecentWallets = mostRecentWallets.filter(wallet => {
return wallet.id !== walletId || wallet.currencyCode !== currencyCode
return wallet.id !== walletId || wallet.tokenId !== tokenId
})
if (currentMostRecentWallets.length === 100) {
currentMostRecentWallets.pop()
}
currentMostRecentWallets.unshift({ id: walletId, currencyCode })
currentMostRecentWallets.unshift({ id: walletId, tokenId })

writeMostRecentWalletsSelected(account, currentMostRecentWallets)
.then(() => {
Expand Down Expand Up @@ -257,17 +226,12 @@ export function activateWalletTokens(
if (currencyPluginId !== pluginId)
throw new Error('Internal Error: Fee asset mismatch.')

const paymentCurrencyCode = getCurrencyCode(wallet, feeTokenId)

const multiplier = getCurrencyCodeMultiplier(
wallet.currencyConfig,
paymentCurrencyCode
)
const { multiplier } = getExchangeDenom(wallet.currencyConfig, feeTokenId)
const exchangeNetworkFee = div(nativeFee, multiplier, multiplier.length)
const feeDenom = selectDisplayDenomByCurrencyCode(
const feeDenom = selectDisplayDenom(
state,
wallet.currencyConfig,
paymentCurrencyCode
feeTokenId
)
const displayFee = div(
nativeFee,
Expand Down
Loading
Loading