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: enable gas sufficiency check for SAFE #142

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 1 addition & 4 deletions packages/widget/src/components/GasMessage/GasMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { Route } from '@lifi/sdk';
import type { BoxProps } from '@mui/material';
import { Box, Collapse } from '@mui/material';
import { useFromTokenSufficiency, useGasSufficiency } from '../../hooks';
import { useWidgetConfig } from '../../providers';
import { FundsSufficiencyMessage } from './FundsSufficiencyMessage';
import { GasSufficiencyMessage } from './GasSufficiencyMessage';

Expand All @@ -13,10 +12,8 @@ interface GasMessageProps extends BoxProps {
export const GasMessage: React.FC<GasMessageProps> = ({ route, ...props }) => {
const { insufficientGas } = useGasSufficiency(route);
const { insufficientFromToken } = useFromTokenSufficiency(route);
const { sdkConfig } = useWidgetConfig();
const isMultisigSigner = sdkConfig?.multisigConfig?.isMultisigSigner;

const validInsufficientGas = insufficientGas?.length && !isMultisigSigner;
const validInsufficientGas = insufficientGas?.length;

return (
<Collapse
Expand Down
6 changes: 4 additions & 2 deletions packages/widget/src/hooks/useGasSufficiency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { EVMChain, Route, Token } from '@lifi/sdk';
import { useQuery } from '@tanstack/react-query';
import Big from 'big.js';
import { useChains, useGasRefuel, useGetTokenBalancesWithRetry } from '.';
import { useWallet } from '../providers';
import { useWallet, useWidgetConfig } from '../providers';
import { useSettings } from '../stores';

export interface GasSufficiency {
Expand All @@ -22,6 +22,8 @@ export const useGasSufficiency = (route?: Route) => {
const getTokenBalancesWithRetry = useGetTokenBalancesWithRetry(
account.signer?.provider,
);
const { sdkConfig } = useWidgetConfig();
const isMultisigSigner = sdkConfig?.multisigConfig?.isMultisigSigner;

const { enabledAutoRefuel } = useSettings(['enabledAutoRefuel']);
const { enabled, isLoading: isRefuelLoading } = useGasRefuel();
Expand All @@ -43,7 +45,7 @@ export const useGasSufficiency = (route?: Route) => {
.filter((step) => !step.execution || step.execution.status !== 'DONE')
.reduce(
(groupedGasCosts, step) => {
if (step.estimate.gasCosts) {
if (step.estimate.gasCosts && !isMultisigSigner) {
const { token } = step.estimate.gasCosts[0];
const gasCostAmount = step.estimate.gasCosts
.reduce(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
useGasSufficiency,
useRoutes,
} from '../../hooks';
import { useWidgetConfig } from '../../providers';
import { useRouteExecutionStore } from '../../stores';
import type { StartTransactionButtonProps } from './types';

Expand All @@ -14,9 +13,6 @@ export const StartTransactionButton: React.FC<StartTransactionButtonProps> = ({
text,
loading,
}) => {
const { sdkConfig } = useWidgetConfig();
const isMultisigSigner = sdkConfig?.multisigConfig?.isMultisigSigner;

const { insufficientGas, isInitialLoading: isGasSufficiencyLoading } =
useGasSufficiency(route);
const {
Expand All @@ -25,7 +21,7 @@ export const StartTransactionButton: React.FC<StartTransactionButtonProps> = ({
} = useFromTokenSufficiency(route);

const shouldDisableButton =
!isMultisigSigner && (insufficientFromToken || !!insufficientGas?.length);
insufficientFromToken || !!insufficientGas?.length;

return (
<DefaultTransactionButton
Expand Down