Skip to content

Commit

Permalink
Merge branch 'master' into feature/sonic-trending-tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
OlaStenberg committed Jan 8, 2025
2 parents 863c2e5 + 9ea159c commit 62cd709
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 47 deletions.
2 changes: 1 addition & 1 deletion apps/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"class-variance-authority": "0.7.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"sushi": "4.1.22"
"sushi": "4.1.23"
},
"devDependencies": {
"@storybook/addon-a11y": "7.4.6",
Expand Down
2 changes: 1 addition & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"react-window": "1.8.7",
"sharp": "^0.33.5",
"strapi-sdk-js": "2.3.3",
"sushi": "4.1.22",
"sushi": "4.1.23",
"swr": "2.1.5",
"tiny-invariant": "1.3.1",
"tronweb": "5.3.2",
Expand Down
82 changes: 61 additions & 21 deletions apps/web/src/ui/stake/SushiBarProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
import { FC, ReactNode, createContext, useContext, useMemo } from 'react'
import { useBarData } from 'src/lib/stake'
import { ChainId } from 'sushi/chain'
import { Amount, SUSHI, Type, XSUSHI, tryParseAmount } from 'sushi/currency'
import {
Amount,
SUSHI,
SUSHI_ADDRESS,
Type,
XSUSHI,
XSUSHI_ADDRESS,
} from 'sushi/currency'
import { erc20Abi } from 'viem'
import { useReadContracts } from 'wagmi'

interface SushiBarContext {
totalSupply: Amount<Type> | undefined
Expand All @@ -19,34 +28,65 @@ export const SushiBarProvider: FC<{
children: ReactNode
watch?: boolean
}> = ({ children }) => {
const { data, isLoading, isError } = useBarData()
const {
data,
isLoading: isLoadingBarData,
isError: isErrorBarData,
} = useBarData()

const [sushiBalance, totalSupply, apy] = useMemo(
() => [
tryParseAmount(
(data?.sushiSupply ?? 0).toString(),
SUSHI[ChainId.ETHEREUM],
),
tryParseAmount(
(data?.xSushiSupply ?? 0).toString(),
XSUSHI[ChainId.ETHEREUM],
),
data && data?.apr1m !== undefined ? Number(data.apr1m) * 12 : undefined,
const {
data: balanceAndSupplyData,
isLoading: isLoadingSushiBalanceData,
isError: isErrorSushiBalanceData,
} = useReadContracts({
allowFailure: false,
contracts: [
{
address: SUSHI_ADDRESS[ChainId.ETHEREUM],
abi: erc20Abi,
functionName: 'balanceOf',
args: [XSUSHI_ADDRESS[ChainId.ETHEREUM]],
chainId: ChainId.ETHEREUM,
},
{
address: XSUSHI_ADDRESS[ChainId.ETHEREUM],
chainId: ChainId.ETHEREUM,
abi: erc20Abi,
functionName: 'totalSupply' as const,
},
],
[data],
)
query: {
select(data) {
return [
Amount.fromRawAmount(SUSHI[ChainId.ETHEREUM], data[0]),
Amount.fromRawAmount(XSUSHI[ChainId.ETHEREUM], data[1]),
] as const
},
refetchInterval: 30000,
},
})

return (
<Context.Provider
value={useMemo(
() => ({
totalSupply,
sushiBalance,
apy,
isLoading,
isError,
sushiBalance: balanceAndSupplyData?.[0],
totalSupply: balanceAndSupplyData?.[1],
apy:
data && data?.apr1m !== undefined
? Number(data.apr1m) * 12
: undefined,
isLoading: isLoadingBarData || isLoadingSushiBalanceData,
isError: isErrorBarData || isErrorSushiBalanceData,
}),
[sushiBalance, totalSupply, apy, isError, isLoading],
[
balanceAndSupplyData,
data,
isLoadingBarData,
isLoadingSushiBalanceData,
isErrorBarData,
isErrorSushiBalanceData,
],
)}
>
{children}
Expand Down
2 changes: 1 addition & 1 deletion packages/graph-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"graphql": "16.6.0",
"graphql-request": "7.1.0",
"json-bigint": "1.0.0",
"sushi": "4.1.22",
"sushi": "4.1.23",
"viem": "2.21.55"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@types/react-dom": "18.2.6",
"react": "18.2.0",
"react-dom": "18.2.0",
"sushi": "4.1.22",
"sushi": "4.1.23",
"tailwindcss": "3.3.2",
"typescript": "5.7.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/notifications/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"@tsconfig/strictest": "2.0.2",
"@types/react": "18.2.14",
"@types/react-dom": "18.2.6",
"sushi": "4.1.22",
"sushi": "4.1.23",
"typescript": "5.7.2"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/steer-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"dependencies": {
"@steerprotocol/contracts": "2.1.0-beta.14",
"sushi": "4.1.22",
"sushi": "4.1.23",
"viem": "2.21.55"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"postcss": "8.4.23",
"react": "18.2.0",
"react-dom": "18.2.0",
"sushi": "4.1.22",
"sushi": "4.1.23",
"tailwindcss": "3.3.2",
"typescript": "5.7.2",
"wagmi": "2.12.10"
Expand Down
37 changes: 18 additions & 19 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 62cd709

Please sign in to comment.