e463bbe238
* feat: unhardcode contract addresses * fix: linting and tests * feat: switch contract usage in token app to use unhardcoded addresses * chore: remove other usage of hard coded contract addresses * feat: convert contracts to classes, update claim contract to fix circular dependency * feat: add hard coded contract addresses to contracts page * fix: misc tidy up * chore: rename ethers big num conversion func * fix: remove pending transactions modal * chore: add single toBigNum function that can accept number string or EthersBignNumber * chore: delete unused tranche helpers and decimals functions from smart contracts lib * feat: add faucetable token class * fix: reset tx state after early exit from approve tx * feat: re add transaction modal using zustand store * fix: loader colors for eth wallet * fix: pass ethereum config to gurantee existence before tx execution * chore: lint smart contracts lib * chore: fix web3container to use children and not render prop * chore: lint * fix: use background to mock ethereum wallet to avoid mocking globally for every test * chore: move web3 mock to common steps and call from withdrawals feature tests
65 lines
1.3 KiB
TypeScript
65 lines
1.3 KiB
TypeScript
import { gql, useQuery } from '@apollo/client';
|
|
import { useMemo } from 'react';
|
|
import type { NetworkParamsQuery } from './__generated__/NetworkParamsQuery';
|
|
|
|
export interface EthereumConfig {
|
|
network_id: string;
|
|
chain_id: string;
|
|
confirmations: number;
|
|
collateral_bridge_contract: {
|
|
address: string;
|
|
};
|
|
multisig_control_contract: {
|
|
address: string;
|
|
deployment_block_height: number;
|
|
};
|
|
staking_bridge_contract: {
|
|
address: string;
|
|
deployment_block_height: number;
|
|
};
|
|
token_vesting_contract: {
|
|
address: string;
|
|
deployment_block_height: number;
|
|
};
|
|
}
|
|
|
|
export const NETWORK_PARAMS_QUERY = gql`
|
|
query NetworkParamsQuery {
|
|
networkParameters {
|
|
key
|
|
value
|
|
}
|
|
}
|
|
`;
|
|
|
|
export const useEthereumConfig = () => {
|
|
const { data, loading, error } =
|
|
useQuery<NetworkParamsQuery>(NETWORK_PARAMS_QUERY);
|
|
|
|
const config = useMemo(() => {
|
|
if (!data) {
|
|
return null;
|
|
}
|
|
|
|
const param = data.networkParameters?.find(
|
|
(np) => np.key === 'blockchains.ethereumConfig'
|
|
);
|
|
|
|
if (!param) {
|
|
return null;
|
|
}
|
|
|
|
let parsedConfig: EthereumConfig;
|
|
|
|
try {
|
|
parsedConfig = JSON.parse(param.value);
|
|
} catch {
|
|
return null;
|
|
}
|
|
|
|
return parsedConfig;
|
|
}, [data]);
|
|
|
|
return { config, loading, error };
|
|
};
|