-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tokens): tokens and token lists library
- Loading branch information
Showing
62 changed files
with
1,848 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"@nx/react/babel", | ||
{ | ||
"runtime": "automatic", | ||
"useBuiltIns": "usage" | ||
} | ||
] | ||
], | ||
"plugins": [ | ||
[ | ||
"styled-components", | ||
{ | ||
"pure": true, | ||
"ssr": true | ||
} | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"extends": ["plugin:@nx/react", "../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Tokens |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* eslint-disable */ | ||
export default { | ||
displayName: 'tokens', | ||
preset: '../../jest.preset.js', | ||
transform: { | ||
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest', | ||
'^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nx/react/babel'] }], | ||
}, | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], | ||
coverageDirectory: '../../coverage/libs/tokens', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "@cowprotocol/tokens", | ||
"version": "0.0.1", | ||
"main": "./index.js", | ||
"types": "./index.d.ts", | ||
"exports": { | ||
".": { | ||
"import": "./index.mjs", | ||
"require": "./index.js" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "@cowprotocol/tokens", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "libs/tokens/src", | ||
"projectType": "library", | ||
"tags": [], | ||
"targets": { | ||
"lint": { | ||
"executor": "@nx/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": ["libs/tokens/**/*.{ts,tsx,js,jsx}"] | ||
} | ||
}, | ||
"build": { | ||
"executor": "@nx/vite:build", | ||
"outputs": ["{options.outputPath}"], | ||
"defaultConfiguration": "production", | ||
"options": { | ||
"outputPath": "dist/libs/tokens" | ||
}, | ||
"configurations": { | ||
"development": { | ||
"mode": "development" | ||
}, | ||
"production": { | ||
"mode": "production" | ||
} | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nx/jest:jest", | ||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"], | ||
"options": { | ||
"jestConfig": "libs/tokens/jest.config.ts", | ||
"passWithNoTests": true | ||
}, | ||
"configurations": { | ||
"ci": { | ||
"ci": true, | ||
"codeCoverage": true | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
{ | ||
"1": [ | ||
{ | ||
"id": "hc_zMahDEXc_WMKgPAUpK", | ||
"priority": 1, | ||
"enabledByDefault": true, | ||
"url": "https://files.cow.fi/tokens/CowSwap.json" | ||
}, | ||
{ | ||
"id": "yi4K5DrkWkF3oiWweRjt3", | ||
"priority": 2, | ||
"enabledByDefault": true, | ||
"url": "https://files.cow.fi/tokens/CoinGecko.json" | ||
}, | ||
{ | ||
"id": "uJcgDR4A3MLQTrDsO34bA", | ||
"priority": 3, | ||
"url": "https://raw.githubusercontent.com/compound-finance/token-list/master/compound.tokenlist.json" | ||
}, | ||
{ | ||
"id": "ePv0T2u5t0omW7HjPxGCL", | ||
"priority": 4, | ||
"ensName": "tokenlist.aave.eth" | ||
}, | ||
{ | ||
"id": "vcO-K1VshU97uUeao5p_i", | ||
"priority": 5, | ||
"ensName": "synths.snx.eth" | ||
}, | ||
{ | ||
"id": "pBJ4ZL5jeZ0DcLw4S-_85", | ||
"priority": 6, | ||
"ensName": "wrapped.tokensoft.eth" | ||
}, | ||
{ | ||
"id": "4nKiWPc0hM6NgkZgTUnsy", | ||
"priority": 7, | ||
"url": "https://raw.githubusercontent.com/SetProtocol/uniswap-tokenlist/main/set.tokenlist.json" | ||
}, | ||
{ | ||
"id": "5anQfdMTp5WyI2jklNvFB", | ||
"priority": 8, | ||
"url": "https://raw.githubusercontent.com/opynfinance/opyn-tokenlist/master/opyn-squeeth-tokenlist.json" | ||
}, | ||
{ | ||
"id": "YBalvtWm1YVzQoe8J2AJa", | ||
"priority": 9, | ||
"url": "https://app.tryroll.com/tokens.json" | ||
}, | ||
{ | ||
"id": "Pl-AdOGqGki43XDf7EoGV", | ||
"priority": 10, | ||
"ensName": "defi.cmc.eth" | ||
}, | ||
{ | ||
"id": "JXGSqoOJDDY9hsY0Zn-Ue", | ||
"priority": 11, | ||
"ensName": "stablecoin.cmc.eth" | ||
}, | ||
{ | ||
"id": "bffPi82n3c4zBzAbUQiV7", | ||
"priority": 12, | ||
"ensName": "t2crtokens.eth" | ||
} | ||
], | ||
"5": [ | ||
{ | ||
"id": "VZ--hetNymtoeZ5QUVhRT", | ||
"priority": 1, | ||
"enabledByDefault": true, | ||
"url": "https://raw.githubusercontent.com/cowprotocol/token-lists/main/src/public/CowSwapGoerli.json" | ||
}, | ||
{ | ||
"id": "uJcgDR4A3MLQTrDsO34bA", | ||
"priority": 2, | ||
"url": "https://raw.githubusercontent.com/compound-finance/token-list/master/compound.tokenlist.json" | ||
} | ||
], | ||
"100": [ | ||
{ | ||
"id": "hc_zMahDEXc_WMKgPAUpK", | ||
"priority": 1, | ||
"enabledByDefault": true, | ||
"url": "https://files.cow.fi/tokens/CowSwap.json" | ||
}, | ||
{ | ||
"id": "hMVOQpr3d-b-lCpYDDyIM", | ||
"priority": 2, | ||
"enabledByDefault": true, | ||
"url": "https://tokens.honeyswap.org" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { TokenListsByNetwork } from '../types' | ||
import tokensList from './tokensList.json' | ||
|
||
export const DEFAULT_TOKENS_LISTS: TokenListsByNetwork = tokensList |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { useAtomValue } from 'jotai' | ||
import { activeTokenListsMapAtom } from '../state/tokenLists/tokenListsStateAtom' | ||
|
||
export function useActiveTokenListsIds() { | ||
return useAtomValue(activeTokenListsMapAtom) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { useSetAtom } from 'jotai' | ||
import { addTokenListAtom } from '../state/tokenLists/tokenListsActionsAtom' | ||
|
||
export function useAddCustomTokenLists() { | ||
return useSetAtom(addTokenListAtom) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { useSetAtom } from 'jotai' | ||
import { addUnsupportedTokenAtom } from '../state/tokens/unsupportedTokensAtom' | ||
|
||
export function useAddUnsupportedToken() { | ||
return useSetAtom(addUnsupportedTokenAtom) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { useAtomValue } from 'jotai' | ||
import { allTokenListsInfoAtom } from '../state/tokenLists/tokenListsStateAtom' | ||
import { TokenListInfo } from '../types' | ||
|
||
export function useAllTokenListsInfo(): TokenListInfo[] { | ||
return useAtomValue(allTokenListsInfoAtom) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { useAtomValue } from 'jotai' | ||
import { activeTokensAtom } from '../state/tokens/tokensAtom' | ||
|
||
import { TokenWithLogo } from '@cowprotocol/common-const' | ||
|
||
export function useAllTokens(): TokenWithLogo[] { | ||
return useAtomValue(activeTokensAtom) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useAtomValue } from 'jotai' | ||
import { useCallback } from 'react' | ||
|
||
import { isAddress } from '@cowprotocol/common-utils' | ||
import { tokensBySymbolAtom } from '../state/tokens/tokensAtom' | ||
|
||
export function useAreThereTokensWithSameSymbol(): (tokenAddressOrSymbol: string | null | undefined) => boolean { | ||
const tokensBySymbol = useAtomValue(tokensBySymbolAtom) | ||
|
||
return useCallback( | ||
(tokenAddressOrSymbol: string | null | undefined) => { | ||
if (!tokenAddressOrSymbol || isAddress(tokenAddressOrSymbol)) return false | ||
|
||
return tokensBySymbol[tokenAddressOrSymbol.toLowerCase()]?.length > 1 | ||
}, | ||
[tokensBySymbol] | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { useAtomValue } from 'jotai' | ||
import { favouriteTokensListAtom } from '../state/tokens/favouriteTokensAtom' | ||
import { TokenWithLogo } from '@cowprotocol/common-const' | ||
|
||
export function useFavouriteTokens(): TokenWithLogo[] { | ||
return useAtomValue(favouriteTokensListAtom) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { TokenWithLogo } from '@cowprotocol/common-const' | ||
import { useSetAtom } from 'jotai' | ||
import { addUserTokenAtom } from '../state/tokens/userAddedTokensAtom' | ||
|
||
export function useImportTokenCallback(): (tokens: TokenWithLogo[]) => void { | ||
return useSetAtom(addUserTokenAtom) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Currency } from '@uniswap/sdk-core' | ||
import { useIsUnsupportedToken } from './useIsUnsupportedToken' | ||
|
||
export function useIsTradeUnsupported( | ||
inputCurrency: Currency | null | undefined, | ||
outputCurrency: Currency | null | undefined | ||
): boolean { | ||
const isUnsupportedToken = useIsUnsupportedToken() | ||
const isInputCurrencyUnsupported = inputCurrency?.isNative ? false : !!isUnsupportedToken(inputCurrency?.address) | ||
const isOutputCurrencyUnsupported = outputCurrency?.isNative ? false : !!isUnsupportedToken(outputCurrency?.address) | ||
|
||
return isInputCurrencyUnsupported || isOutputCurrencyUnsupported | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { useUnsupportedTokens } from './useUnsupportedTokens' | ||
import { useCallback } from 'react' | ||
|
||
export function useIsUnsupportedToken() { | ||
const unsupportedTokens = useUnsupportedTokens() | ||
|
||
return useCallback( | ||
(address?: string) => { | ||
const state = address && unsupportedTokens[address.toLowerCase()] | ||
|
||
if (state) { | ||
return { | ||
...state, | ||
address, | ||
} | ||
} | ||
return false | ||
}, | ||
[unsupportedTokens] | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useUnsupportedTokens } from './useUnsupportedTokens' | ||
import { useCallback } from 'react' | ||
|
||
export function useIsUnsupportedTokens() { | ||
const unsupportedTokens = useUnsupportedTokens() | ||
|
||
return useCallback( | ||
({ sellToken, buyToken }: { sellToken: string | null | undefined; buyToken: string | null | undefined }) => { | ||
if (!unsupportedTokens) return false | ||
|
||
return !!( | ||
(sellToken && unsupportedTokens[sellToken.toLowerCase()]) || | ||
(buyToken && unsupportedTokens[buyToken.toLowerCase()]) | ||
) | ||
}, | ||
[unsupportedTokens] | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { TokenWithLogo } from '@cowprotocol/common-const' | ||
import { useSetAtom } from 'jotai' | ||
import { removeUserTokenAtom } from '../state/tokens/userAddedTokensAtom' | ||
|
||
export function useRemoveTokenCallback(): (token: TokenWithLogo) => void { | ||
const removeUserToken = useSetAtom(removeUserTokenAtom) | ||
|
||
return (token: TokenWithLogo) => { | ||
removeUserToken(token) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { useSetAtom } from 'jotai' | ||
import { removeTokenListAtom } from '../state/tokenLists/tokenListsActionsAtom' | ||
|
||
export function useRemoveTokenList() { | ||
return useSetAtom(removeTokenListAtom) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { useSetAtom } from 'jotai' | ||
import { removeUnsupportedTokenAtom } from '../state/tokens/unsupportedTokensAtom' | ||
|
||
export function useRemoveUnsupportedToken() { | ||
return useSetAtom(removeUnsupportedTokenAtom) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { useSetAtom } from 'jotai' | ||
import { resetFavouriteTokensAtom } from '../state/tokens/favouriteTokensAtom' | ||
|
||
export function useResetFavouriteTokens() { | ||
return useSetAtom(resetFavouriteTokensAtom) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { useSetAtom } from 'jotai' | ||
import { resetUserTokenAtom } from '../state/tokens/userAddedTokensAtom' | ||
|
||
export function useResetUserTokensCallback(): () => void { | ||
return useSetAtom(resetUserTokenAtom) | ||
} |
Oops, something went wrong.