Skip to content

Commit 275a200

Browse files
VelenirW3stside
andauthored
Hotfix/1.0.5 (gnosis#1184)
* Disable tokens list (gnosis#1168) * add disabledTokens to config * parse DISABLED_TOKEN_MAPS * allow to filter against disabledTokens in useTokenBalances * filter out disabledTokens where appropriate * pass disabledTokens to /wallet * override data of disabledTokens * don't show deposit + button for disabledTokens * show warning for disabledTokens * Revert "override data of disabledTokens" This reverts commit a1edff3. * Revert "pass disabledTokens to /wallet" This reverts commit 13112aa. * Revert "filter out disabledTokens where appropriate" This reverts commit 7d455e2. * better text * rename alert icon * override disabled tokens in TokenListApi, closer to the metal * simplify excluding deprecated in useTokenList * extend types * switch to params object for useTokenList * add comments * disable Enable button for deprecated tokens * make deprecated logo opaque * show deprecated in ManageTokens * add TokenSymbol component * fix wrong name * add tests for CONFIG.disabledTokens * fix build * opaque -> faded * more override reasons * disable token for any overrideReason * disable SNX-old * disable PAXG * disable aTokens * Update config-default.yaml Co-authored-by: David <[email protected]> * simplify overrideReason * add STA token * Update config-default.yaml Co-authored-by: David <[email protected]> * better wording Co-authored-by: David <[email protected]> * * * Add link ⚠️ (gnosis#1186) * add disabledTokens[].url * wrap WarningImg in anchor when appropriate * pass tokenOverride.url to TokenSymbol * fix Toggle swallowing clicks on WarningImg in ManageTokens * url -> warningUrl * consider never expired orders (gnosis#1187) Co-authored-by: David <[email protected]>
1 parent be6a885 commit 275a200

File tree

21 files changed

+298
-48
lines changed

21 files changed

+298
-48
lines changed

config-default.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,48 @@ defaultProviderConfig:
6161
# Wallet Connect
6262
walletConnect:
6363
bridge: 'wss://safe-walletconnect.gnosis.io/'
64+
65+
# tokens that aren't allowed to be traded nor deposited
66+
disabledTokens:
67+
1: # Mainnet
68+
- address: '0x57Ab1E02fEE23774580C119740129eAC7081e9D3'
69+
name: Synthetics sUSD (deprecated)
70+
symbol: sUSD-old
71+
description: This token is disabled for trading and depositing. sUSD will be deprecated and replaced by another token at the end of July 2020. Go to https://www.synthetix.io for more information
72+
reason: DEPRECATED
73+
url: https://docs.synthetix.io/integrations/guide/#proxy-deprecation
74+
75+
- address: '0xC011A72400E58ecD99Ee497CF89E3775d4bd732F'
76+
name: Synthetix Network Token (deprecated)
77+
symbol: SNX-old
78+
description: This token is disabled for trading and depositing. SNX will be deprecated and replaced by another token at the end of July 2020. Go to https://www.synthetix.io for more information
79+
reason: DEPRECATED
80+
url: https://docs.synthetix.io/integrations/guide/#proxy-deprecation
81+
82+
- address: '0x45804880De22913dAFE09f4980848ECE6EcbAf78'
83+
name: Paxos Gold
84+
symbol: PAXG
85+
86+
- address: '0xa7DE087329BFcda5639247F96140f9DAbe3DeED1'
87+
name: Statera
88+
symbol: STA
89+
90+
# aTokens:
91+
- address: '0x7D2D3688Df45Ce7C552E19c27e007673da9204B8'
92+
- address: '0xA64BD6C70Cb9051F6A9ba1F163Fdc07E0DfB5F84'
93+
- address: '0x71fc860F7D3A592A4a98740e39dB31d25db65ae8'
94+
- address: '0x9bA00D6856a4eDF4665BcA2C2309936572473B7E'
95+
- address: '0x3a3A65aAb0dd2A17E3F1947bA16138cd37d08c04'
96+
- address: '0xfC1E690f61EFd961294b3e1Ce3313fBD8aa4f85d'
97+
- address: '0x9D91BE44C06d373a8a226E1f3b146956083803eB'
98+
- address: '0x4DA9b813057D04BAef4e5800E36083717b4a0341'
99+
- address: '0x328C4c80BC7aCa0834Db37e6600A6c49E12Da4DE'
100+
- address: '0x7deB5e830be29F91E298ba5FF1356BB7f8146998'
101+
- address: '0xE1BA0FB44CCb0D11b80F92f4f8Ed94CA3fF51D00'
102+
- address: '0x6ee0f7bb50a54ab5253da0667b0dc2ee526c30a8'
103+
- address: '0x625aE63000f46200499120B906716420bd059240'
104+
- address: '0x6FCE4A401B6B80ACe52baAefE4421Bd188e76F6f'
105+
- address: '0x71010A9D003445aC60C4e6A7017c1E89A477B438'
106+
- address: '0x6Fb0855c404E09c47C3fBCA25f08d4E41f9F062f'
107+
- address: '0xFC4B8ED459e00e5400be803A9BB3954234FD50e3'
108+
4: [] # Rinkeby

src/api/tokenList/TokenListApi.ts

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@ import { TokenDetails } from 'types'
22
import { getTokensByNetwork } from './tokenList'
33
import { logDebug } from 'utils'
44
import GenericSubscriptions, { SubscriptionsInterface } from './Subscriptions'
5+
import { DISABLED_TOKEN_MAPS } from 'const'
6+
7+
const addOverrideToDisabledTokens = (networkId: number) => (token: TokenDetails): TokenDetails => {
8+
const tokenOverride = DISABLED_TOKEN_MAPS[networkId]?.[token.address]
9+
if (tokenOverride) {
10+
token.override = tokenOverride
11+
token.disabled = true
12+
// override only keys present in both token and tokenOverride
13+
Object.keys(token).forEach(key => {
14+
if (tokenOverride[key] !== undefined) token[key] = tokenOverride[key]
15+
})
16+
}
17+
18+
return token
19+
}
520

621
export interface TokenList extends SubscriptionsInterface<TokenDetails[]> {
722
getTokens: (networkId: number) => TokenDetails[]
@@ -63,7 +78,10 @@ export class TokenListApiImpl extends GenericSubscriptions<TokenDetails[]> imple
6378
// then default list
6479
getTokensByNetwork(networkId),
6580
)
66-
this._tokensByNetwork[networkId] = tokenList
81+
this._tokensByNetwork[networkId] = TokenListApiImpl.extendTokensInList(
82+
tokenList,
83+
addOverrideToDisabledTokens(networkId),
84+
)
6785

6886
tokenList.forEach(({ address }) => {
6987
this._tokenAddressNetworkSet.add(
@@ -96,6 +114,13 @@ export class TokenListApiImpl extends GenericSubscriptions<TokenDetails[]> imple
96114
return result
97115
}
98116

117+
private static extendTokensInList(
118+
list: TokenDetails[],
119+
extensionFunction: (token: TokenDetails) => TokenDetails,
120+
): TokenDetails[] {
121+
return list.map(extensionFunction)
122+
}
123+
99124
private static constructAddressNetworkKey({ tokenAddress, networkId }: HasTokenParams): string {
100125
return tokenAddress.toLowerCase() + '|' + networkId
101126
}
@@ -122,7 +147,12 @@ export class TokenListApiImpl extends GenericSubscriptions<TokenDetails[]> imple
122147
})
123148
if (addedTokens.length === 0) return
124149

125-
this._tokensByNetwork[networkId] = TokenListApiImpl.mergeTokenLists(this._tokensByNetwork[networkId], addedTokens)
150+
const extendedTokens = TokenListApiImpl.extendTokensInList(addedTokens, addOverrideToDisabledTokens(networkId))
151+
152+
this._tokensByNetwork[networkId] = TokenListApiImpl.mergeTokenLists(
153+
this._tokensByNetwork[networkId],
154+
extendedTokens,
155+
)
126156
this.persistNewUserTokens(addedTokens, networkId)
127157

128158
this.triggerSubscriptions(this._tokensByNetwork[networkId])
@@ -148,8 +178,11 @@ export class TokenListApiImpl extends GenericSubscriptions<TokenDetails[]> imple
148178
public persistTokens({ networkId, tokenList }: PersistTokensParams): void {
149179
// fetch list of user added tokens
150180
const userAddedTokens = this.loadTokenList(networkId, 'user')
181+
182+
const extendedTokens = TokenListApiImpl.extendTokensInList(tokenList, addOverrideToDisabledTokens(networkId))
183+
151184
// update copy in memory, appending anything user might have added
152-
this._tokensByNetwork[networkId] = TokenListApiImpl.mergeTokenLists(tokenList, userAddedTokens)
185+
this._tokensByNetwork[networkId] = TokenListApiImpl.mergeTokenLists(extendedTokens, userAddedTokens)
153186

154187
// update copy in local storage for service tokens
155188
const serviceStorageKey = TokenListApiImpl.getStorageKey(networkId, 'service')
File renamed without changes.

src/components/DepositWidget/Row.tsx

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { TokenRow, RowClaimButton, RowClaimSpan } from 'components/DepositWidget
2323
// Hooks and reducers
2424
import useNoScroll from 'hooks/useNoScroll'
2525
import { TokenLocalState } from 'reducers-actions'
26+
import { TokenSymbol } from 'components/TokenSymbol'
2627

2728
export interface RowProps extends Record<keyof TokenLocalState, boolean> {
2829
ethBalance: BN | null
@@ -66,6 +67,8 @@ export const Row: React.FC<RowProps> = (props: RowProps) => {
6667
claimable,
6768
walletBalance,
6869
enabled: tokenEnabled,
70+
override,
71+
disabled: tokenDisabled,
6972
} = tokenBalances
7073

7174
const [visibleForm, showForm] = useState<'deposit' | 'withdraw' | void>()
@@ -91,9 +94,9 @@ export const Row: React.FC<RowProps> = (props: RowProps) => {
9194
<>
9295
<TokenRow data-address={address} className={className} data-address-mainnet={addressMainnet}>
9396
<td data-label="Token">
94-
<TokenImg src={image} alt={name} />
97+
<TokenImg src={image} alt={name} faded={tokenDisabled} />
9598
<div>
96-
<b>{symbol}</b>
99+
<TokenSymbol symbol={symbol} warning={override?.description} warningUrl={override?.url} />
97100
{name}
98101
</div>
99102
</td>
@@ -147,29 +150,30 @@ export const Row: React.FC<RowProps> = (props: RowProps) => {
147150
)}
148151
</td>
149152
<td data-label="Actions">
150-
{enabled || tokenEnabled ? (
151-
<button
152-
type="button"
153-
className="withdrawToken"
154-
onClick={(): void => showForm('deposit')}
155-
disabled={isDepositFormVisible}
156-
>
157-
<PlusSVG />
158-
</button>
159-
) : (
160-
<>
161-
<button type="button" className="enableToken" onClick={onEnableToken} disabled={enabling}>
162-
{enabling ? (
163-
<>
164-
<Spinner />
165-
Enabling
166-
</>
167-
) : (
168-
<>Enable Deposit</>
169-
)}
153+
{!tokenDisabled &&
154+
(enabled || tokenEnabled ? (
155+
<button
156+
type="button"
157+
className="withdrawToken"
158+
onClick={(): void => showForm('deposit')}
159+
disabled={isDepositFormVisible}
160+
>
161+
<PlusSVG />
170162
</button>
171-
</>
172-
)}
163+
) : (
164+
<>
165+
<button type="button" className="enableToken" onClick={onEnableToken} disabled={enabling}>
166+
{enabling ? (
167+
<>
168+
<Spinner />
169+
Enabling
170+
</>
171+
) : (
172+
<>Enable Deposit</>
173+
)}
174+
</button>
175+
</>
176+
))}
173177
{!totalExchangeBalance.isZero() && (
174178
<button
175179
type="button"

src/components/DepositWidget/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ const BalancesDisplayMemoed = React.memo(BalancesDisplay)
477477

478478
const DepositWidget: React.FC = () => {
479479
const { ethBalance } = useEthBalances()
480+
// get all token balances, including deprecated
480481
const { balances, error } = useTokenBalances()
481482

482483
const { requestWithdrawToken, ...restActions } = useRowActions({ balances })

src/components/OrderBookBtn.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ function onChangeToken(params: {
114114
export const OrderBookBtn: React.FC<OrderBookBtnProps> = (props: OrderBookBtnProps) => {
115115
const { baseToken: baseTokenDefault, quoteToken: quoteTokenDefault, label, className } = props
116116
const { networkIdOrDefault: networkId } = useWalletConnection()
117-
const tokenList = useTokenList(networkId)
117+
// get all tokens
118+
const tokenList = useTokenList({ networkId })
118119
const [baseToken, setBaseToken] = useSafeState<TokenDetails>(baseTokenDefault)
119120
const [quoteToken, setQuoteToken] = useSafeState<TokenDetails>(quoteTokenDefault)
120121
const networkDescription = networkId !== Network.Mainnet ? ` (${getNetworkFromId(networkId)})` : ''

src/components/OrdersWidget/OrderRow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { getTokenFromExchangeById } from 'services'
88

99
// assets
1010
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
11-
import lowBalanceIcon from 'assets/img/lowBalance.svg'
11+
import alertIcon from 'assets/img/alert.svg'
1212
import { faChevronUp, faChevronDown } from '@fortawesome/free-solid-svg-icons'
1313

1414
// components
@@ -262,7 +262,7 @@ const Status: React.FC<Pick<Props, 'order' | 'isOverBalance' | 'transactionHash'
262262
<br />
263263
<span className="lowBalance">
264264
low balance
265-
<img src={lowBalanceIcon} />
265+
<img src={alertIcon} />
266266
</span>
267267
</>
268268
)}

src/components/PoolingWidget/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ const PoolingInterface: React.FC = () => {
145145

146146
const { networkId, networkIdOrDefault, userAddress } = useWalletConnection()
147147
// Get all the tokens for the current network
148-
const tokenList = useTokenList(networkIdOrDefault)
148+
const tokenList = useTokenList({ networkId: networkIdOrDefault })
149149

150150
const tokens = useMemo(() => {
151151
return (

src/components/TokenImg.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ function _loadFallbackTokenImage(event: React.SyntheticEvent<HTMLImageElement>):
77
image.src = unknownTokenImg
88
}
99

10-
const TokenImg = styled.img.attrs(() => ({ onError: _loadFallbackTokenImage }))`
10+
interface TokenImgProps {
11+
faded?: boolean
12+
}
13+
14+
const TokenImg = styled.img.attrs(() => ({ onError: _loadFallbackTokenImage }))<TokenImgProps>`
1115
width: 2.8rem;
1216
height: 2.8rem;
1317
border-radius: 3.6rem;
1418
object-fit: contain;
1519
margin: 0 1rem 0 0;
1620
background-color: white;
1721
padding: 2px;
22+
opacity: ${(props): number => (props.faded ? 0.4 : 1)};
1823
`
1924

2025
export default TokenImg

src/components/TokenOptionItem.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { TokenImgWrapper } from 'components/TokenImg'
1818
// hooks
1919
import useSafeState from 'hooks/useSafeState'
2020
import { UseAddTokenModalResult } from 'hooks/useBetterAddTokenModal'
21+
import { TokenSymbol } from './TokenSymbol'
2122

2223
const OptionItemWrapper = styled.div`
2324
display: flex;
@@ -73,18 +74,30 @@ interface OptionItemProps {
7374
image?: string
7475
name?: string
7576
symbol?: string
77+
faded?: boolean
78+
warning?: string
79+
warningUrl?: string
7680
}
7781

7882
// generic component to display token
7983
// with custom children option
80-
export const OptionItem: React.FC<OptionItemProps> = ({ image, name, symbol, children }) => {
84+
export const OptionItem: React.FC<OptionItemProps> = ({
85+
image,
86+
name,
87+
symbol,
88+
children,
89+
faded,
90+
warning,
91+
warningUrl,
92+
}) => {
8193
return (
8294
<OptionItemWrapper>
83-
<TokenImgWrapper src={image} alt={name} />
95+
<TokenImgWrapper src={image} alt={name} faded={faded} />
96+
8497
<div className="tokenDetails">
8598
<div className="tokenName">
8699
<div>
87-
<strong>{symbol}</strong>
100+
<TokenSymbol symbol={symbol} warning={warning} warningUrl={warningUrl} />
88101
</div>
89102
<div>{name}</div>
90103
</div>

0 commit comments

Comments
 (0)