-
Notifications
You must be signed in to change notification settings - Fork 146
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
Conversation
src/app/pages/send/ordinal-inscription/coinselect/select-inscription-coins.ts
Outdated
Show resolved
Hide resolved
src/app/pages/send/ordinal-inscription/coinselect/select-inscription-coins.ts
Outdated
Show resolved
Hide resolved
b354027
to
7bdabba
Compare
7bdabba
to
0fdaafd
Compare
@@ -75,36 +79,46 @@ export function useBitcoinFeesList({ | |||
feeRate: feeRates.hourFee.toNumber(), | |||
}; | |||
|
|||
const feesArr = []; |
There was a problem hiding this comment.
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(),
}] : [])
]
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this 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
There was a problem hiding this 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
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); | ||
}); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
This pr handles unprocessed fees calc error in bitcoin flows:
Also: