Skip to content

Commit

Permalink
feat: injective amino signing (#549)
Browse files Browse the repository at this point in the history
* feat: dashboard through api
  • Loading branch information
nick134-bit authored Mar 26, 2024
1 parent fc949f1 commit 38f5213
Show file tree
Hide file tree
Showing 307 changed files with 143,968 additions and 206 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"eslint-plugin-import-helpers",
"@typescript-eslint"
],
"ignorePatterns": ["**/util/inj-types/**"],
"rules": {
// Possible Problems
"array-callback-return": [
Expand Down
32 changes: 13 additions & 19 deletions components/Pages/Dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import React, { FC, useEffect } from 'react'

import { HStack, Text, VStack } from '@chakra-ui/react'
import Loader from 'components/Loader'
import { Header } from 'components/Pages/Dashboard/Header'
import { StatsTable } from 'components/Pages/Dashboard/StatsTable'
import { usePrices } from 'hooks/usePrices'
import { fetchSupply } from 'libs/fetchSupply'
import { useRecoilState } from 'recoil'
import { getBondingAPRsAPI } from 'services/useAPI'
import { dashboardDataState } from 'state/dashboardDataState'
import { getChainLogoUrlByName } from 'util/getChainLogoUrlByName'
import { getDashboardData } from 'util/getDashboardData'
import { useGetDailyBuybacks } from './hooks/useGetDailyBuybacks'

import { useGetDashboardDataAPI } from './hooks/getDashboardDataAPI'

export type DashboardData = {
logoUrl: string
Expand All @@ -22,20 +21,15 @@ export type DashboardData = {
}
export const Dashboard: FC = () => {
const [dashboardState, setDashboardDataState] = useRecoilState(dashboardDataState)
const { data: buybackData, isLoading } = useGetDailyBuybacks()
const { data: dashboardData, isLoading } = useGetDashboardDataAPI()
const prices = usePrices()
useEffect(() => {
const fetchDashboardData = async () => {
let [circulatingWhaleSupply, mockData, aprs]: any = await Promise.all([
fetchSupply(),
getDashboardData(),
getBondingAPRsAPI(),
])
circulatingWhaleSupply = circulatingWhaleSupply?.circulating / (10 ** 6) || 0
const marketCap = circulatingWhaleSupply * (prices?.WHALE || 0)
const mappedDashboardData = mockData.map((data) => {
const apr = aprs[data.chainName].bondingAPR
const buyback = buybackData.find(buybackData=> buybackData.chainName === data.chainName)?.buyback
const circulatingWhaleSupply = dashboardData.supply?.circulating / (10 ** 6) || 0
const marketCap = circulatingWhaleSupply * (prices?.WHALE || 0) || 0
const mappedDashboardData = dashboardData.dashboardData?.map((data) => {
const apr = dashboardData.bondingInfos[data.chainName]?.bondingAPR
const buyback = dashboardData.bondingInfos[data.chainName]?.buyback
return ({
logoUrl: getChainLogoUrlByName(data.chainName),
chainName: data.chainName,
Expand All @@ -50,7 +44,7 @@ export const Dashboard: FC = () => {
data: mappedDashboardData,
whalePrice: prices?.WHALE ? prices.WHALE : 0,
marketCap: marketCap ? marketCap : 0,
isInitialized: prices?.WHALE !== 0 && marketCap !== 0,
isInitialized: prices?.WHALE !== 0 && circulatingWhaleSupply !== 0 && marketCap !== 0 && dashboardData.dashboardData?.length > 0,
})
}
if (!dashboardState.isInitialized) {
Expand All @@ -59,7 +53,7 @@ export const Dashboard: FC = () => {
}, [prices, dashboardState.isInitialized, isLoading])

return <VStack width={'full'}>
{dashboardState.isInitialized && <Header dashboardData={dashboardState.data} />}
{dashboardState.isInitialized && <Header dashboardData={dashboardState?.data} />}
{!dashboardState.isInitialized && (<HStack
paddingTop={'20%'}
width="full"
Expand All @@ -68,7 +62,7 @@ export const Dashboard: FC = () => {
alignItems="center">
<Loader />
</HStack>)}
{dashboardState.isInitialized && <StatsTable dashboardData={dashboardState.data} />}
{dashboardState.isInitialized && <HStack alignSelf={'start'}><Text fontWeight={'bold'}>{`Total Daily Dex Buybacks: ${dashboardState.data.reduce((acc, data) => acc + data.buyback, 0).toFixed(2)} WHALE`}</Text></HStack>}
{dashboardState.isInitialized && <StatsTable dashboardData={dashboardState?.data} />}
{dashboardState.isInitialized && <HStack alignSelf={'start'}><Text fontWeight={'bold'}>{`Total Daily Dex Buybacks: ${dashboardState.data?.reduce((acc, data) => acc + data.buyback, 0).toFixed(2)} WHALE`}</Text></HStack>}
</VStack>
}
58 changes: 58 additions & 0 deletions components/Pages/Dashboard/hooks/getDashboardDataAPI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { useMemo } from 'react'
import { useQueries } from 'react-query'

import { fetchSupply } from 'libs/fetchSupply'
import { debounce } from 'lodash'
import { getBondingAPRsAPI } from 'services/useAPI'
import { getDashboardData } from 'util/getDashboardData'

export const useGetDashboardDataAPI = () => {
const debouncedRefetch = useMemo(() => debounce((refetchFunc) => refetchFunc(), 500),
[])

const queries = useQueries([
{
queryKey: ['WHALEsupply'],
queryFn: () => fetchSupply(),
refetchOnMount: 'always',
refetchInterval: 180000
},
{
queryKey: ['dashBoardData'],
queryFn: () => getDashboardData(),
refetchOnMount: 'always',
refetchInterval: 180000
},
{
queryKey: ['bondingInfos'],
queryFn: () => getBondingAPRsAPI(),
refetchOnMount: 'always',
refetchInterval: 180000
},
])

const isLoading = useMemo(() => queries.some((query) => (
query.isLoading || (!query.data && query.data !== 0)
)),
[queries])

const refetchAll = () => {
queries.forEach((query) => {
debouncedRefetch(query.refetch)
})
}

const data = useMemo(() => {
const supply = queries[0].data
const dashboardData = queries[1].data
const bondingInfos = queries[2].data

return { supply,
dashboardData,
bondingInfos }
}, [queries])

return { data,
isLoading,
refetch: refetchAll }
}
130 changes: 0 additions & 130 deletions components/Pages/Dashboard/hooks/useGetDailyBuybacks.ts

This file was deleted.

15 changes: 1 addition & 14 deletions components/Wallet/ChainSelect/ChainList/ChainItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ const ChainItem = ({
onClose,
active,
walletConnected,
walletType,
}) => {
const queryClient = useQueryClient()
return (
<Tooltip
label={ !walletConnected && !chain.chainName?.includes('Injective') ? (
label={ !walletConnected ? (
<Box
maxWidth="220px"
minWidth="fit-content"
Expand All @@ -28,18 +27,6 @@ const ChainItem = ({
whiteSpace="pre-wrap"
>
To access this chain, you must add it to your wallet.
</Box>) : !walletConnected && chain.chainName?.includes('Injective') && walletType !== 'station-extension' ? (
<Box
maxWidth="220px"
minWidth="fit-content"
borderRadius="10px"
bg="black"
color="white"
fontSize={14}
p={4}
whiteSpace="pre-wrap"
>
Injective with Station not supported. Please try Keplr or Leap.
</Box>) : null
}
bg="transparent"
Expand Down
3 changes: 0 additions & 3 deletions components/Wallet/Modal/WalletConnectButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ export const WalletConnectButton = ({ onCloseModal, connect, walletType }: Props
console.error(`${chainId} not activated`)
handleChainActivationError(chainName, toast);
}
if (walletType === WalletType.terraExtension && chainName.includes('injective')) {
error = true
}
}
if (!error) {
connect()
Expand Down
10 changes: 8 additions & 2 deletions components/Wallet/Modal/WalletModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,18 @@ export const WalletModal = ({ isOpen, setOpen, walletRepo }) => {
}
}

const shouldRenderButton = (wallet: { walletName: string, isModeExtension: boolean }) => {
const shouldRenderButton = (wallet: { walletName: WalletType, isModeExtension: boolean }) => {
const { walletName } = wallet
const okxchains = ['osmosis-1', 'juno-1', 'pacific-1', 'injective-1']
const inAppLeap = isMobile && window.leap && window.leap.mode === 'mobile-web'
const inAppKeplr = isMobile && window.keplr && window.keplr.mode === 'mobile-web' && !inAppLeap
const inj = chainId.includes('injective') && (walletName === WalletType.keplrExtension || walletName === WalletType.leapExtension || walletName === WalletType.ninjiExtension || walletName === WalletType.okxwallet)
const inj = chainId.includes('injective') && [
WalletType.terraExtension,
WalletType.keplrExtension,
WalletType.leapExtension,
WalletType.ninjiExtension,
WalletType.okxwallet,
].includes(walletName);
if (walletName === WalletType.okxwallet && !okxchains.includes(chainId)) {
return false
}
Expand Down
20 changes: 6 additions & 14 deletions components/Wallet/Wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,27 +110,19 @@ const Wallet = () => {
};
filterChains().then(async ([chainNames, ids]) => {
if (chainNames.includes('injective')) {
if (walletType !== WalletType.terraExtension) {
try {
await walletWindowConnection.getKey(ChainId.injective)
} catch {
console.error('Injective not activated');
const injIndex = chainNames.indexOf('injective')
if (injIndex !== -1) {
chainNames.splice(injIndex, 1)
ids.splice(injIndex, 1)
}
}
} else {
try {
await walletWindowConnection.getKey(ChainId.injective)
} catch {
console.error('Injective not activated');
const injIndex = chainNames.indexOf('injective')
if (injIndex !== -1) {
chainNames.splice(injIndex, 1)
ids.splice(injIndex, 1)
}
}
setWalletChains(chainNames)
setCurrentConnectedChainIds(ids)
}
setWalletChains(chainNames)
setCurrentConnectedChainIds(ids)
});
} else if (walletChains.length === 0) {
setCurrentConnectedChainIds(Object.values(ACTIVE_NETWORKS[currentChainState.network]))
Expand Down
2 changes: 1 addition & 1 deletion constants/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export const POOL_INFO_BASE_URL =

export const COSMOS_KIT_WALLET_KEY = 'cosmos-kit@2:core//current-wallet'

export const API_URLS = ['https://fd60qhijvtes7do71ou6moc14s.ingress.pcgameservers.com']
export const API_URLS = ['https://fd60qhijvtes7do71ou6moc14s.ingress.pcgameservers.com', 'https://9c0pbpbijhepr6ijm4lk85uiuc.ingress.europlots.com']

export const ADV_MEMO = 'app.whitewhale.money'
Loading

0 comments on commit 38f5213

Please sign in to comment.