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: tx calc unhandled errors, closes #4941 #5011

Merged
merged 1 commit into from
Mar 6, 2024
Merged

Conversation

alter-eggo
Copy link
Collaborator

@alter-eggo alter-eggo commented Mar 1, 2024

Try out this version of Leather — Extension build, Test report

This pr handles unprocessed fees calc error in bitcoin flows:

  • Removes fee variant in fees list, if there is no enough balance for it
  • Shows insufficient balance error in custom fee input

Also:

  • refactored custom fee input, so we use one component in all flows, including increasing fee
  • refactored inscription fees list, so it considers inscription utxo type (NS or Taproot)

@alter-eggo alter-eggo marked this pull request as ready for review March 5, 2024 20:32
@@ -75,36 +79,46 @@ export function useBitcoinFeesList({
feeRate: feeRates.hourFee.toNumber(),
};

const feesArr = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can spread values into this array instead?

    ...(highFeeValue ? [{
        label: BtcFeeType.High,
        value: highFeeValue,
        btcValue: formatMoneyPadded(createMoney(highFeeValue, 'BTC')),
        time: btcTxTimeMap.fastestFee,
        fiatValue: getFiatFeeValue(highFeeValue),
        feeRate: feeRates.fastestFee.toNumber(),
      }] : [])
  ]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it so to improve readability. don't really like such constructions even if they save several lines of code

@@ -37,11 +37,11 @@ describe(selectInscriptionTransferCoins.name, () => {
Number(inscriptionInputAmount)
);

expect(result.txFee).toEqual(6765);
expect(result.txFee).toEqual(5048);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this value of 5048 decided? Maybe we can give it a const name for readability?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since I will refactor fees gen, will return to this test in future pr. thanks Pete!


const feesArr = [];

if (highFeeValue) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems almost the same as - https://github.com/leather-wallet/extension/pull/5011/files#r1514527890

Maybe we can extract and share logic?

Copy link
Collaborator Author

@alter-eggo alter-eggo Mar 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it makes sense in general, but I will change the fees gen logic in future prs, so prob better to leave it for now

Copy link
Contributor

@pete-watters pete-watters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some suggestions but LGTM

Copy link
Collaborator

@kyranjamie kyranjamie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing @alter-eggo

This is good for now but this feature clearly needs a refactor. Look forward to seeing what you come up with next

Comment on lines +60 to +84
function processFeeValue(feeRate: string) {
try {
const feeValues = getCustomFeeValues(Number(feeRate));
setFeeValue(feeValues);

setUnknownError(false);
setCustomInsufficientBalanceError(false);
} catch (err) {
if (err instanceof InsufficientFundsError) {
return setCustomInsufficientBalanceError(true);
}

setUnknownError(true);
}
}

function onChange(e: React.ChangeEvent<HTMLInputElement>) {
const value = e.target.value;
setCustomFeeInitialValue?.(e.target.value);
processFeeValue(value);
}

useOnMount(() => {
processFeeValue(customFeeInitialValue);
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Processing the fee on mount, then setting the values, like this seems kinda side-effecty. Okay for now as we're going to do fee work and refactor entirely, but I'm sure there's a nicer way to do this next time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I realise it could have been done way better

@alter-eggo alter-eggo added this pull request to the merge queue Mar 6, 2024
Merged via the queue into dev with commit 150e7de Mar 6, 2024
28 checks passed
@alter-eggo alter-eggo deleted the fix/tx-size-error branch March 6, 2024 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants