From 2158982e844e49311aa10a583870ada9ba970290 Mon Sep 17 00:00:00 2001 From: simke9445 Date: Tue, 26 Sep 2023 17:49:37 +0200 Subject: [PATCH] add nibiru support + sdk new ver --- apps/shared/hooks/ChainSelector.module.sass | 3 ++ apps/shared/hooks/useChainSelector.tsx | 45 ++++++++++++++++--- apps/shared/package.json | 2 +- .../queries/tokens/useNativeTokensQuery.ts | 3 +- apps/shared/types/tokens.ts | 11 +++++ apps/warp-protocol/package.json | 2 +- .../src/components/assets/Nibiru.svg | 12 +++++ .../warp-protocol/src/hooks/useNativeToken.ts | 4 +- indexers/warp-protocol/package.json | 2 +- yarn.lock | 14 +++--- 10 files changed, 81 insertions(+), 17 deletions(-) create mode 100644 apps/shared/hooks/ChainSelector.module.sass create mode 100644 apps/warp-protocol/src/components/assets/Nibiru.svg diff --git a/apps/shared/hooks/ChainSelector.module.sass b/apps/shared/hooks/ChainSelector.module.sass new file mode 100644 index 00000000..cd8185f2 --- /dev/null +++ b/apps/shared/hooks/ChainSelector.module.sass @@ -0,0 +1,3 @@ +.chain_icon + height: 24px + width: 24px \ No newline at end of file diff --git a/apps/shared/hooks/useChainSelector.tsx b/apps/shared/hooks/useChainSelector.tsx index a97a0f3b..8cb5b475 100644 --- a/apps/shared/hooks/useChainSelector.tsx +++ b/apps/shared/hooks/useChainSelector.tsx @@ -4,6 +4,7 @@ import { ReactNode, createContext, useContext, useMemo, useCallback, useEffect, import { ReactComponent as TerraIcon } from 'components/assets/Terra.svg'; import { ReactComponent as InjectiveIcon } from 'components/assets/Injective.svg'; import { ReactComponent as NeutronIcon } from 'components/assets/Neutron.svg'; +import { ReactComponent as NibiruIcon } from 'components/assets/Nibiru.svg'; import { ChainMetadata as SdkChainMetadata, TERRA_CHAIN, @@ -13,6 +14,8 @@ import { } from '@terra-money/warp-sdk'; import { useLocalStorage } from 'usehooks-ts'; +import styles from './ChainSelector.module.sass'; + export type ChainMetadata = SdkChainMetadata & { icon: ReactNode; }; @@ -29,16 +32,38 @@ type ChainSelectorContextState = { const getChainMetadata = (sdkMetadata: SdkChainMetadata) => { switch (sdkMetadata.name) { case 'injective': - return { ...sdkMetadata, icon: }; + return { ...sdkMetadata, icon: }; case 'terra': - return { ...sdkMetadata, icon: }; + return { ...sdkMetadata, icon: }; case 'neutron': - return { ...sdkMetadata, icon: }; + return { ...sdkMetadata, icon: }; + case 'nibiru': + return { ...sdkMetadata, icon: }; } }; const networkName = (networks: InfoResponse): NetworkName => ('pisco-1' in networks ? 'testnet' : 'mainnet'); +// TODO: required for mainnet flicker not to break app - remove when station mainnet supported is added +const addNibiru = (networks: InfoResponse): InfoResponse => { + if (networkName(networks) === 'mainnet') { + return { + ...networks, + 'nibiru-itn-2': { + chainID: 'nibiru-itn-2', + lcd: 'https://lcd.itn-2.nibiru.fi', + gasAdjustment: 1.75, + gasPrices: { + unibi: 0.15, + }, + prefix: 'nibi', + }, + }; + } + + return networks; +}; + const ChainSelectorContext = createContext(undefined); const useChainSelector = () => { @@ -55,7 +80,9 @@ interface ChainSelectorProviderProps { const ChainSelectorProvider = (props: ChainSelectorProviderProps) => { const { children } = props; - const { network } = useWallet(); + const { network: prevNetwork } = useWallet(); + + const network = useMemo(() => addNibiru(prevNetwork), [prevNetwork]); const [selectedChainMetadata, setSelectedChainMetadata] = useLocalStorage( '__warp_selected_chain', @@ -96,7 +123,15 @@ const ChainSelectorProvider = (props: ChainSelectorProviderProps) => { lcdClientConfig, lcd: new LCDClient(network), setSelectedChain, - supportedChains: ChainModule.supportedChains().map(getChainMetadata), + supportedChains: ChainModule.supportedChains() + .map(getChainMetadata) + .filter((c) => { + if (c.name === 'nibiru' && networkName(network) === 'mainnet') { + return false; + } + + return true; + }), }; return ret; diff --git a/apps/shared/package.json b/apps/shared/package.json index 90ae15c8..8432166d 100644 --- a/apps/shared/package.json +++ b/apps/shared/package.json @@ -33,7 +33,7 @@ "@mui/material": "^5.10.2", "@terra-money/feather.js": "^1.0.11", "@terra-money/wallet-kit": "^1.0.11", - "@terra-money/warp-sdk": "^0.1.56", + "@terra-money/warp-sdk": "^0.1.60", "assert": "^2.0.0", "big.js": "^6.2.1", "buffer": "^6.0.3", diff --git a/apps/shared/queries/tokens/useNativeTokensQuery.ts b/apps/shared/queries/tokens/useNativeTokensQuery.ts index f722d26d..8f840b74 100644 --- a/apps/shared/queries/tokens/useNativeTokensQuery.ts +++ b/apps/shared/queries/tokens/useNativeTokensQuery.ts @@ -1,6 +1,6 @@ import { useQuery, UseQueryResult } from 'react-query'; import { useChainSelector } from '../../hooks'; -import { INJ, LUNA, NativeTokensResponse, NEUTRON } from '../../types'; +import { INJ, LUNA, NativeTokensResponse, NEUTRON, NIBIRU } from '../../types'; export const useNativeTokensQuery = ( queryName: string = 'QUERY:NATIVE_TOKENS' @@ -14,6 +14,7 @@ export const useNativeTokensQuery = ( ...(selectedChain.name === 'terra' && { [LUNA.key]: LUNA }), ...(selectedChain.name === 'injective' && { [INJ.key]: INJ }), ...(selectedChain.name === 'neutron' && { [NEUTRON.key]: NEUTRON }), + ...(selectedChain.name === 'nibiru' && { [NIBIRU.key]: NIBIRU }), }; }, { diff --git a/apps/shared/types/tokens.ts b/apps/shared/types/tokens.ts index d369a919..71d2f79c 100644 --- a/apps/shared/types/tokens.ts +++ b/apps/shared/types/tokens.ts @@ -36,6 +36,17 @@ export const NEUTRON: NativeToken = { coinGeckoId: 'neutron', }; +export const NIBIRU: NativeToken = { + key: 'unibi', + type: 'native', + denom: 'unibi', + name: 'Nibiru', + symbol: 'NIBI', + decimals: 6, + icon: 'https://assets.terra.dev/icon/svg/ibc/ATOM.svg', + coinGeckoId: 'nibiru', +}; + export const INJ: NativeToken = { key: 'inj', type: 'native', diff --git a/apps/warp-protocol/package.json b/apps/warp-protocol/package.json index 993e05c4..66b3f8d1 100644 --- a/apps/warp-protocol/package.json +++ b/apps/warp-protocol/package.json @@ -41,7 +41,7 @@ "@popperjs/core": "^2.11.6", "@terra-money/feather.js": "^1.0.11", "@terra-money/wallet-kit": "^1.0.11", - "@terra-money/warp-sdk": "^0.1.56", + "@terra-money/warp-sdk": "^0.1.60", "assert": "^2.0.0", "big.js": "^6.2.1", "brace": "^0.11.1", diff --git a/apps/warp-protocol/src/components/assets/Nibiru.svg b/apps/warp-protocol/src/components/assets/Nibiru.svg new file mode 100644 index 00000000..3ca6f8c0 --- /dev/null +++ b/apps/warp-protocol/src/components/assets/Nibiru.svg @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/apps/warp-protocol/src/hooks/useNativeToken.ts b/apps/warp-protocol/src/hooks/useNativeToken.ts index f9219aaf..0b849cff 100644 --- a/apps/warp-protocol/src/hooks/useNativeToken.ts +++ b/apps/warp-protocol/src/hooks/useNativeToken.ts @@ -1,5 +1,5 @@ import { useChainSelector } from '@terra-money/apps/hooks'; -import { INJ, LUNA, NativeToken, NEUTRON } from '@terra-money/apps/types'; +import { INJ, LUNA, NativeToken, NEUTRON, NIBIRU } from '@terra-money/apps/types'; import { useMemo } from 'react'; export const useNativeToken = (): NativeToken => { @@ -13,6 +13,8 @@ export const useNativeToken = (): NativeToken => { return INJ; case 'neutron': return NEUTRON; + case 'nibiru': + return NIBIRU; } }, [selectedChain.name]); }; diff --git a/indexers/warp-protocol/package.json b/indexers/warp-protocol/package.json index 4ee0e698..3d123f8a 100644 --- a/indexers/warp-protocol/package.json +++ b/indexers/warp-protocol/package.json @@ -16,7 +16,7 @@ "@aws-sdk/client-dynamodb": "^3.159.0", "@aws-sdk/util-dynamodb": "^3.159.0", "@terra-money/feather.js": "^1.0.11", - "@terra-money/warp-sdk": "^0.1.56", + "@terra-money/warp-sdk": "^0.1.60", "@types/node": "^16.11.56", "axios": "^1.1.2", "big.js": "^6.2.1", diff --git a/yarn.lock b/yarn.lock index 73c16a38..473f430f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4322,7 +4322,7 @@ __metadata: "@mui/material": ^5.10.2 "@terra-money/feather.js": ^1.0.11 "@terra-money/wallet-kit": ^1.0.11 - "@terra-money/warp-sdk": ^0.1.56 + "@terra-money/warp-sdk": ^0.1.60 "@testing-library/jest-dom": ^5.16.5 "@testing-library/react": ^13.3.0 "@testing-library/user-event": ^13.5.0 @@ -4468,9 +4468,9 @@ __metadata: languageName: node linkType: hard -"@terra-money/warp-sdk@npm:^0.1.56": - version: 0.1.56 - resolution: "@terra-money/warp-sdk@npm:0.1.56" +"@terra-money/warp-sdk@npm:^0.1.60": + version: 0.1.60 + resolution: "@terra-money/warp-sdk@npm:0.1.60" dependencies: "@terra-money/feather.js": ^1.0.11 "@types/node": ^16.11.56 @@ -4483,7 +4483,7 @@ __metadata: lodash: ^4.17.21 pino: ^8.4.2 typescript: ^4.8.2 - checksum: a65e69fe0e9795473036da5a8bd6bfc905d8f21c951109569acb10cf6c3f262bdd8edc88c96ddbddcc32e7e603f0272395793e5ef56bf2aca29e320c2a7a9f92 + checksum: 52a07df9042933bff264602c332d16b455bd5e62f1e3a1a445b44176e9e9633a5c18bb38e735c78e98901ea87d1ef7599993d22bb12617d1c515b528dee7e6ce languageName: node linkType: hard @@ -5406,7 +5406,7 @@ __metadata: "@popperjs/core": ^2.11.6 "@terra-money/feather.js": ^1.0.11 "@terra-money/wallet-kit": ^1.0.11 - "@terra-money/warp-sdk": ^0.1.56 + "@terra-money/warp-sdk": ^0.1.60 "@testing-library/jest-dom": ^5.16.5 "@testing-library/react": ^13.3.0 "@testing-library/user-event": ^13.5.0 @@ -5483,7 +5483,7 @@ __metadata: "@aws-sdk/client-dynamodb": ^3.159.0 "@aws-sdk/util-dynamodb": ^3.159.0 "@terra-money/feather.js": ^1.0.11 - "@terra-money/warp-sdk": ^0.1.56 + "@terra-money/warp-sdk": ^0.1.60 "@types/d3-array": ^3.0.3 "@types/node": ^16.11.56 axios: ^1.1.2