Skip to content

Commit

Permalink
fix: animation and zod
Browse files Browse the repository at this point in the history
  • Loading branch information
Majorfi committed Oct 4, 2023
1 parent 5d0e429 commit 70dcd38
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion apps/common/schemas/yDaemonPricesSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {addressSchema} from '@yearn-finance/web-lib/utils/schemas/addressSchema'

export const yDaemonPriceSchema = z.string();
export const yDaemonPricesSchema = z.record(addressSchema, yDaemonPriceSchema);
export const yDaemonPricesChainSchema = z.record(z.number(), yDaemonPricesSchema);
export const yDaemonPricesChainSchema = z.record(z.string(), yDaemonPricesSchema);

export type TYDaemonPrice = z.infer<typeof yDaemonPriceSchema>;
export type TYDaemonPrices = z.infer<typeof yDaemonPricesSchema>;
Expand Down
2 changes: 1 addition & 1 deletion apps/common/schemas/yDaemonTokensSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const yDaemonTokenSchema = z.object({
});

export const yDaemonTokensSchema = z.record(addressSchema, yDaemonTokenSchema);
export const yDaemonTokensChainSchema = z.record(z.number(), yDaemonTokensSchema);
export const yDaemonTokensChainSchema = z.record(z.string(), yDaemonTokensSchema);

export type TYDaemonToken = z.infer<typeof yDaemonTokenSchema>;
export type TYDaemonTokens = z.infer<typeof yDaemonTokensSchema>;
Expand Down
29 changes: 15 additions & 14 deletions pages/vaults/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Fragment, useCallback, useMemo} from 'react';
import {Fragment, useCallback, useEffect, useMemo} from 'react';
import {motion, useSpring, useTransform} from 'framer-motion';
import {VaultListOptions} from '@vaults/components/list/VaultListOptions';
import {VaultsListEmpty} from '@vaults/components/list/VaultsListEmpty';
import {VaultsListInternalMigrationRow} from '@vaults/components/list/VaultsListInternalMigrationRow';
Expand All @@ -19,7 +20,6 @@ import {toAddress} from '@yearn-finance/web-lib/utils/address';
import {formatAmount} from '@yearn-finance/web-lib/utils/format.number';
import {isZero} from '@yearn-finance/web-lib/utils/isZero';
import {ListHead} from '@common/components/ListHead';
import {ValueAnimation} from '@common/components/ValueAnimation';
import {useWallet} from '@common/contexts/useWallet';
import {useYearn} from '@common/contexts/useYearn';
import {getVaultName} from '@common/utils';
Expand All @@ -31,6 +31,17 @@ import type {TYDaemonVault} from '@common/schemas/yDaemonVaultsSchemas';
import type {TSortDirection} from '@common/types/types';
import type {TPossibleSortBy} from '@vaults/hooks/useSortVaults';

function Counter({value}: {value: number}): ReactElement {
const v = useSpring(value, {mass: 1, stiffness: 75, damping: 15});
const display = useTransform(v, (current): string => `$${formatAmount(current)}`);

useEffect((): void => {
v.set(value);
}, [v, value]);

return <motion.span>{display}</motion.span>;
}

function HeaderUserPosition(): ReactElement {
const {cumulatedValueInVaults} = useWallet();
const {earned} = useYearn();
Expand Down Expand Up @@ -69,23 +80,13 @@ function HeaderUserPosition(): ReactElement {
<div className={'col-span-12 w-full md:col-span-8'}>
<p className={'pb-2 text-lg text-neutral-900 md:pb-6 md:text-3xl'}>{'Deposited'}</p>
<b className={'font-number text-4xl text-neutral-900 md:text-7xl'}>
<ValueAnimation
identifier={'youHave'}
value={formatedYouHave}
defaultValue={'0,00'}
prefix={'$'}
/>
<Counter value={Number(formatedYouHave)} />
</b>
</div>
<div className={'col-span-12 w-full md:col-span-4'}>
<p className={'pb-2 text-lg text-neutral-900 md:pb-6 md:text-3xl'}>{'Earnings'}</p>
<b className={'font-number text-3xl text-neutral-900 md:text-7xl'}>
<ValueAnimation
identifier={'youEarned'}
value={formatedYouEarned}
defaultValue={'0,00'}
prefix={'$'}
/>
<Counter value={Number(formatedYouEarned)} />
</b>
</div>
</Fragment>
Expand Down

0 comments on commit 70dcd38

Please sign in to comment.