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

fix: hide cowswap solver on sidechains #262

Merged
merged 2 commits into from
Jul 1, 2023
Merged
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
36 changes: 23 additions & 13 deletions apps/vaults/components/SettingsPopover.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import {Fragment} from 'react';
import {Fragment, useMemo} from 'react';
import {Popover, Transition} from '@headlessui/react';
import {isSolverDisabled} from '@vaults/contexts/useSolver';
import Renderable from '@yearn-finance/web-lib/components/Renderable';
import {useChainID} from '@yearn-finance/web-lib/hooks/useChainID';
import IconSettings from '@yearn-finance/web-lib/icons/IconSettings';
import {useYearn} from '@common/contexts/useYearn';
import {Solver} from '@common/schemas/yDaemonTokenListBalances';

import type {ReactElement} from 'react';
import type {TSolver} from '@common/schemas/yDaemonTokenListBalances';

export default function SettingsPopover(): ReactElement {
const {chainID} = useChainID();
type TSettingPopover = {
chainID: number
}
export default function SettingsPopover({chainID}: TSettingPopover): ReactElement {
const {zapProvider, set_zapProvider, zapSlippage, set_zapSlippage} = useYearn();

const currentZapProvider = useMemo((): TSolver => {
if (chainID !== 1 && zapProvider === 'Cowswap') {
return 'Wido';
}
Comment on lines +19 to +21
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If not 1 and Cowswap, switch back to second solver, aka Wido

Copy link
Member

Choose a reason for hiding this comment

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

Wondering if we can have a more centralized place to decide when or which network a zap should be enabled, that way we could keep the logic as is and just disable the zap for specific networks. Wdyt?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should probably be refactored at some point yes.

return zapProvider;
}, [chainID, zapProvider]);

return (
<Popover className={'relative flex'}>
{(): ReactElement => (
Expand All @@ -38,13 +46,15 @@ export default function SettingsPopover(): ReactElement {
<select
id={'zapProvider'}
onChange={(e): void => set_zapProvider(e.target.value as TSolver)}
value={zapProvider}
value={currentZapProvider}
className={'mt-1 h-10 w-full overflow-x-scroll border-none bg-neutral-100 p-2 outline-none scrollbar-none'}>
<option
disabled={isSolverDisabled[Solver.enum.Cowswap]}
value={Solver.enum.Cowswap}>
{Solver.enum.Cowswap}
</option>
{chainID === 1 ? (
Copy link
Member

Choose a reason for hiding this comment

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

Would this logic be better in isSolverDisabled?

<option
disabled={isSolverDisabled[Solver.enum.Cowswap]}
value={Solver.enum.Cowswap}>
{Solver.enum.Cowswap}
</option>
): null}
<option
disabled={isSolverDisabled[Solver.enum.Wido]}
value={Solver.enum.Wido}>
Expand All @@ -56,7 +66,7 @@ export default function SettingsPopover(): ReactElement {
{Solver.enum.Portals}
</option>
</select>
<Renderable shouldRender={zapProvider === Solver.enum.Cowswap}>
<Renderable shouldRender={currentZapProvider === Solver.enum.Cowswap}>
<legend className={'text-xs italic text-neutral-500'}>
{'Submit a'}&nbsp;
<a
Expand All @@ -69,7 +79,7 @@ export default function SettingsPopover(): ReactElement {
&nbsp;{'using CoW Swap.'}
</legend>
</Renderable>
<Renderable shouldRender={zapProvider === Solver.enum.Wido}>
<Renderable shouldRender={currentZapProvider === Solver.enum.Wido}>
<legend className={'text-xs italic text-neutral-500'}>
{'Submit an order via'}&nbsp;
<a
Expand All @@ -82,7 +92,7 @@ export default function SettingsPopover(): ReactElement {
&nbsp;{'(0.3% fee).'}
</legend>
</Renderable>
<Renderable shouldRender={zapProvider === Solver.enum.Portals}>
<Renderable shouldRender={currentZapProvider === Solver.enum.Portals}>
<legend>&nbsp;</legend>
</Renderable>
</div>
Expand Down
2 changes: 1 addition & 1 deletion apps/vaults/components/details/VaultActionsTabsWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ function VaultActionsTabsWrapper({currentVault}: {currentVault: TYDaemonVault}):
</div>

<div className={'flex flex-row items-center justify-end space-x-2 pb-0 md:pb-4 md:last:space-x-4'}>
<SettingsPopover />
<SettingsPopover chainID={currentVault.chainID} />
Majorfi marked this conversation as resolved.
Show resolved Hide resolved
</div>
</div>
<div className={'-mt-0.5 h-0.5 w-full bg-neutral-300'} />
Expand Down