-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a33452a
commit a4a4a8b
Showing
5 changed files
with
56 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const TOKEN_DECIMALS = 18; // should be retrieved from the contract? |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import type { ToastId, UseToastOptions } from '@chakra-ui/react'; | ||
import type { ReadContractErrorType, WriteContractErrorType } from 'viem'; | ||
|
||
export const renderContractErrorToast = ( | ||
error: ReadContractErrorType | WriteContractErrorType | null, | ||
toast: (options?: UseToastOptions) => ToastId, | ||
desc: string | ||
) => { | ||
if (error) { | ||
console.error(desc, error.message); | ||
toast({ | ||
title: desc, | ||
description: error.message, | ||
status: 'error', | ||
duration: 5000, | ||
isClosable: true, | ||
}); | ||
} | ||
}; | ||
|
||
export const renderToastSuccess = ( | ||
toast: (options?: UseToastOptions) => ToastId, | ||
desc: string | ||
) => { | ||
toast({ | ||
title: desc, | ||
status: 'success', | ||
duration: 5000, | ||
isClosable: true, | ||
}); | ||
}; | ||
|
||
export function decimalToFraction( | ||
decimal: number, | ||
decimalPlaces?: number | ||
): [number, number] { | ||
if (Number.isInteger(decimal)) { | ||
return [decimal, 1]; | ||
} | ||
|
||
const precision = decimalPlaces || 1000000; // Adjust this for more/less precision | ||
let numerator = Math.round(decimal * precision); | ||
let denominator = precision; | ||
|
||
const gcd = (a: number, b: number): number => (b ? gcd(b, a % b) : a); | ||
const divisor = gcd(numerator, denominator); | ||
|
||
numerator /= divisor; | ||
denominator /= divisor; | ||
|
||
return [numerator, denominator]; | ||
} |