Skip to content

Commit

Permalink
Insufficient Gas (#5932)
Browse files Browse the repository at this point in the history
* Insufficient Gas

* Update bitrise.yml with latest from bitrise.io (#5940)

* insufficient native symbol

* Prevent crashing on remote cards code (#5924)

* Return undefined from cards store if data is missing

* deal with undefined card obj

---------

Co-authored-by: Christian Baroni <[email protected]>

* fix keyboard dismisses option to copy contract address or view on etherscan (#5908)

* fix

* keyboardShouldPersistTaps

* ContextMenuButton

* Simplify SwapInputController animated reaction logic for responding to input value changes (#5923)

* Remove redundant sliderXPosition update in debounced onTypedNumber

* Remove redundant preservedAmount argument in onTypedNumber as the default is true

* Pull out resetToZero as its own worklet to reduce redundant code

* Remove unnecessary check for amount > 0 now that onTypedNumber is only used for when the amount is > 0

* Replace onTypedNumber with debouncedFetchQuote function

* Pull out variables for prev input / output native values for code readability

* Calculate native value based on the new amounts and native prices to be more accurate

* Simplify resetToZeroValues logic

* Convert swap warning to derived value (#5930)

* Convert swap warning to derived value

* Move out noWarning to NO_WARNING out of derived value

* Tidy up swapInputsController repeated logic around `niceIncrementFormatter` (#5931)

* Simplify the calls to niceIncrementFormatter

Also removes the niceIncrementFormatter call in formattedInputAmount
since the input amount has already been set using the
niceIncrementFormatter for the cases it cares about.

* Remove incrementDecimalPlaces and niceIncrement as shared values as they are only used in the niceIncrementFormatter function

* Upgrade react-native-gesture-handler to v2.17.1 (#5925)

* Upgrade reanimated to fix crash

* Fix type errors from reanimated upgrade

* lint

* Fix HourglassAnimation

* Revert "move nft fetching logic to graphql worker (#5421)"

This reverts commit fff25a6.

* Bump reanimated to v3.7.1

* Upgrade react-native-gesture-handler to v2.15.0

* Imports

* Android

* Merge branch '@christian/upgrade-reanimated' into @christian/upgrade-gesture-handler

* Fix android build - remove old reanimated shim

* Fix RNGH and ZoomableButton

Couldn't get these changes to apply via patch-package, so at least for now had to fork RNGH to apply them:

rainbow-me/react-native-gesture-handler@0c4b8be

* Fix RNGH install

* Bump RNGH, bump reanimated patch

* Patch GH instead of forking

* Fix native Android ZoomableButton

Will follow up with some code cleanup but everything should be working.

This also removes a bunch of unnecessary wrapper views and layout recalculations in the Android ButtonPressAnimation component.

* Delete unneeded @ts-expect-errors

* Remove unneeded @ts-expect-error

---------

Co-authored-by: Ben Goldberg <[email protected]>
Co-authored-by: Ibrahim Taveras <[email protected]>

* Update inputMethod to inputAmount anytime the asset changes (#5934)

* Update bitrise.yml with latest from bitrise.io (#5940)

* :)

* Update src/languages/en_US.json

Co-authored-by: Matthew Wall <[email protected]>

* Update src/__swaps__/screens/Swap/providers/swap-provider.tsx

Co-authored-by: Matthew Wall <[email protected]>

* Update src/__swaps__/screens/Swap/providers/swap-provider.tsx

Co-authored-by: Matthew Wall <[email protected]>

* ah😮

* Update src/__swaps__/screens/Swap/providers/swap-provider.tsx

Co-authored-by: Matthew Wall <[email protected]>

* idk

---------

Co-authored-by: Jin <[email protected]>
Co-authored-by: Bruno Barbieri <[email protected]>
Co-authored-by: Christian Baroni <[email protected]>
Co-authored-by: Ben Goldberg <[email protected]>
Co-authored-by: Ibrahim Taveras <[email protected]>
Co-authored-by: Matthew Wall <[email protected]>
  • Loading branch information
7 people authored Jul 22, 2024
1 parent 87d5fd1 commit e8529d2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { calculateGasFee } from '../hooks/useEstimatedGasFee';
import { useSelectedGas } from '../hooks/useSelectedGas';
import { useSwapEstimatedGasLimit } from '../hooks/useSwapEstimatedGasLimit';
import { useSwapContext } from './swap-provider';
import { lessThan } from '@/helpers/utilities';

const BUFFER_RATIO = 0.5;

Expand Down Expand Up @@ -93,7 +92,7 @@ export function SyncGasStateToSharedValues() {
const { assetToSell, chainId = ChainId.mainnet, quote } = useSyncedSwapQuoteStore();

const gasSettings = useSelectedGas(chainId);
const { data: userNativeNetworkAsset } = useUserNativeNetworkAsset(chainId);
const { data: userNativeNetworkAsset, isLoading: isLoadingNativeNetworkAsset } = useUserNativeNetworkAsset(chainId);
const { data: estimatedGasLimit } = useSwapEstimatedGasLimit({ chainId, assetToSell, quote });

const gasFeeRange = useSharedValue<[string, string] | null>(null);
Expand Down Expand Up @@ -128,7 +127,12 @@ export function SyncGasStateToSharedValues() {

useEffect(() => {
hasEnoughFundsForGas.value = undefined;
if (!gasSettings || !estimatedGasLimit || !quote || 'error' in quote || !userNativeNetworkAsset) return;
if (!gasSettings || !estimatedGasLimit || !quote || 'error' in quote || isLoadingNativeNetworkAsset) return;

if (!userNativeNetworkAsset) {
hasEnoughFundsForGas.value = false;
return;
}

const gasFee = calculateGasFee(gasSettings, estimatedGasLimit);

Expand All @@ -151,7 +155,16 @@ export function SyncGasStateToSharedValues() {
return () => {
hasEnoughFundsForGas.value = undefined;
};
}, [estimatedGasLimit, gasFeeRange, gasSettings, hasEnoughFundsForGas, quote, userNativeNetworkAsset]);
}, [
estimatedGasLimit,
gasFeeRange,
gasSettings,
hasEnoughFundsForGas,
quote,
userNativeNetworkAsset,
isLoadingNativeNetworkAsset,
chainId,
]);

return null;
}
11 changes: 8 additions & 3 deletions src/__swaps__/screens/Swap/providers/swap-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { RainbowError, logger } from '@/logger';
import { loadWallet } from '@/model/wallet';
import { Navigation } from '@/navigation';
import Routes from '@/navigation/routesNames';
import { getNetworkObj } from '@/networks';
import { RainbowNetworkByChainId, getNetworkObj } from '@/networks';
import { walletExecuteRap } from '@/raps/execute';
import { QuoteTypeMap, RapSwapActionParameters } from '@/raps/references';
import { queryClient } from '@/react-query';
Expand All @@ -47,12 +47,12 @@ import { swapsStore } from '@/state/swaps/swapsStore';
import { ethereumUtils, haptics } from '@/utils';
import { CrosschainQuote, Quote, QuoteError } from '@rainbow-me/swaps';

import { IS_IOS } from '@/env';
import { Address } from 'viem';
import { clearCustomGasSettings } from '../hooks/useCustomGas';
import { getGasSettingsBySpeed, getSelectedGas, getSelectedGasSpeed } from '../hooks/useSelectedGas';
import { useSwapOutputQuotesDisabled } from '../hooks/useSwapOutputQuotesDisabled';
import { SyncGasStateToSharedValues, SyncQuoteSharedValuesToState } from './SyncSwapStateAndSharedValues';
import { IS_IOS } from '@/env';

const swapping = i18n.t(i18n.l.swap.actions.swapping);
const tapToSwap = i18n.t(i18n.l.swap.actions.tap_to_swap);
Expand All @@ -62,6 +62,7 @@ const review = i18n.t(i18n.l.swap.actions.review);
const fetchingPrices = i18n.t(i18n.l.swap.actions.fetching_prices);
const selectToken = i18n.t(i18n.l.swap.actions.select_token);
const insufficientFunds = i18n.t(i18n.l.swap.actions.insufficient_funds);
const insufficient = i18n.t(i18n.l.swap.actions.insufficient);
const quoteError = i18n.t(i18n.l.swap.actions.quote_error);

interface SwapContextType {
Expand Down Expand Up @@ -667,7 +668,11 @@ export const SwapProvider = ({ children }: SwapProviderProps) => {
}

if (!hasEnoughFundsForGas.value) {
return { label: insufficientFunds, disabled: true };
const nativeCurrency = RainbowNetworkByChainId[sellAsset?.chainId || ChainId.mainnet].nativeCurrency;
return {
label: `${insufficient} ${nativeCurrency.symbol}`,
disabled: true,
};
}

if (isReviewSheetOpen) {
Expand Down
1 change: 1 addition & 0 deletions src/languages/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -1978,6 +1978,7 @@
"swapping": "Swapping",
"select_token": "Select Token",
"insufficient_funds": "Insufficient Funds",
"insufficient": "Insufficient",
"quote_error": "Quote Error"
},
"aggregators": {
Expand Down
25 changes: 17 additions & 8 deletions src/networks/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { ChainId } from '@/__swaps__/types/chains';
import store from '@/redux/store';
import * as ls from '@/storage';
import { getArbitrumNetworkObject } from './arbitrum';
import { getAvalancheNetworkObject } from './avalanche';
import { getBaseNetworkObject } from './base';
import { getBlastNetworkObject } from './blast';
import { getBSCNetworkObject } from './bsc';
import { getMainnetNetworkObject } from './mainnet';
import { getDegenNetworkObject } from './degen';
import { getGnosisNetworkObject } from './gnosis';
import { getGoerliNetworkObject } from './goerli';
import { getMainnetNetworkObject } from './mainnet';
import { getOptimismNetworkObject } from './optimism';
import { getPolygonNetworkObject } from './polygon';
import { Network, NetworkProperties } from './types';
import { getZoraNetworkObject } from './zora';
import { getGnosisNetworkObject } from './gnosis';
import { getBaseNetworkObject } from './base';
import { getAvalancheNetworkObject } from './avalanche';
import { getBlastNetworkObject } from './blast';
import { getDegenNetworkObject } from './degen';
import store from '@/redux/store';
import * as ls from '@/storage';

/**
* Array of all Rainbow Networks
Expand Down Expand Up @@ -93,3 +94,11 @@ export function sortNetworks(): NetworkProperties[] {
export function getSwappableNetworks(): NetworkProperties[] {
return RainbowNetworks.filter(network => network.features.swaps);
}

export const RainbowNetworkByChainId = RainbowNetworks.reduce(
(acc, network) => {
acc[network.id] = network;
return acc;
},
{} as Record<ChainId, NetworkProperties>
);

0 comments on commit e8529d2

Please sign in to comment.