Skip to content

Commit

Permalink
fix: switch chain
Browse files Browse the repository at this point in the history
  • Loading branch information
rhlsthrm committed Oct 25, 2024
1 parent 8e1d2f5 commit beecb66
Showing 1 changed file with 33 additions and 17 deletions.
50 changes: 33 additions & 17 deletions packages/ui/app/_components/dashboards/InfoRows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import { useMemo, type Dispatch, type SetStateAction } from 'react';

import dynamic from 'next/dynamic';

import { useChainId } from 'wagmi';

import { FLYWHEEL_TYPE_MAP, pools } from '@ui/constants/index';
import { multipliers } from '@ui/utils/multipliers';
import { handleSwitchOriginChain } from '@ui/utils/NetworkChecker';

import { getAssetName } from '../../util/utils';
// import { Rewards } from '../markets/Rewards';
Expand Down Expand Up @@ -61,6 +64,7 @@ const InfoRows = ({
toggler,
setCollateralSwapFromAsset
}: InfoRowsProps) => {
const walletChain = useChainId();
const supplyRewards = useMemo(
() =>
rewards?.filter((reward) =>
Expand Down Expand Up @@ -201,31 +205,43 @@ const InfoRows = ({
>
<button
className={`w-full uppercase rounded-lg bg-accent text-black py-1.5 px-3`}
onClick={() => {
setSelectedSymbol(asset);
setPopupMode(
mode === InfoMode.SUPPLY ? PopupMode.SUPPLY : PopupMode.REPAY
onClick={async () => {
const result = await handleSwitchOriginChain(
selectedChain,
walletChain
);
if (result) {
setSelectedSymbol(asset);
setPopupMode(
mode === InfoMode.SUPPLY ? PopupMode.SUPPLY : PopupMode.REPAY
);
}
}}
>
{mode === InfoMode.SUPPLY ? 'Withdraw / Add Collateral' : 'Repay'}
</button>

<button
className={`w-full uppercase ${pools[+selectedChain].text} ${pools[+selectedChain].bg} rounded-lg text-black py-1.5 px-3`}
onClick={() => {
if (mode === InfoMode.SUPPLY) {
// Router.push()
//toggle the mode
setSelectedSymbol(asset);
setCollateralSwapFromAsset?.();
toggler?.();
}
if (mode === InfoMode.BORROW) {
// Router.push()
// toggle the mode
setSelectedSymbol(asset);
setPopupMode(PopupMode.BORROW);
onClick={async () => {
const result = await handleSwitchOriginChain(
selectedChain,
walletChain
);
if (result) {
if (mode === InfoMode.SUPPLY) {
// Router.push()
//toggle the mode
setSelectedSymbol(asset);
setCollateralSwapFromAsset?.();
toggler?.();
}
if (mode === InfoMode.BORROW) {
// Router.push()
// toggle the mode
setSelectedSymbol(asset);
setPopupMode(PopupMode.BORROW);
}
}
}}
>
Expand Down

0 comments on commit beecb66

Please sign in to comment.