-
Notifications
You must be signed in to change notification settings - Fork 101
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
feat(tokens): tokens and token lists library #3189
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments.
Obviously did not test ;)
libs/tokens/src/hooks/tokens/unsupported/useIsUnsupportedToken.ts
Outdated
Show resolved
Hide resolved
libs/tokens/src/hooks/tokens/unsupported/useIsUnsupportedTokens.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is remarkable! This is really a great job.
I need to still review it a bit more, but here are some small initial comments.
The first impression of the lib API and state looks great to me!
|
||
// Types | ||
export * from './types' | ||
export type { TokensByAddress, TokensBySymbol } from './state/tokens/allTokensAtom' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I would say, these types belong to th types.ts
if they are part of the interface.
Then, it just happens that you actually also use them in the atom because in this case you made the persistance to match the interface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
… refactor/tokens-lib
👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎ This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored. |
… refactor/tokens-lib
…cowswap into refactor/tokens-lib
* feat(tokens): tokens list, search and management ui (#3191) * refactor(tokens): remove excessive types and consts (#3196) * refactor(tokens): integrate TokenLogo component (#3197) * refactor(tokens): wire up components to new hooks (#3198) * refactor(tokens): remove Uniswap currency entities usage (#3199) * refactor(tokens): use new tokens UI and logic by default (#3200) * fix(tokens): fix e2e tests for tokens updates (#3193) * refactor(tokens): remove legacy code (#3194) * fix(tokens): fix tokens list loading state (#3201)
… refactor/tokens-lib # Conflicts: # apps/cowswap-frontend/src/common/pure/CurrencyLogo/index.tsx # apps/cowswap-frontend/src/common/updaters/ListsUpdater.ts # apps/cowswap-frontend/src/legacy/components/SearchModal/CommonBases/CommonBasesMod.tsx # apps/cowswap-frontend/src/legacy/components/SearchModal/CommonBases/index.ts # apps/cowswap-frontend/src/modules/tokensList/pure/TokenLogo/index.tsx # apps/cowswap-frontend/src/modules/tokensList/pure/TokenSourceTitle/index.tsx # apps/widget-configurator/src/app/configurator/index.tsx # libs/tokens/src/utils/validateTokenList.ts # package.json # yarn.lock
New and removed dependencies detected. Learn more about Socket for GitHub ↗︎
🚮 Removed packages: @types/[email protected], @uniswap/[email protected], [email protected], [email protected], [email protected] |
… refactor/tokens-lib # Conflicts: # apps/cowswap-frontend/src/modules/swap/containers/SwapWidget/index.tsx
Summary
The new
tokens
lib serves to provide a relevant list of tokens.Globally, there are two groups of entities: lists and tokens.
libs/tokens/src/const/tokensList.json
, it contains urls/ensNames of lists withpriority
andenabledByDefault
flags. The content of the json file is stored intodefaultListsSourcesAtom
.There is also
userAddedListsSourcesAtom
with the same data added by user.It looks like:
TokensListsUpdater
fetches lists sources once in 6 hours and stores results intolistsStatesByChainAtom
.Example of the state inside:
To detect if a list is enabled we check
isEnabled
value in the list state, if it's not set, then we fallback toenabledByDefault
in the list source. See more inlistsEnabledStateAtom
Now we split tokens into two groups: active and inactive, depending on is a list enabled (see the previous point). In the "Select a token" modal we display only tokens from active lists by default. We use tokens from inactive lists only to search for a token. Splitting into active/inactive is concentrated in
tokensStateAtom
.We also have user-added tokens and favorite tokens. Those entities are represented as CRUD atoms:
userAddedTokensAtom
andfavouriteTokensAtom
. We add then into general active tokens list as well (activeTokensAtom
).The lib also provides a component to display a token logo -
TokenLogo
. The main goal of the component is to find a valid URL for a logo. A token from some list might have an invalid URL or even don't have it, in this case we try other sources of images. See details below.One of the most complex things in the lib is
useSearchToken
. The hook is searching into 4 sources: active lists, inactive lists, external API, and blockchain.useSWR
is widely used inside to cache search results.Any entity collection contains sets of data per network. I've chosen
jotai
style to derive data for a current network. It has one huge advantage - caching. If we use react hooks to derive data for a current network, it means we will calculate data on every subscription. On the other side,jotai
calculates it once. To not spoil the lib dependencies I've addedenvironmentAtom
that actually contains only one property -chainId
. The value is persisted fromTokensListsUpdater
.Details
1.
TokensListsUpdater
2.
TokenLogo
3.
Lists and tokens state
4.
Token search
To Test
Please, test everything in #3201