Skip to content

Commit

Permalink
feat: rsk amm fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
creed-victor committed May 15, 2024
1 parent 6501611 commit e5cfb97
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { FC } from 'react';

import { RSK_CHAIN_ID } from '../../../config/chains';

import { CrocContextProvider } from '../../../contexts/CrocContext';
import { useCurrentChain } from '../../../hooks/useChainStore';
import { AmbientMarketMaking } from './components/AmbientMarketMaking/AmbientMarketMaking';
import { MarketMaking } from './components/MarketMaking/MarketMaking';
Expand All @@ -10,7 +11,11 @@ const MarketMakingPage: FC = () => {
const currentChainId = useCurrentChain();

if (currentChainId !== RSK_CHAIN_ID) {
return <AmbientMarketMaking />;
return (
<CrocContextProvider>
<AmbientMarketMaking />
</CrocContextProvider>
);
}
return <MarketMaking />;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ import { Decimal } from '@sovryn/utils';

import { useAccount } from '../../../../../../../hooks/useAccount';
import { useBlockNumber } from '../../../../../../../hooks/useBlockNumber';
import { useCurrentChain } from '../../../../../../../hooks/useChainStore';
import { useMaintenance } from '../../../../../../../hooks/useMaintenance';
import { translations } from '../../../../../../../locales/i18n';
import { COMMON_SYMBOLS } from '../../../../../../../utils/asset';
import { getChainById } from '../../../../../../../utils/chain';
import { useCheckPoolMaintenance } from '../../../../hooks/useCheckPoolMaintenance';
import { useGetUserInfo } from '../../../../hooks/useGetUserInfo';
import { AmmLiquidityPool } from '../../../../utils/AmmLiquidityPool';
Expand All @@ -28,10 +26,6 @@ type PoolsTableActionProps = {
};

export const PoolsTableAction: FC<PoolsTableActionProps> = ({ pool }) => {
const chainId = useCurrentChain();
const chain = useMemo(() => getChainById(chainId), [chainId]);
const isBobChain = useMemo(() => chain?.label === 'BOB', [chain?.label]);

const { account } = useAccount();
const { value: block } = useBlockNumber();

Expand Down Expand Up @@ -116,7 +110,7 @@ export const PoolsTableAction: FC<PoolsTableActionProps> = ({ pool }) => {
style={ButtonStyle.primary}
size={ButtonSize.small}
text={
isBobChain && pool.assetA === COMMON_SYMBOLS.SOV
pool.assetA === COMMON_SYMBOLS.SOV
? t(translations.common.withdraw)
: t(translations.common.deposit)
}
Expand All @@ -139,16 +133,13 @@ export const PoolsTableAction: FC<PoolsTableActionProps> = ({ pool }) => {
onClick={handleAdjustClick}
/>
)}
<p>{actionLocked && 'action locked'}</p>
</>
}
/>

<AdjustAndDepositModal
isOpen={
isModalOpen &&
isBobChain &&
![COMMON_SYMBOLS.DLLR, COMMON_SYMBOLS.SOV].includes(pool.assetA)
}
isOpen={isModalOpen}
onClose={handleClose}
pool={pool}
isInitialDeposit={isInitialDeposit}
Expand Down
10 changes: 2 additions & 8 deletions apps/frontend/src/constants/infrastructure/rsk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@ import { Environments } from '../../types/global';

export const RSK = {
rpc: {
[Environments.Mainnet]: [
'https://rsk-live.sovryn.app/rpc',
'https://public-node.rsk.co',
],
[Environments.Testnet]: [
'https://testnet.sovryn.app/rpc',
'https://public-node.testnet.rsk.co',
],
[Environments.Mainnet]: ['https://rsk-live.sovryn.app/rpc'],
[Environments.Testnet]: ['https://testnet.sovryn.app/rpc'],
},
publicRpc: {
[Environments.Mainnet]: 'https://mainnet.sovryn.app/rpc',
Expand Down
5 changes: 3 additions & 2 deletions apps/frontend/src/contexts/CrocContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import React, {
useState,
} from 'react';

import { CrocEnv } from '@sovryn/sdex';
import { getProvider } from '@sovryn/ethers-provider';
import { CrocEnv } from '@sovryn/sdex';

import { useAccount } from '../hooks/useAccount';
import { useCurrentChain } from '../hooks/useChainStore';
import { isBobChain } from '../utils/chain';

type CrocContextValue = {
croc?: CrocEnv;
Expand All @@ -31,7 +32,7 @@ export const CrocContextProvider: FC<PropsWithChildren> = ({ children }) => {
const [croc, setCroc] = useState(defaultContextValue.croc);

useEffect(() => {
if (!croc && account) {
if (!croc && account && isBobChain(chainId)) {
setCroc(new CrocEnv(getProvider(chainId), signer));
}
}, [croc, signer, account, chainId]);
Expand Down
6 changes: 1 addition & 5 deletions apps/frontend/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,7 @@ const routes = [
},
{
path: '/earn/market-making',
element: (
<CrocContextProvider>
<MarketMakingPage />
</CrocContextProvider>
),
element: <MarketMakingPage />,
},
{
path: '/earn',
Expand Down

0 comments on commit e5cfb97

Please sign in to comment.