Skip to content

Commit c5e33a5

Browse files
committed
refactor: remove native currency symbol check
1 parent bfb602d commit c5e33a5

File tree

5 files changed

+11
-27
lines changed

5 files changed

+11
-27
lines changed

apps/main/src/dex/store/createUserBalancesSlice.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ const createUserBalancesSlice = (
6767
chainId,
6868
userAddress: signerAddress,
6969
tokenAddress: token as Address,
70-
tokenSymbol: '',
7170
}).then((balance) => [token, balance]),
7271
),
7372
)

apps/main/src/llamalend/features/borrow/hooks/useCreateLoanForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export function useCreateLoanForm<ChainId extends LlamaChainId>({
7676
params,
7777
isPending: form.formState.isSubmitting || isCreating,
7878
onSubmit: form.handleSubmit(onSubmit), // todo: handle form errors
79-
maxTokenValues: useMaxTokenValues(collateralToken, params, form),
79+
maxTokenValues: useMaxTokenValues(collateralToken?.address, params, form),
8080
borrowToken,
8181
collateralToken,
8282
isCreated,

apps/main/src/llamalend/features/borrow/hooks/useMaxTokenValues.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ import type { BorrowForm, BorrowFormQueryParams } from '../types'
1818
* @param form - The react-hook-form instance managing the borrow form state.
1919
*/
2020
export function useMaxTokenValues(
21-
collateralToken: { address: Address; symbol?: string } | undefined,
21+
collateralToken: Address | undefined,
2222
params: BorrowFormQueryParams & { userAddress?: Address },
2323
form: UseFormReturn<BorrowForm>,
2424
) {
2525
const {
2626
data: userBalance,
2727
error: balanceError,
2828
isLoading: isBalanceLoading,
29-
} = useTokenBalance({ ...params, tokenAddress: collateralToken?.address, tokenSymbol: collateralToken?.symbol })
29+
} = useTokenBalance({ ...params, tokenAddress: collateralToken })
3030
const { data: maxBorrow, error: maxBorrowError, isLoading: isLoadingMaxBorrow } = useCreateLoanMaxReceive(params)
3131
const {
3232
data: maxTotalLeverage,

apps/main/src/llamalend/widgets/manage-loan/LoanFormTokenInput.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ export const LoanFormTokenInput = <
5353
chainId: network?.chainId,
5454
userAddress,
5555
tokenAddress: token?.address,
56-
tokenSymbol: token?.symbol,
5756
})
5857

5958
const errors = form.formState.errors as PartialRecord<FieldPath<TFieldValues>, Error>

packages/curve-ui-kit/src/queries/token-balance.query.ts

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { erc20Abi, ethAddress, formatUnits, type Address } from 'viem'
1+
import { erc20Abi, ethAddress, formatUnits, isAddressEqual, type Address } from 'viem'
22
import { useConfig } from 'wagmi'
33
import { useBalance, useReadContracts } from 'wagmi'
44
import type { FieldsOf } from '@ui-kit/lib'
@@ -10,7 +10,6 @@ import type { GetBalanceReturnType } from '@wagmi/core'
1010
import { getBalanceQueryOptions, readContractsQueryOptions } from '@wagmi/core/query'
1111

1212
type TokenQuery = { tokenAddress: Address }
13-
type TokenSymbolQuery = { tokenSymbol: string }
1413

1514
/** Convert user collateral from GetBalanceReturnType to number */
1615
const convertBalance = ({ value, decimals }: Partial<GetBalanceReturnType>) =>
@@ -30,20 +29,12 @@ const getERC20QueryContracts = ({ chainId, userAddress, tokenAddress }: ChainQue
3029
{ chainId, address: tokenAddress, abi: erc20Abi, functionName: 'decimals' },
3130
] as const
3231

33-
/** Function that gets the native currency symbol for a given chain */
34-
const getNativeCurrencySymbol = (config: Config, chainId: number) =>
35-
config.chains.find((chain) => chain.id === chainId)?.nativeCurrency?.symbol
36-
37-
/** Function that checks if a given token address and symbol are the chain's native currency symbol */
38-
const isNative = (config: Config, { chainId, tokenAddress, tokenSymbol }: ChainQuery & TokenQuery & TokenSymbolQuery) =>
39-
tokenAddress === ethAddress || tokenSymbol === getNativeCurrencySymbol(config, chainId)
32+
/** In the Curve ecosystem all native chain gas tokens are the 0xeee...eee address */
33+
const isNative = ({ tokenAddress }: TokenQuery) => isAddressEqual(tokenAddress, ethAddress)
4034

4135
/** Imperatively fetch token balance */
42-
export const fetchTokenBalance = async (
43-
config: Config,
44-
query: ChainQuery & UserQuery & TokenQuery & TokenSymbolQuery,
45-
) =>
46-
isNative(config, query)
36+
export const fetchTokenBalance = async (config: Config, query: ChainQuery & UserQuery & TokenQuery) =>
37+
isNative(query)
4738
? await queryClient
4839
.fetchQuery(getNativeBalanceQueryOptions(config, query))
4940
.then((balance) => convertBalance({ value: balance.value, decimals: balance.decimals }))
@@ -57,16 +48,11 @@ export const fetchTokenBalance = async (
5748
.then((balance) => convertBalance({ value: balance[0], decimals: balance[1] }))
5849

5950
/** Hook to fetch the token balance */
60-
export function useTokenBalance({
61-
chainId,
62-
userAddress,
63-
tokenAddress,
64-
tokenSymbol,
65-
}: FieldsOf<ChainQuery & UserQuery & TokenQuery & TokenSymbolQuery>) {
51+
export function useTokenBalance({ chainId, userAddress, tokenAddress }: FieldsOf<ChainQuery & UserQuery & TokenQuery>) {
6652
const config = useConfig()
6753

68-
const isEnabled = chainId != null && userAddress != null && tokenAddress != null && tokenSymbol != null
69-
const isNativeToken = isEnabled && isNative(config, { chainId, tokenAddress, tokenSymbol })
54+
const isEnabled = chainId != null && userAddress != null && tokenAddress != null
55+
const isNativeToken = isEnabled && isNative({ tokenAddress })
7056

7157
const nativeBalance = useBalance({
7258
...(isEnabled ? getNativeBalanceQueryOptions(config, { chainId, userAddress }) : {}),

0 commit comments

Comments
 (0)