File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed
src/app/backing/components/AllocationInput Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -118,7 +118,7 @@ export const AllocationInput = ({
118118 if ( ! editing ) return
119119
120120 try {
121- updateBacking ( normaliseBackingValue ( onchainBacking , value ) )
121+ updateBacking ( preventLeftoverDecimals ( onchainBacking , value ) )
122122 } catch ( error ) {
123123 setParsingError ( error as Error )
124124 }
@@ -185,9 +185,18 @@ export const AllocationInput = ({
185185 )
186186}
187187
188- // A little bit of a hacky way to check that the input is equal to the on-chain backing in the integer part and if so it should be set to that to prevent accidental fractions.
189- function normaliseBackingValue ( onchainBacking : bigint , value : string ) {
190- return Number ( formatEther ( onchainBacking ) ) . toFixed ( 0 ) === value ? onchainBacking : parseEther ( value )
188+ // A little bit of a hacky way to check that the input is equal to the on-chain backing **in the integer part**
189+ // If it does, it should be set to the onchain value.
190+ // The purpose of this is to prevent leftover fractions in the available balance, which cannot be used up.
191+ function preventLeftoverDecimals ( onchainBacking : bigint , value : string ) : bigint {
192+ const onchainBackingStr = formatEther ( onchainBacking )
193+ const [ onchainBackingIntegerValue ] = onchainBackingStr . split ( '.' )
194+
195+ if ( onchainBackingIntegerValue === value ) {
196+ return onchainBacking
197+ }
198+
199+ return parseEther ( value )
191200}
192201
193202function isValidBalanceFraction (
You can’t perform that action at this time.
0 commit comments