Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add base #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions packages/gimme/components/Earn/SelectVault.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Fragment, type ReactElement, useCallback, useMemo, useState} from 'react';
import {useWeb3} from '@builtbymom/web3/contexts/useWeb3';
import {cl, formatPercent, numberSort, zeroNormalizedBN} from '@builtbymom/web3/utils';
import {Dialog, DialogPanel, Transition, TransitionChild} from '@headlessui/react';
import * as Popover from '@radix-ui/react-popover';
Expand Down Expand Up @@ -170,6 +171,7 @@ export function SelectVault({
onSelect: (value: TYDaemonVault) => void;
availableVaults: TYDaemonVault[];
}): ReactElement {
const {chainID} = useWeb3();
const {configuration} = useDepositSolver();
const {getPrice} = usePrices();
const [vaultInfo, set_vaultInfo] = useState<TVaultInfoModal>(undefined);
Expand Down Expand Up @@ -207,6 +209,11 @@ export function SelectVault({
);
}, [filteredVaults, sortDirection]);

const filteredByChain = useMemo(() => {
return sortedVaults.filter(vault => vault.chainID === chainID);
}, [chainID, sortedVaults]);
const isEmpty = filteredByChain.length === 0;

const onChangeSort = useCallback(() => {
if (sortDirection === '') {
set_sortDirection('desc');
Expand Down Expand Up @@ -323,16 +330,24 @@ export function SelectVault({
</div>
</div>
<div className={'scrollable flex size-full flex-col gap-2 md:h-96'}>
{sortedVaults.map(vault => (
<Vault
key={`${vault.address}-${vault.chainID}`}
vault={vault}
assetPrice={assetPrice}
onSelect={onSelect}
onClose={onClose}
onChangeVaultInfo={set_vaultInfo}
/>
))}
{isEmpty ? (
<p className={'text-grey-700 mt-20'}>
{
'Sorry! No opportunities found. Try switching the network.'
}
</p>
) : (
filteredByChain.map(vault => (
<Vault
key={`${vault.address}-${vault.chainID}`}
vault={vault}
assetPrice={assetPrice}
onSelect={onSelect}
onClose={onClose}
onChangeVaultInfo={set_vaultInfo}
/>
))
)}
</div>
</DialogPanel>

Expand Down
48 changes: 29 additions & 19 deletions packages/gimme/components/Portfolio/VaultRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,40 @@ export function VaultRow(props: {
}
};

const onWithdraw = (): void => {
dispatchConfiguration({
type: 'SET_CONFIGURATION',
payload: {
vault: props.vault,
asset: {
UUID: crypto.randomUUID(),
amount: props.balance.display,
normalizedBigAmount: props.balance,
status: 'none',
isValid: true,
error: undefined,
token: {
const onWithdraw = async (): Promise<void> => {
try {
dispatchConfiguration({
type: 'SET_CONFIGURATION',
payload: {
vault: props.vault,
asset: {
UUID: crypto.randomUUID(),
amount: props.balance.display,
normalizedBigAmount: props.balance,
status: 'none',
isValid: true,
error: undefined,
token: {
...props.vault.token,
chainID: props.vault.chainID,
value: 0,
balance: props.balance
}
},
tokenToReceive: {
...props.vault.token,
chainID: props.vault.chainID,
value: 0,
balance: props.balance
}
},
tokenToReceive: {...props.vault.token, chainID: props.vault.chainID, value: 0, balance: props.balance}
}
});
plausible(PLAUSIBLE_EVENTS.OPEN_WITHDRAW_MODAL);
props.onWithdrawModalChange(true);
}
});
plausible(PLAUSIBLE_EVENTS.OPEN_WITHDRAW_MODAL);
await switchChainAsync({connector, chainId: props.vault.chainID});
props.onWithdrawModalChange(true);
} catch (err) {
console.log(err);
}
};

return (
Expand Down
7 changes: 6 additions & 1 deletion packages/gimme/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ function MyApp(props: AppProps): ReactElement {
<WithMom
supportedChains={supportedNetworksWithMainnet}
defaultNetwork={supportedNetworks[0]}
tokenLists={['https://raw.githubusercontent.com/SmolDapp/tokenLists/main/lists/137/yearn-min.json']}>
tokenLists={[
'https://raw.githubusercontent.com/SmolDapp/tokenLists/main/lists/137.json',
'https://raw.githubusercontent.com/SmolDapp/tokenLists/main/lists/137/yearn-min.json',
'https://raw.githubusercontent.com/SmolDapp/tokenLists/main/lists/8453.json',
'https://raw.githubusercontent.com/SmolDapp/tokenLists/main/lists/8453/yearn-min.json'
]}>
<WalletContextApp>
<WithPopularTokens>
<WithPrices supportedNetworks={supportedNetworks}>
Expand Down
8 changes: 3 additions & 5 deletions packages/lib/common/NetworkPopoverSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ export function NetworkPopoverSelector(props: {networks?: Chain[]}): ReactElemen
const isDev = process.env.NODE_ENV === 'development' && Boolean(process.env.SHOULD_USE_FORKNET);

const currentNetwork = useMemo(() => {
const currentNetwork = networks.find(
const currentNetwork = supportedNetworks.find(
(network): boolean => network.id === safeChainID || (isDev && network.id === chainID)
);
if (!currentNetwork) {
return networks[0];
}

return currentNetwork;
}, [networks, safeChainID, isDev, chainID]);
}, [safeChainID, isDev, chainID]);

const [isOpen, set_isOpen] = useState(false);

Expand Down
4 changes: 2 additions & 2 deletions packages/lib/common/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Image from 'next/image';
import Link from 'next/link';
import {type Router, useRouter} from 'next/router';
import {usePlausible} from 'next-plausible';
import {polygon} from 'wagmi/chains';
import {base, polygon} from 'wagmi/chains';
import {useWeb3} from '@builtbymom/web3/contexts/useWeb3';
import {cl, truncateHex} from '@builtbymom/web3/utils';
import {useAccountModal} from '@rainbow-me/rainbowkit';
Expand Down Expand Up @@ -89,7 +89,7 @@ function WalletSection(): ReactElement {
'flex items-center justify-center gap-3 rounded-2xl border border-white bg-white/60 py-0 pl-2 backdrop-blur-md md:border-none md:bg-transparent md:p-0',
'md:py-2 md:backdrop-filter-none'
)}>
<NetworkPopoverSelector networks={[polygon]} />
<NetworkPopoverSelector networks={[polygon, base]} />
<button
onClick={(): void => {
openAccountModal?.();
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/contexts/useVaults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const VaultsContext = createContext<TVaultsContext>({

export const VaultsContextApp = memo(function VaultsContextApp({children}: {children: ReactElement}): ReactElement {
const {data: gimmeVaults, isLoading: isLoadingVaults} = useSWR<TYDaemonVault[]>(
'https://ydaemon.yearn.fi/vaults/gimme?chainIDs=137', // Persist on displaying polygon vaults
'https://ydaemon.yearn.fi/vaults/gimme', // Persist on displaying polygon vaults
Majorfi marked this conversation as resolved.
Show resolved Hide resolved
baseFetcher
);

Expand Down
19 changes: 12 additions & 7 deletions packages/lib/utils/tools.chains.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/* eslint-disable object-curly-newline */
'use client';

import {
mainnet,
polygon
} from 'viem/chains';
import {base, mainnet, polygon} from 'viem/chains';
import {toAddress} from '@builtbymom/web3/utils';
import {localhost} from '@builtbymom/web3/utils/wagmi';

Expand All @@ -22,7 +19,6 @@ type TSmolChains = TNDict<
}
>;


const isDev = process.env.NODE_ENV === 'development' && Boolean(process.env.SHOULD_USE_FORKNET);
const CHAINS: TSmolChains = {
[mainnet.id]: {
Expand All @@ -32,7 +28,7 @@ const CHAINS: TSmolChains = {
coingeckoGasCoinID: 'ethereum',
llamaChainName: 'ethereum',
yearnRouterAddress: toAddress('0x1112dbcf805682e828606f74ab717abf4b4fd8de'),
isEnabled: false
isEnabled: true
},
[polygon.id]: {
...polygon,
Expand All @@ -43,6 +39,15 @@ const CHAINS: TSmolChains = {
yearnRouterAddress: toAddress('0x1112dbcf805682e828606f74ab717abf4b4fd8de'),
isEnabled: true
},
[base.id]: {
...base,
safeAPIURI: 'https://safe-transaction-base.safe.global',
safeUIURI: 'https://app.safe.global/home?safe=base:',
coingeckoGasCoinID: 'ethereum',
llamaChainName: 'base',
yearnRouterAddress: toAddress('0x1112dbcf805682e828606f74ab717abf4b4fd8de'),
isEnabled: true
},
[localhost.id]: {
...localhost,
safeUIURI: 'https://app.safe.global/home?safe=eth:',
Expand All @@ -58,4 +63,4 @@ const supportedTestNetworks: Chain[] = Object.values(CHAINS).filter(e => e.testn
const networks: Chain[] = [...supportedNetworks, ...supportedTestNetworks];
const supportedNetworksWithMainnet = [CHAINS[mainnet.id], ...supportedNetworks];

export {CHAINS, isDev, networks, supportedNetworks, supportedNetworksWithMainnet,supportedTestNetworks};
export {CHAINS, isDev, networks, supportedNetworks, supportedNetworksWithMainnet, supportedTestNetworks};