Skip to content

Commit

Permalink
revert bdb1506 and improve solution
Browse files Browse the repository at this point in the history
  • Loading branch information
pivilartisant committed Jun 4, 2024
1 parent b8c68ff commit 3bb8b3f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/components/Status/ChainStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useAccount } from 'wagmi';
import { Connected, Disconnected, WrongChain } from '.';
import { Blockchain, SupportedEvmBlockchain } from '@/const';
import { Blockchain } from '@/const';
import {
ChainContext,
useEvmChainValidation,
Expand All @@ -9,7 +9,7 @@ import {
import { useAccountStore } from '@/store/store';

interface ChainStatusProps {
blockchain: Blockchain | SupportedEvmBlockchain;
blockchain: Blockchain;
context: ChainContext;
}

Expand Down
8 changes: 2 additions & 6 deletions src/components/Status/WrongChain/WrongChain.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { Tag, Tooltip } from '@massalabs/react-ui-kit';
import {
Blockchain,
SUPPORTED_MASSA_WALLETS,
SupportedEvmBlockchain,
} from '@/const';
import { Blockchain, SUPPORTED_MASSA_WALLETS } from '@/const';
import Intl from '@/i18n/i18n';
import { useAccountStore, useBridgeModeStore } from '@/store/store';
import { tagTypes } from '@/utils/const';

interface WrongChainProps {
blockchain: Blockchain | SupportedEvmBlockchain;
blockchain: Blockchain;
}

export function WrongChain(props: WrongChainProps) {
Expand Down
7 changes: 4 additions & 3 deletions src/custom/bridge/useClaim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useCallback } from 'react';
import { useWaitForTransactionReceipt, useWriteContract } from 'wagmi';
import { useConnectedEvmChain } from './useConnectedEvmChain';
import bridgeVaultAbi from '@/abi/bridgeAbi.json';
import { config } from '@/const/const';
import { SupportedEvmBlockchain, config } from '@/const/const';
import { useBridgeModeStore, useOperationStore } from '@/store/store';
import { getMinConfirmation } from '@/utils/utils';

Expand All @@ -19,8 +19,9 @@ export function useClaim() {
const { selectedEvm } = useOperationStore();
const chain = useConnectedEvmChain();

// selected evm is what we want when context is bridge; when claim page we want the connected chain
const bridgeContractAddr = config[currentMode][chain];
// Conversion to type unkown is necessary because type Blockchain and SupportedEvmBlockchin don't overlap enough
const bridgeContractAddr =
config[currentMode][chain as unknown as SupportedEvmBlockchain];

const { data: hash, writeContract, error, isPending } = useWriteContract();

Expand Down
15 changes: 8 additions & 7 deletions src/custom/bridge/useConnectedEvmChain.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useAccount } from 'wagmi';
import { bsc, bscTestnet } from 'wagmi/chains';
import { SupportedEvmBlockchain } from '@/const';
import { bsc, bscTestnet, mainnet, sepolia } from 'wagmi/chains';
import { Blockchain } from '@/const';

export function useConnectedEvmChain(): SupportedEvmBlockchain {
export function useConnectedEvmChain(): Blockchain {
const { chain } = useAccount();
if (chain?.id === bsc.id || chain?.id === bscTestnet.id) {
return SupportedEvmBlockchain.BSC;
}
return SupportedEvmBlockchain.ETH;
if (chain?.id === bsc.id || chain?.id === bscTestnet.id)
return Blockchain.BSC;
if (chain?.id === mainnet.id || chain?.id === sepolia.id)
return Blockchain.ETHEREUM;
return Blockchain.UNKNOWN;
}
4 changes: 2 additions & 2 deletions src/layouts/LayoutBridge/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useAccount } from 'wagmi';
import { BridgeLogo } from '@/assets/BridgeLogo';
import { Banner } from '@/components';
import { Tos } from '@/components/Tos';
import { PAGES, SupportedEvmBlockchain } from '@/const';
import { Blockchain, PAGES } from '@/const';
import { useConnectedEvmChain } from '@/custom/bridge/useConnectedEvmChain';
import {
useEvmChainValidation,
Expand Down Expand Up @@ -134,7 +134,7 @@ export function Navbar(props: NavbarProps) {
</div>
</div>
<Tos />
{currentEvmChain === SupportedEvmBlockchain.BSC && (
{currentEvmChain === Blockchain.BSC && (
<Banner>
{Intl.t('dao-maker.dao-bridge-redeem-warning')}{' '}
<Link to={`/${PAGES.DAO}`}>
Expand Down

0 comments on commit 3bb8b3f

Please sign in to comment.