Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

- added: Buy conversion tracking for Moonpay
- added: Error tracking for failure to report conversions to referral server
- changed: Remove whitespaces from custom token contract address input
- fixed: Clear previous swap errors when new amounts are entered or swap assets are changed in `SwapCreateScene`
- fixed: AddressTile2 touchable area states
- fixed: Cases where it was possible to create duplicate custom tokens
- fixed: Message about overriding a built-in token contract, which is not possible to do

## 4.14.0

Expand All @@ -19,8 +22,9 @@
- added: Sell with Moonpay
- changed: Added Iraq to list of Visa/MC supported countries
- changed: Display Asset Status cards in the same style as Promo Cards
- changed: Updated ACH supported US stat- fixed: Inconsistent content of address hint dropdown between iOS and Android in `AddressFormScene`
- changed: Updated ACH supported US states
- changed: Use new platform-specific `assetStatsCards2` info server data
- fixed: Inconsistent content of address hint dropdown between iOS and Android in `AddressFormScene`
- fixed: Crash on HomeScene when logging while in airplane mode
- fixed: Inconsistent corners in `SideMenu`
- fixed: "Most Recent Wallets" do not show those chosen through `fiatPlugin`
Expand Down
65 changes: 36 additions & 29 deletions src/components/scenes/EditTokenScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export interface EditTokenParams {
displayName?: string
multiplier?: string
networkLocation?: JsonObject
tokenId?: EdgeTokenId // Acts like "add token" if this is missing

/** If exists, means they are editing an existing custom token.
* If missing, then creating/adding a new token */
tokenId?: EdgeTokenId
walletId: string
}

Expand Down Expand Up @@ -138,45 +141,49 @@ function EditTokenSceneComponent(props: Props) {
await wallet.currencyConfig.changeCustomToken(tokenId, customTokenInput)
navigation.goBack()
} else {
// Creating a new token
const { currencyConfig } = wallet
const { builtinTokens } = currencyConfig

// Check if custom token input conflicts with built-in tokens.
// There's currently no mechanism to obtain a new custom token's tokenId
// for proper comparison against built-in tokens besides physically adding
// the new custom token first.
const newTokenId = await currencyConfig.addCustomToken(customTokenInput)

const matchingContractToken =
Object.keys(builtinTokens).find(builtinTokenId => builtinTokenId === newTokenId) == null ? undefined : builtinTokens[newTokenId]
const isMatchingCurrencyCode = Object.values(builtinTokens).find(builtInToken => builtInToken.currencyCode === currencyCode) != null
const newTokenId = await currencyConfig.getTokenId(customTokenInput)

if (matchingContractToken != null && isMatchingCurrencyCode) {
await showMessage(sprintf(lstrings.warning_token_exists_1s, currencyCode))
// Check if custom token input conflicts with built-in tokens.
const matchingBuiltinTokenId = Object.keys(builtinTokens).find(builtinTokenId => builtinTokenId === newTokenId)
if (matchingBuiltinTokenId != null) {
await showMessage(sprintf(lstrings.warning_token_exists_1s, builtinTokens[matchingBuiltinTokenId].currencyCode))
return
}

const warningMessage =
isMatchingCurrencyCode && matchingContractToken == null
? sprintf(lstrings.warning_token_code_override_2s, currencyCode, config.supportEmail)
: matchingContractToken != null && !isMatchingCurrencyCode
? sprintf(lstrings.warning_token_contract_override_3s, currencyCode, matchingContractToken.currencyCode, config.supportEmail)
: undefined

const approveAdd =
warningMessage == null
? true
: await Airship.show<boolean>(bridge => (
<ConfirmContinueModal bridge={bridge} body={warningMessage} title={lstrings.string_warning} warning isSkippable />
))
const isMatchingBuiltinCurrencyCode = Object.values(builtinTokens).find(builtInToken => builtInToken.currencyCode === currencyCode) != null
const approveAdd = !isMatchingBuiltinCurrencyCode
? true
: await Airship.show<boolean>(bridge => (
<ConfirmContinueModal
bridge={bridge}
body={sprintf(lstrings.warning_token_code_override_2s, currencyCode, config.supportEmail)}
title={lstrings.string_warning}
warning
isSkippable
/>
))

if (approveAdd) {
// Check if custom token input conflicts with custom tokens.
if (currencyConfig.customTokens[newTokenId] != null) {
// Always override changes to custom tokens
// TODO: Fine for if they are on this scene intentionally modifying a
// custom token, but maybe warn about this override if they are trying
// to add a new custom token with the same contract address as an
// existing custom token
await currencyConfig.changeCustomToken(newTokenId, customTokenInput)
} else {
await currencyConfig.addCustomToken(customTokenInput)
}

await wallet.changeEnabledTokenIds([...wallet.enabledTokenIds, newTokenId])
logActivity(`Add Custom Token: ${account.username} -- ${getWalletName(wallet)} -- ${wallet.type} -- ${newTokenId} -- ${currencyCode} -- ${decimals}`)
navigation.goBack()
} else {
await currencyConfig.removeCustomToken(newTokenId)
}
navigation.goBack()
}
})

Expand Down Expand Up @@ -217,7 +224,7 @@ function EditTokenSceneComponent(props: Props) {
onChangeText={value =>
setLocation(location => {
const out = new Map(location)
out.set(item.key, value)
out.set(item.key, value.replace(/\s/g, ''))
return out
})
}
Expand Down
2 changes: 0 additions & 2 deletions src/locales/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ const strings = {

warning_token_code_override_2s:
'The entered contract address differs from the contract address of built-in token %1$s. Please proceed with caution and verify the contract is legitimate as use of this token can result in loss of funds. If you have questions about this feature or contract please contact %2$s.',
warning_token_contract_override_3s:
'The entered token %1$s exists as a built-in token %2$s with the same contract address. Please proceed with caution and verify the contract is legitimate as use of this token can result in loss of funds. If you have questions about this feature please contact %3$s.',
warning_token_exists_1s: 'The entered token already exists as a built-in token %1$s',
warning_uk_risk: `Don't invest unless you're prepared to lose all the money you invest. This is a high-risk investment and you should not expect to be protected if something goes wrong. Take 2 min to learn more.`,

Expand Down
1 change: 0 additions & 1 deletion src/locales/strings/enUS.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
"warning_scam_message_no_1s": "Great, if you ever have any questions, please reach out to our support team at %1$s.",
"warning_scam_message_yes_1s": "Please proceed with caution! Assistance with account creation has the potential for fraud. Users should never share passwords or private keys. Social media and chat platforms have been involved in attacks. Do not send cryptocurrency to strangers. If you believe you’re being taken advantage of, please contact our support team at %1$s.",
"warning_token_code_override_2s": "The entered contract address differs from the contract address of built-in token %1$s. Please proceed with caution and verify the contract is legitimate as use of this token can result in loss of funds. If you have questions about this feature or contract please contact %2$s.",
"warning_token_contract_override_3s": "The entered token %1$s exists as a built-in token %2$s with the same contract address. Please proceed with caution and verify the contract is legitimate as use of this token can result in loss of funds. If you have questions about this feature please contact %3$s.",
"warning_token_exists_1s": "The entered token already exists as a built-in token %1$s",
"warning_uk_risk": "Don't invest unless you're prepared to lose all the money you invest. This is a high-risk investment and you should not expect to be protected if something goes wrong. Take 2 min to learn more.",
"alert_dropdown_alert": "Alert! ",
Expand Down