Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make specific warnings for adding custom asset #3478

Merged
merged 6 commits into from
Jun 20, 2023
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
10 changes: 7 additions & 3 deletions ui/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,13 @@
"asset.label.balance": "Balance",
"asset.label.symbol": "Name",
"networkSelect.title": "Select Network",
"warning.alreadyExists.title": "Asset already exists, you will see it once your balance is over 0",
"warning.alreadyExists.desc": "If you still have issues seeing an asset, turn off “Hide asset balances under 2$” from Settings",
"warning.dust.title": "Asset balance is under <$2, you wil see it once your balance is over $2",
"warning.alreadyExists.title": "Asset already exists",
"warning.alreadyExists.desc": {
"dust": "Your balance is under {{sign}}{{amount}}. You will see it once you turn off “{{settings}}” in Settings.",
"noBalance": "Your balance is 0, you will see it once your balance is over {{sign}}{{amount}}.",
"visibility": "You should see it in your asset list."
},
"warning.dust.title": "Asset balance is under {{sign}}{{amount}}, you wil see it once your balance is over {{sign}}{{amount}}",
"error.invalidToken": "Invalid contract address",
"submit": "Add asset",
"snackbar.success": "Asset added successfully",
Expand Down
7 changes: 5 additions & 2 deletions ui/pages/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import {
toggleShowUnverifiedAssets,
} from "@tallyho/tally-background/redux-slices/ui"
import { useHistory } from "react-router-dom"
import { selectMainCurrencySign } from "@tallyho/tally-background/redux-slices/selectors"
import {
selectMainCurrencySign,
userValueDustThreshold,
} from "@tallyho/tally-background/redux-slices/selectors"
import {
FeatureFlags,
isEnabled,
Expand Down Expand Up @@ -156,7 +159,7 @@ export default function Settings(): ReactElement {

const hideSmallAssetBalance = {
title: t("settings.hideSmallAssetBalance", {
amount: 2,
amount: userValueDustThreshold,
sign: mainCurrencySign,
}),
component: () => (
Expand Down
30 changes: 28 additions & 2 deletions ui/pages/Settings/SettingsAddCustomAsset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from "@tallyho/tally-background/redux-slices/assets"
import {
selectCurrentNetwork,
selectMainCurrencySign,
userValueDustThreshold,
} from "@tallyho/tally-background/redux-slices/selectors"
import { selectEVMNetworks } from "@tallyho/tally-background/redux-slices/selectors/networks"
Expand Down Expand Up @@ -96,6 +97,7 @@ export default function SettingsAddCustomAsset(): ReactElement {
const currentNetwork = useBackgroundSelector(selectCurrentNetwork)
const allNetworks = useBackgroundSelector(selectEVMNetworks)
const showTestNetworks = useBackgroundSelector(selectShowTestNetworks)
const mainCurrencySign = useBackgroundSelector(selectMainCurrencySign)

const networks = allNetworks.filter(
(network) =>
Expand Down Expand Up @@ -178,9 +180,32 @@ export default function SettingsAddCustomAsset(): ReactElement {
const hideDustEnabled = useBackgroundSelector(selectHideDust)
const showWarningAboutDust =
hideDustEnabled &&
assetData?.mainCurrencyAmount !== 0 &&
assetData?.mainCurrencyAmount !== undefined &&
assetData?.mainCurrencyAmount < userValueDustThreshold

const warningOptions = {
amount: userValueDustThreshold,
sign: mainCurrencySign,
}

const renderWarningText = () => {
if (showWarningAboutDust) {
return t("warning.alreadyExists.desc.dust", {
...warningOptions,
settings: sharedT("settings.hideSmallAssetBalance", warningOptions),
})
}

// showWarningAboutNoBalance
if (assetData?.mainCurrencyAmount === 0) {
return t("warning.alreadyExists.desc.noBalance", warningOptions)
}

// showWarningAboutVisibility
return t("warning.alreadyExists.desc.visibility")
}

return (
<div className="standard_width_padded wrapper">
<SharedPageHeader withoutBackText>{t(`title`)}</SharedPageHeader>
Expand Down Expand Up @@ -370,7 +395,7 @@ export default function SettingsAddCustomAsset(): ReactElement {
/>
<div className="alert_content">
<div className="title">{t("warning.alreadyExists.title")}</div>
<div className="desc">{t("warning.alreadyExists.desc")}</div>
<div className="desc">{renderWarningText()}</div>
</div>
</div>
) : (
Expand All @@ -385,7 +410,7 @@ export default function SettingsAddCustomAsset(): ReactElement {
/>
<div className="alert_content">
<div className="title" style={{ color: "var(--attention)" }}>
{t("warning.dust.title")}
{t("warning.dust.title", warningOptions)}
</div>
</div>
</div>
Expand All @@ -398,6 +423,7 @@ export default function SettingsAddCustomAsset(): ReactElement {
background: var(--green-120);
border-radius: 8px;
padding: 8px;
padding-right: 24px;
display: flex;
gap: 8px;
}
Expand Down