Skip to content

Commit

Permalink
gas and quote state fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
benisgold committed Nov 15, 2024
1 parent 4f91665 commit ff7a615
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function TransactionClaimableFlow() {
const { goBack } = useNavigation();
console.log(claimStatus);
// BUTTON PROPS
const shouldShowClaimText = !!(claimStatus === 'ready' && outputChainId && outputToken);
const disabled = !(
((claimStatus === 'ready' || claimStatus === 'recoverableError') && txState.isSufficientGas) ||
claimStatus === 'success' ||
Expand All @@ -42,25 +43,34 @@ export function TransactionClaimableFlow() {

switch (claimStatus) {
case 'notReady':
if (quoteState.status === 'success' || !requiresSwap) {
switch (txState.status) {
case 'error':
return 'Gas Error';
case 'success':
if (!txState.isSufficientGas) {
return i18n.t(i18n.l.claimables.panel.insufficient_funds);
}
case 'fetching':
default:
return i18n.t(i18n.l.claimables.panel.estimating_gas_fee);
}
}

switch (quoteState.status) {
case 'noQuoteError':
return 'Quote Error';
case 'noRouteError':
return 'No Route Found';
case 'fetching':
return 'Fetching Quote...';
default:
return i18n.t(i18n.l.claimables.panel.estimating_gas_fee);
return 'Fetching Quote...';
}

case 'ready':
if (claimStatus === 'ready') {
return i18n.t(i18n.l.claimables.panel.claim_amount, {
amount: requiresSwap && quoteState.tokenAmountDisplay ? quoteState.tokenAmountDisplay : claimable.value.claimAsset.display,
});
} else {
return i18n.t(i18n.l.claimables.panel.insufficient_funds);
}
return i18n.t(i18n.l.claimables.panel.claim_amount, {
amount: requiresSwap && quoteState.tokenAmountDisplay ? quoteState.tokenAmountDisplay : claimable.value.claimAsset.display,
});
case 'claiming':
return i18n.t(i18n.l.claimables.panel.claim_in_progress);
case 'pending':
Expand All @@ -71,15 +81,7 @@ export function TransactionClaimableFlow() {
default:
return i18n.t(i18n.l.points.points.try_again);
}
}, [
claimStatus,
claimable.value.claimAsset.display,
outputChainId,
outputToken,
quoteState.status,
quoteState.tokenAmountDisplay,
requiresSwap,
]);
}, [claimStatus, claimable.value.claimAsset.display, requiresSwap, quoteState, txState, outputChainId, outputToken]);

const onPress = useCallback(() => {
if (claimStatus === 'ready' || claimStatus === 'recoverableError') {
Expand All @@ -102,7 +104,7 @@ export function TransactionClaimableFlow() {
<ClaimCustomization />
</Box>
<Box alignItems="center" width="full">
<ClaimButton onPress={onPress} disabled={disabled} shimmer={shimmer} biometricIcon={claimStatus === 'ready'} label={buttonLabel} />
<ClaimButton onPress={onPress} disabled={disabled} shimmer={shimmer} biometricIcon={shouldShowClaimText} label={buttonLabel} />
<GasDetails />
</Box>
</ClaimPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ interface OutputConfig {
}

interface TxState {
status: 'fetching' | 'success' | 'none';
status: 'fetching' | 'error' | 'success' | 'none';
isSufficientGas: boolean;
gasFeeDisplay: string | undefined;
txPayload: TransactionClaimableTxPayload | undefined;
Expand Down Expand Up @@ -179,7 +179,7 @@ export function TransactionClaimableContextProvider({
fromAddress: accountAddress,
sellTokenAddress: claimable.asset.isNativeAsset ? ETH_ADDRESS : claimable.asset.address,
buyTokenAddress: tokenToClaim.isNativeAsset ? ETH_ADDRESS : (tokenToClaim.networks[tokenToClaim.chainId]?.address as string),
sellAmount: convertAmountToRawAmount(0.0001, claimable.asset.decimals),
sellAmount: convertAmountToRawAmount(claimable.value.claimAsset.amount, claimable.asset.decimals),
slippage: 0.5,
refuel: false,
toChainId: tokenToClaim.chainId,
Expand Down Expand Up @@ -331,17 +331,18 @@ export function TransactionClaimableContextProvider({

gasFeeNativeCurrencyDisplay = convertAmountToNativeDisplayWorklet(feeInUserCurrency, nativeCurrency, true);
}

console.log(sufficientGas);
setLastGasEstimateTime(Date.now());
setTxState({
isSufficientGas: sufficientGas,
gasFeeDisplay: gasFeeNativeCurrencyDisplay,
txPayload: { ...partialTxPayload, gasLimit },
status: 'success',
});
console.log('HEYO');
} catch (e) {
if (txState.status === 'fetching') {
setTxState(prev => ({ ...prev, status: 'none' }));
setTxState(prev => ({ ...prev, status: 'error' }));
}
logger.warn('[TransactionClaimablePanel]: Failed to estimate gas', { error: e });
}
Expand Down Expand Up @@ -454,7 +455,7 @@ export function TransactionClaimableContextProvider({

const swapData = {
amount: claimable.value.claimAsset.amount,
sellAmount: convertAmountToRawAmount(0.0001, claimable.asset.decimals),
sellAmount: convertAmountToRawAmount(claimable.value.claimAsset.amount, claimable.asset.decimals),
chainId: claimable.chainId,
toChainId: outputConfig.chainId,
assetToSell: outputAsset,
Expand Down

0 comments on commit ff7a615

Please sign in to comment.