From 3a4f37f1d18c4f8504aa7eebf6daba4ebca158d1 Mon Sep 17 00:00:00 2001 From: Niranjan Ramadas Date: Fri, 23 Sep 2022 12:30:10 -0400 Subject: [PATCH] Make it possible to adjust token metadata (#1059) --- package.json | 2 ++ public/realms/token-overrides.json | 8 ++++++++ utils/services/token.tsx | 14 +++++++++++++- yarn.lock | 12 ++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 public/realms/token-overrides.json diff --git a/package.json b/package.json index 8c240021b5..f493cd0563 100644 --- a/package.json +++ b/package.json @@ -88,6 +88,7 @@ "@streamflow/stream": "3.0.10", "@switchboard-xyz/switchboard-v2": "^0.0.110", "@tippyjs/react": "^4.2.6", + "@types/ramda": "^0.28.15", "@urql/exchange-auth": "^1.0.0", "@urql/exchange-graphcache": "^5.0.1", "@urql/exchange-multipart-fetch": "^1.0.1", @@ -122,6 +123,7 @@ "psyfi-euros-test": "^0.0.1-rc.33", "pyth-staking-api": "^1.2.17", "qr-code-styling": "^1.6.0-rc.1", + "ramda": "^0.28.0", "rc-slider": "^9.7.5", "react": "^18.1.0", "react-dom": "^18.0.0", diff --git a/public/realms/token-overrides.json b/public/realms/token-overrides.json new file mode 100644 index 0000000000..8a44678f9f --- /dev/null +++ b/public/realms/token-overrides.json @@ -0,0 +1,8 @@ +{ + "METAewgxyPbgwsseH8T16a39CQ5VyVxZi9zXiDPY18m": { + "symbol": "MPLX", + "extensions": { + "coingeckoId": "metaplex" + } + } +} diff --git a/utils/services/token.tsx b/utils/services/token.tsx index c389d675c1..0066fa3a6c 100644 --- a/utils/services/token.tsx +++ b/utils/services/token.tsx @@ -1,8 +1,12 @@ import axios from 'axios' import { TokenListProvider, TokenInfo } from '@solana/spl-token-registry' +import { mergeDeepRight } from 'ramda' + import { notify } from '@utils/notifications' import { WSOL_MINT } from '@components/instructions/tools' import { MANGO_MINT } from 'Strategies/protocols/mango/tools' +import overrides from 'public/realms/token-overrides.json' + const coingeckoPriceEndpoint = 'https://api.coingecko.com/api/v3/simple/price' class TokenService { @@ -17,7 +21,15 @@ class TokenService { const tokens = await new TokenListProvider().resolve() const tokenList = tokens.filterByClusterSlug('mainnet-beta').getList() if (tokenList && tokenList.length) { - this._tokenList = tokenList + this._tokenList = tokenList.map((token) => { + const override = overrides[token.address] + + if (override) { + return mergeDeepRight(token, override) + } + + return token + }) } } catch (e) { console.log(e) diff --git a/yarn.lock b/yarn.lock index 3044edbcda..e4b0e27a80 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6923,6 +6923,13 @@ resolved "https://registry.npmjs.org/@types/qs/-/qs-6.9.7.tgz" integrity sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw== +"@types/ramda@^0.28.15": + version "0.28.15" + resolved "https://registry.yarnpkg.com/@types/ramda/-/ramda-0.28.15.tgz#36bb4c8de430e3bbcd29590537569aef64409716" + integrity sha512-FCaLNVZry65jW8x/FDnKgjgkCNQxgc5AYMQwdNn6yW5M+62R+0nt2Y36U43dTNora9hcquemfrY5gxhE5pcilQ== + dependencies: + ts-toolbelt "^6.15.1" + "@types/range-parser@*": version "1.2.4" resolved "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.4.tgz" @@ -19109,6 +19116,11 @@ ts-proto@^1.79.0: ts-poet "^4.5.0" ts-proto-descriptors "1.6.0" +ts-toolbelt@^6.15.1: + version "6.15.5" + resolved "https://registry.yarnpkg.com/ts-toolbelt/-/ts-toolbelt-6.15.5.tgz#cb3b43ed725cb63644782c64fbcad7d8f28c0a83" + integrity sha512-FZIXf1ksVyLcfr7M317jbB67XFJhOO1YqdTcuGaq9q5jLUoTikukZ+98TPjKiP2jC5CgmYdWWYs0s2nLSU0/1A== + tsconfig-paths@^3.14.1: version "3.14.1" resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.14.1.tgz#ba0734599e8ea36c862798e920bcf163277b137a"