Skip to content

Commit

Permalink
fix: enable gas sufficiency check for SAFE (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhikumar98 authored Oct 16, 2023
1 parent 439d34f commit a2030cf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
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 (
<BaseTransactionButton
Expand Down

0 comments on commit a2030cf

Please sign in to comment.