Skip to content

Commit

Permalink
add nibiru support + sdk new ver
Browse files Browse the repository at this point in the history
  • Loading branch information
simke9445 committed Sep 26, 2023
1 parent 8be7fac commit 2158982
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 17 deletions.
3 changes: 3 additions & 0 deletions apps/shared/hooks/ChainSelector.module.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.chain_icon
height: 24px
width: 24px
45 changes: 40 additions & 5 deletions apps/shared/hooks/useChainSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
};
Expand All @@ -29,16 +32,38 @@ type ChainSelectorContextState = {
const getChainMetadata = (sdkMetadata: SdkChainMetadata) => {
switch (sdkMetadata.name) {
case 'injective':
return { ...sdkMetadata, icon: <InjectiveIcon /> };
return { ...sdkMetadata, icon: <InjectiveIcon className={styles.chain_icon} /> };
case 'terra':
return { ...sdkMetadata, icon: <TerraIcon /> };
return { ...sdkMetadata, icon: <TerraIcon className={styles.chain_icon} /> };
case 'neutron':
return { ...sdkMetadata, icon: <NeutronIcon /> };
return { ...sdkMetadata, icon: <NeutronIcon className={styles.chain_icon} /> };
case 'nibiru':
return { ...sdkMetadata, icon: <NibiruIcon className={styles.chain_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<ChainSelectorContextState | undefined>(undefined);

const useChainSelector = () => {
Expand All @@ -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<SdkChainMetadata>(
'__warp_selected_chain',
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion apps/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion apps/shared/queries/tokens/useNativeTokensQuery.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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 }),
};
},
{
Expand Down
11 changes: 11 additions & 0 deletions apps/shared/types/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion apps/warp-protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions apps/warp-protocol/src/components/assets/Nibiru.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion apps/warp-protocol/src/hooks/useNativeToken.ts
Original file line number Diff line number Diff line change
@@ -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 => {
Expand All @@ -13,6 +13,8 @@ export const useNativeToken = (): NativeToken => {
return INJ;
case 'neutron':
return NEUTRON;
case 'nibiru':
return NIBIRU;
}
}, [selectedChain.name]);
};
2 changes: 1 addition & 1 deletion indexers/warp-protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 7 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2158982

Please sign in to comment.