Skip to content

Commit

Permalink
chore: merge branch 'dev' into feat/multi-chain
Browse files Browse the repository at this point in the history
  • Loading branch information
Polybius93 committed Nov 20, 2024
2 parents 4d33dbc + 301f526 commit 803088a
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { BitcoinTransactionConfirmationsContext } from '@providers/bitcoin-query
import { BitcoinWalletContextState } from '@providers/bitcoin-wallet-context-provider';
import { useForm } from '@tanstack/react-form';
import Decimal from 'decimal.js';
import { isEmpty } from 'ramda';

import { parseAssetAmount } from '@shared/utils';

import { TransactionFormNavigateButtonGroup } from './components/transaction-screen.transaction-form.navigate-button-group';
import { TransactionFormProgressStack } from './components/transaction-screen.transaction-form.progress-stack/components/transaction-screen.transaction-form.progress-stack';
Expand Down Expand Up @@ -141,16 +142,12 @@ export function VaultTransactionForm({
},
validators: {
onChange: ({ value }) => {
const assetAmount = value.assetAmount;
setCurrentFieldValue(isEmpty(assetAmount) ? 0 : new Decimal(value.assetAmount).toNumber());
const decimalValue = parseAssetAmount(value.assetAmount);
setCurrentFieldValue(decimalValue.toNumber());

return {
fields: {
assetAmount: validateFormAmount(
parseFloat(value.assetAmount),
flow,
depositLimit,
vault
),
assetAmount: validateFormAmount(decimalValue.toNumber(), flow, depositLimit, vault),
},
};
},
Expand Down
1 change: 1 addition & 0 deletions src/app/hooks/use-blockchain-height-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export function useBlockchainHeightQuery(): number | undefined {
if (!response.ok) throw new Error('Network response was not ok');
return response.json();
} catch (error) {
// eslint-disable-next-line no-console
console.error('Error fetching blockchain height', error);
return undefined;
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/hooks/use-confirmation-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export function useConfirmationChecker(): [string, number][] {
try {
const bitcoinTransactionBlockHeight = await fetchBitcoinTransactionBlockHeight(vault);

return blockHeight - bitcoinTransactionBlockHeight;
const difference = blockHeight - bitcoinTransactionBlockHeight;
return Math.max(difference, 0);
} catch (error) {
return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions src/app/hooks/use-mint-burn-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function useMintBurnEvents(): UseMintBurnEventsReturnType {

return await response.json();
} catch (error) {
// eslint-disable-next-line no-console
console.error(`Error fetching mint burn events`, error);
return [];
}
Expand Down Expand Up @@ -60,6 +61,7 @@ export function useMintBurnEvents(): UseMintBurnEventsReturnType {
merchantMintBurnEvents: mintBurnEvents,
};
} catch (error) {
// eslint-disable-next-line no-console
console.error(`Error fetching mint burn events`, error);
return undefined;
}
Expand Down
1 change: 1 addition & 0 deletions src/app/hooks/use-points.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function usePoints(): UsePointsReturnType {

return responseData.points;
} catch (error) {
// eslint-disable-next-line no-console
console.error(`Error fetching user: ${address} points`, error);
return undefined;
}
Expand Down
1 change: 1 addition & 0 deletions src/app/hooks/use-proof-of-reserve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export function useProofOfReserve(): UseProofOfReserveReturnType {

return await response.json();
} catch (error) {
// eslint-disable-next-line no-console
console.error('Error fetching Proof of Reserve', error);
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions src/app/hooks/use-total-supply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function useTotalSupply(): UseTotalSupplyReturnType {

return responseData;
} catch (error) {
// eslint-disable-next-line no-console
console.error('Error fetching Total Supply', error);
return undefined;
}
Expand Down
13 changes: 13 additions & 0 deletions src/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ export function formatEvent(event: DetailedEvent): FormattedEvent {
};
}

export function parseAssetAmount(assetAmount: string): Decimal {
const isValidNumber = /^-?\d*\.?\d*$/.test(assetAmount);

if (isValidNumber) {
try {
return new Decimal(assetAmount);
} catch {
return new Decimal(0);
}
}
return new Decimal(0);
}

export function formatToFourDecimals(value: number): number {
return parseFloat(value.toFixed(4));
}
Expand Down

0 comments on commit 803088a

Please sign in to comment.