Skip to content

Commit 165dea2

Browse files
authored
Merge pull request #5855 from EdgeApp/matthew/sans-currency-code
Use tokenId instead of currencyCode
2 parents f2955cf + 3b09883 commit 165dea2

File tree

107 files changed

+1306
-1188
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+1306
-1188
lines changed

ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ PODS:
1515
- disklet (0.5.2):
1616
- React
1717
- DoubleConversion (1.1.6)
18-
- edge-core-js (2.35.0):
18+
- edge-core-js (2.37.0):
1919
- React-Core
2020
- edge-currency-accountbased (4.66.0):
2121
- React-Core
@@ -3333,7 +3333,7 @@ SPEC CHECKSUMS:
33333333
CNIOWindows: 3047f2d8165848a3936a0a755fee27c6b5ee479b
33343334
disklet: 8a20bf8a568635b6e6bb8f93297dac13ee5cef98
33353335
DoubleConversion: cb417026b2400c8f53ae97020b2be961b59470cb
3336-
edge-core-js: 2e9266c5197e8f556058acf4874e5e554985e590
3336+
edge-core-js: 248f7d28942a5ea6c9835eca6f9f16969c89476c
33373337
edge-currency-accountbased: 434044274f205514017b18fe3dd3cb942231e233
33383338
edge-currency-plugins: 0d8a1a8da63672342cbc9bd5055feb4b397544e7
33393339
edge-exchange-plugins: a97b9ea3ede379b8aad026c5bd3f67d042b09983

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
"deprecated-react-native-prop-types": "^5.0.0",
106106
"detect-bundler": "^1.1.0",
107107
"disklet": "^0.5.2",
108-
"edge-core-js": "^2.35.0",
108+
"edge-core-js": "^2.37.0",
109109
"edge-currency-accountbased": "^4.66.0",
110110
"edge-currency-monero": "^2.0.1",
111111
"edge-currency-plugins": "^3.8.9",

src/__tests__/reducers/__snapshots__/RootReducer.test.ts.snap

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ exports[`initialState 1`] = `
8585
},
8686
"fio": {
8787
"connectedWalletsByFioAddress": {},
88+
"fioWallets": [],
8889
},
8990
"fioAddress": {
9091
"fioAddresses": [],
@@ -156,11 +157,6 @@ exports[`initialState 1`] = `
156157
"walletsSort": "manual",
157158
},
158159
"subcategories": [],
159-
"wallets": {
160-
"fioWallets": [],
161-
"selectedCurrencyCode": "",
162-
"selectedWalletId": "",
163-
},
164160
},
165161
}
166162
`;

src/__tests__/utils.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, expect, test } from '@jest/globals'
22
import { log10 } from 'biggystring'
33

4-
import { selectDisplayDenomByCurrencyCode } from '../selectors/DenominationSelectors'
4+
import { selectDisplayDenom } from '../selectors/DenominationSelectors'
55
import { btcCurrencyInfo } from '../util/fake/fakeBtcInfo'
66
import { makeFakeCurrencyConfig } from '../util/fake/fakeCurrencyConfig'
77
import { ethCurrencyInfo } from '../util/fake/fakeEthInfo'
@@ -393,15 +393,18 @@ describe('getDisplayDenomination', function () {
393393
const input = [
394394
{
395395
pluginId: 'bitcoin',
396-
currencyCode: 'BTC'
396+
currencyCode: 'BTC',
397+
tokenId: null
397398
},
398399
{
399400
pluginId: 'ethereum',
400-
currencyCode: 'ETH'
401+
currencyCode: 'ETH',
402+
tokenId: null
401403
},
402404
{
403405
pluginId: 'ethereum',
404-
currencyCode: 'TKN'
406+
currencyCode: 'TKN',
407+
tokenId: '1985365e9f78359a9B6AD760e32412f4a445E862'
405408
}
406409
] as const
407410
const output = [
@@ -425,10 +428,10 @@ describe('getDisplayDenomination', function () {
425428
const currencyConfig =
426429
state.core.account.currencyConfig[currency.pluginId]
427430
expect(
428-
selectDisplayDenomByCurrencyCode(
431+
selectDisplayDenom(
429432
state as any,
430433
currencyConfig as any,
431-
currency.currencyCode
434+
currency.tokenId
432435
)
433436
).toMatchObject(output[index])
434437
})

src/actions/CreateWalletActions.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ import type {
1919
import { Airship } from '../components/services/AirshipInstance'
2020
import { SPECIAL_CURRENCY_INFO } from '../constants/WalletAndCurrencyConstants'
2121
import { lstrings } from '../locales/strings'
22-
import { getExchangeDenomByCurrencyCode } from '../selectors/DenominationSelectors'
22+
import { getExchangeDenom } from '../selectors/DenominationSelectors'
2323
import type { TokenWalletCreateItem } from '../selectors/getCreateWalletList'
2424
import { config } from '../theme/appConfig'
2525
import type { ThunkAction } from '../types/reduxTypes'
2626
import type { NavigationBase } from '../types/routerTypes'
2727
import type { EdgeAsset } from '../types/types'
28-
import { getWalletTokenId } from '../util/CurrencyInfoHelpers'
2928
import { logActivity } from '../util/logger'
3029
import { filterNull } from '../util/safeFilters'
3130
import { logEvent } from '../util/tracking'
@@ -155,16 +154,12 @@ export function createAccountTransaction(
155154
createdCurrencyWallet.currencyInfo.currencyCode
156155
const currencyPlugin =
157156
account.currencyConfig[createdCurrencyWallet.currencyInfo.pluginId]
158-
const { paymentAddress, amount, currencyCode } = activationPaymentInfo
157+
const { paymentAddress, amount, tokenId } = activationPaymentInfo
159158
const handleAvailability =
160159
await currencyPlugin.otherMethods.validateAccount(accountName)
161-
const paymentDenom = getExchangeDenomByCurrencyCode(
162-
paymentWallet.currencyConfig,
163-
currencyCode
164-
)
160+
const paymentDenom = getExchangeDenom(paymentWallet.currencyConfig, tokenId)
165161
let nativeAmount = mul(amount, paymentDenom.multiplier)
166162
nativeAmount = toFixed(nativeAmount, 0, 0)
167-
const tokenId = getWalletTokenId(paymentWallet, currencyCode)
168163

169164
if (handleAvailability.result === 'AccountAvailable') {
170165
navigation.push('send2', {

src/actions/FioActions.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const refreshConnectedWallets = async (
2727
getState: GetState
2828
) => {
2929
const wallets: EdgeCurrencyWallet[] = []
30-
const fioWallets: EdgeCurrencyWallet[] = getState().ui.wallets.fioWallets
30+
const fioWallets: EdgeCurrencyWallet[] = getState().ui.fio.fioWallets
3131
const currencyWallets = getState().core.account.currencyWallets
3232
for (const walletId of Object.keys(currencyWallets)) {
3333
wallets.push(currencyWallets[walletId])
@@ -69,7 +69,7 @@ export function checkFioObtData(
6969
let loopCount = 0
7070
while (true) {
7171
account = state.core.account
72-
fioWallets = state.ui.wallets.fioWallets
72+
fioWallets = state.ui.fio.fioWallets
7373
if (account?.currencyConfig != null && fioWallets.length > 0) break
7474
if (loopCount++ > MAX_OBT_DATA_CHECKS) return
7575
await snooze(400)

src/actions/FioAddressActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function refreshAllFioAddresses(): ThunkAction<Promise<void>> {
3131
})
3232
const state = getState()
3333
const { currencyWallets } = state.core.account
34-
const fioWallets: EdgeCurrencyWallet[] = state.ui.wallets.fioWallets
34+
const fioWallets: EdgeCurrencyWallet[] = state.ui.fio.fioWallets
3535

3636
const { fioAddresses, fioDomains, fioWalletsById } = await refreshFioNames(
3737
fioWallets

src/actions/LoginActions.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import type { EdgeAccount, EdgeCreateCurrencyWallet } from 'edge-core-js/types'
1+
import type {
2+
EdgeAccount,
3+
EdgeCreateCurrencyWallet,
4+
EdgeTokenId
5+
} from 'edge-core-js/types'
26
import {
37
getSupportedBiometryType,
48
hasSecurityAlerts,
@@ -53,7 +57,7 @@ const MIN_CREATE_WALLET_TIMEOUT = 20000
5357

5458
function getFirstActiveWalletInfo(account: EdgeAccount): {
5559
walletId: string
56-
currencyCode: string
60+
tokenId: EdgeTokenId
5761
} {
5862
// Find the first wallet:
5963
const [walletId] = account.activeWalletIds
@@ -64,13 +68,13 @@ function getFirstActiveWalletInfo(account: EdgeAccount): {
6468
for (const pluginId of Object.keys(account.currencyConfig)) {
6569
const { currencyInfo } = account.currencyConfig[pluginId]
6670
if (currencyInfo.walletType === walletKey.type) {
67-
return { walletId, currencyCode: currencyInfo.currencyCode }
71+
return { walletId, tokenId: null }
6872
}
6973
}
7074
}
7175

7276
// The user has no wallets:
73-
return { walletId: '', currencyCode: '' }
77+
return { walletId: '', tokenId: null }
7478
}
7579

7680
export function initializeAccount(
@@ -257,7 +261,7 @@ export function initializeAccount(
257261
let accountInitObject: AccountInitPayload = {
258262
...initialState,
259263
account,
260-
currencyCode: '',
264+
tokenId: null,
261265
pinLoginEnabled: false,
262266
isTouchEnabled: await isTouchEnabled(account),
263267
isTouchSupported: (await getSupportedBiometryType()) !== false,
@@ -267,9 +271,9 @@ export function initializeAccount(
267271
try {
268272
if (!newAccount) {
269273
// We have a wallet
270-
const { walletId, currencyCode } = getFirstActiveWalletInfo(account)
274+
const { walletId, tokenId } = getFirstActiveWalletInfo(account)
271275
accountInitObject.walletId = walletId
272-
accountInitObject.currencyCode = currencyCode
276+
accountInitObject.tokenId = tokenId
273277
}
274278

275279
accountInitObject = { ...accountInitObject, ...syncedSettings }

src/actions/ScanActions.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@ import {
2525
} from '../components/services/AirshipInstance'
2626
import { getSpecialCurrencyInfo } from '../constants/WalletAndCurrencyConstants'
2727
import { lstrings } from '../locales/strings'
28+
import { getExchangeDenom } from '../selectors/DenominationSelectors'
2829
import { getExchangeRate } from '../selectors/WalletSelectors'
2930
import { config } from '../theme/appConfig'
3031
import type { RequestAddressLink } from '../types/DeepLinkTypes'
3132
import type { Dispatch, RootState, ThunkAction } from '../types/reduxTypes'
3233
import type { NavigationBase } from '../types/routerTypes'
33-
import {
34-
getCurrencyCode,
35-
getCurrencyCodeMultiplier
36-
} from '../util/CurrencyInfoHelpers'
34+
import { getCurrencyCode } from '../util/CurrencyInfoHelpers'
3735
import { parseDeepLink } from '../util/DeepLinkParser'
3836
import { logActivity } from '../util/logger'
3937
import { runOnce } from '../util/runOnce'
@@ -401,10 +399,7 @@ async function sweepPrivateKeys(
401399

402400
// Check for a $50 maximum sweep for light accounts:
403401
const sendNativeAmount = abs(unsignedTx.nativeAmount)
404-
const multiplier = getCurrencyCodeMultiplier(
405-
wallet.currencyConfig,
406-
wallet.currencyInfo.currencyCode
407-
)
402+
const { multiplier } = getExchangeDenom(wallet.currencyConfig, null)
408403
const sendExchangeAmount = div(
409404
sendNativeAmount,
410405
multiplier,

src/actions/WalletActions.tsx

Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,15 @@ import {
2828
SPECIAL_CURRENCY_INFO
2929
} from '../constants/WalletAndCurrencyConstants'
3030
import { lstrings } from '../locales/strings'
31-
import { selectDisplayDenomByCurrencyCode } from '../selectors/DenominationSelectors'
31+
import {
32+
getExchangeDenom,
33+
selectDisplayDenom
34+
} from '../selectors/DenominationSelectors'
3235
import { convertCurrency } from '../selectors/WalletSelectors'
3336
import type { ThunkAction } from '../types/reduxTypes'
3437
import type { NavigationBase } from '../types/routerTypes'
3538
import type { MapObject } from '../types/types'
36-
import {
37-
getCurrencyCode,
38-
getCurrencyCodeMultiplier,
39-
isKeysOnlyPlugin
40-
} from '../util/CurrencyInfoHelpers'
39+
import { getCurrencyCode, isKeysOnlyPlugin } from '../util/CurrencyInfoHelpers'
4140
import { getWalletName } from '../util/CurrencyWalletHelpers'
4241
import { fetchInfo } from '../util/network'
4342

@@ -77,9 +76,6 @@ export function selectWalletToken({
7776
const currencyCode = getCurrencyCode(wallet, tokenId)
7877
dispatch(updateMostRecentWalletsSelected(walletId, tokenId))
7978

80-
const currentWalletId = state.ui.wallets.selectedWalletId
81-
const currentWalletCurrencyCode = state.ui.wallets.selectedCurrencyCode
82-
8379
if (tokenId != null) {
8480
const { unactivatedTokenIds } = wallet
8581
if (
@@ -90,15 +86,7 @@ export function selectWalletToken({
9086
await dispatch(activateWalletTokens(navigation, wallet, [tokenId]))
9187
return false
9288
}
93-
if (
94-
walletId !== currentWalletId ||
95-
currencyCode !== currentWalletCurrencyCode
96-
) {
97-
dispatch({
98-
type: 'UI/WALLETS/SELECT_WALLET',
99-
data: { walletId, currencyCode }
100-
})
101-
}
89+
10290
return true
10391
}
10492

@@ -107,27 +95,14 @@ export function selectWalletToken({
10795
)
10896
if (isAccountActivationRequired) {
10997
// activation-required wallets need different path in case not activated yet
110-
if (
111-
alwaysActivate ||
112-
walletId !== currentWalletId ||
113-
currencyCode !== currentWalletCurrencyCode
114-
) {
98+
if (alwaysActivate) {
11599
return await dispatch(
116100
selectActivationRequiredWallet(navigation, walletId, currencyCode)
117101
)
118102
}
119103
return true
120104
}
121105

122-
if (
123-
walletId !== currentWalletId ||
124-
currencyCode !== currentWalletCurrencyCode
125-
) {
126-
dispatch({
127-
type: 'UI/WALLETS/SELECT_WALLET',
128-
data: { walletId, currencyCode }
129-
})
130-
}
131106
return true
132107
}
133108
}
@@ -146,10 +121,6 @@ function selectActivationRequiredWallet(
146121

147122
if (publicAddress !== '') {
148123
// already activated
149-
dispatch({
150-
type: 'UI/WALLETS/SELECT_WALLET',
151-
data: { walletId, currencyCode }
152-
})
153124
return true
154125
} else {
155126
// not activated yet
@@ -185,16 +156,14 @@ export function updateMostRecentWalletsSelected(
185156
return (dispatch, getState) => {
186157
const state = getState()
187158
const { account } = state.core
188-
const wallet = account.currencyWallets[walletId]
189-
const currencyCode = getCurrencyCode(wallet, tokenId)
190159
const { mostRecentWallets } = state.ui.settings
191160
const currentMostRecentWallets = mostRecentWallets.filter(wallet => {
192-
return wallet.id !== walletId || wallet.currencyCode !== currencyCode
161+
return wallet.id !== walletId || wallet.tokenId !== tokenId
193162
})
194163
if (currentMostRecentWallets.length === 100) {
195164
currentMostRecentWallets.pop()
196165
}
197-
currentMostRecentWallets.unshift({ id: walletId, currencyCode })
166+
currentMostRecentWallets.unshift({ id: walletId, tokenId })
198167

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

260-
const paymentCurrencyCode = getCurrencyCode(wallet, feeTokenId)
261-
262-
const multiplier = getCurrencyCodeMultiplier(
263-
wallet.currencyConfig,
264-
paymentCurrencyCode
265-
)
229+
const { multiplier } = getExchangeDenom(wallet.currencyConfig, feeTokenId)
266230
const exchangeNetworkFee = div(nativeFee, multiplier, multiplier.length)
267-
const feeDenom = selectDisplayDenomByCurrencyCode(
231+
const feeDenom = selectDisplayDenom(
268232
state,
269233
wallet.currencyConfig,
270-
paymentCurrencyCode
234+
feeTokenId
271235
)
272236
const displayFee = div(
273237
nativeFee,

0 commit comments

Comments
 (0)