Skip to content

Commit

Permalink
fix: pricing when no wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
Majorfi committed Nov 30, 2023
1 parent c75ec8c commit e91af9f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 0.3.1 (30/11/2023)

- Fix: Divisions by 0 in the veYFI rate calculator
- Fix: Pricing when wallet isn't connected

# 0.3.0 (30/11/2023)

Expand Down
28 changes: 15 additions & 13 deletions apps/common/contexts/useWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import type {TYDaemonVault} from '@common/schemas/yDaemonVaultsSchemas';
import type {TChainTokens, TNormalizedBN, TToken} from '@common/types/types';

export type TWalletContext = {
getToken: ({address, chainID}: {address: TAddress; chainID: number}) => TToken;
getBalance: ({address, chainID}: {address: TAddress; chainID: number}) => TNormalizedBN;
getPrice: ({address, chainID}: {address: TAddress; chainID: number}) => TNormalizedBN;
getToken: ({address, chainID}: TTokenAndChain) => TToken;
getBalance: ({address, chainID}: TTokenAndChain) => TNormalizedBN;
getPrice: ({address, chainID}: TTokenAndChain) => TNormalizedBN;
balances: TChainTokens;
cumulatedValueInV2Vaults: number;
cumulatedValueInV3Vaults: number;
Expand All @@ -39,6 +39,7 @@ export type TWalletContext = {
refresh: (tokenList?: TUseBalancesTokens[]) => Promise<TChainTokens>;
triggerForknetBalances: () => void;
};
type TTokenAndChain = {address: TAddress; chainID: number};

const defaultToken: TToken = {
address: zeroAddress,
Expand Down Expand Up @@ -217,7 +218,7 @@ function useYearnBalances({shouldUseForknetBalances}: {shouldUseForknetBalances:
******************************************************************************/
const WalletContext = createContext<TWalletContext>(defaultProps);
export const WalletContextApp = memo(function WalletContextApp({children}: {children: ReactElement}): ReactElement {
const {vaults, vaultsMigrations} = useYearn();
const {vaults, prices, vaultsMigrations} = useYearn();
const [shouldUseForknetBalances, set_shouldUseForknetBalances] = useState<boolean>(false);
const {tokens, isLoading, onRefresh} = useYearnBalances({shouldUseForknetBalances});

Expand Down Expand Up @@ -248,22 +249,23 @@ export const WalletContextApp = memo(function WalletContextApp({children}: {chil
}, [vaults, vaultsMigrations, tokens]);

const getToken = useCallback(
({address, chainID}: {address: TAddress; chainID: number}): TToken => {
return tokens?.[chainID || 1]?.[address] || defaultToken;
},
({address, chainID}: TTokenAndChain): TToken => tokens?.[chainID || 1]?.[address] || defaultToken,
[tokens]
);
const getBalance = useCallback(
({address, chainID}: {address: TAddress; chainID: number}): TNormalizedBN => {
return tokens?.[chainID || 1]?.[address]?.balance || toNormalizedBN(0);
},
({address, chainID}: TTokenAndChain): TNormalizedBN =>
tokens?.[chainID || 1]?.[address]?.balance || toNormalizedBN(0),
[tokens]
);
const getPrice = useCallback(
({address, chainID}: {address: TAddress; chainID: number}): TNormalizedBN => {
return tokens?.[chainID || 1]?.[address]?.price || toNormalizedBN(0);
({address, chainID}: TTokenAndChain): TNormalizedBN => {
const price = tokens?.[chainID || 1]?.[address]?.price;
if (!price) {
return toNormalizedBN(prices?.[chainID]?.[address] || 0, 6) || toNormalizedBN(0);
}
return price;
},
[tokens]
[prices, tokens]
);

/* 🔵 - Yearn Finance ******************************************************
Expand Down
8 changes: 4 additions & 4 deletions apps/common/hooks/useMultichainBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,10 @@ export function useBalances(props?: TUseBalancesReq): TUseBalancesRes {
status: status.isError
? 'error'
: status.isLoading || status.isFetching
? 'loading'
: status.isSuccess
? 'success'
: 'unknown'
? 'loading'
: status.isSuccess
? 'success'
: 'unknown'
}),
[
assignPrices,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export function VaultDetailsStrategies({currentVault}: {currentVault: TYDaemonVa
<p className={'text-center text-neutral-600'}>{'Try another search term'}</p>
<Button
className={'mt-4 w-full md:w-48'}
onClick={() => onSearch('')}>
onClick={(): void => onSearch('')}>
{'Clear Search'}
</Button>
</div>
Expand Down
1 change: 1 addition & 0 deletions apps/veyfi/components/ViewStakeUnstakeGauges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export function StakeUnstakeGauges(): ReactElement {
Number(gauge?.totalStaked.normalized || 0) /
Number(tokenPrice.normalized || 0)) *
100;

if (tokenPrice.raw === 0n || Number(gauge?.totalStaked.normalized || 0) === 0) {
APRFor10xBoost = 0;
}
Expand Down

1 comment on commit e91af9f

@vercel
Copy link

@vercel vercel bot commented on e91af9f Nov 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.