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 devex to not crash for high gas txn #707

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"elliptic": "^6.5.0",
"enzyme": "^3.11.0",
"enzyme-to-json": "^3.6.2",
"eslint": "8",
"eslint": "^7.32.0",
"eslint-plugin-react": "^7.31.10",
"events": "^3.3.0",
"expect": "^29.3.1",
Expand Down
18 changes: 11 additions & 7 deletions products/devex/src/utils/Utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const zilAddrToHexAddr: (addr: string) => string = (zilAddr: string) => {

// Convert timestamp to display format, M/D/YYYY, h:mm:ssa
export const timestampToDisplay: (timestamp: string | number) => string = (
timestamp: string | number
timestamp: string | number,
) => {
if (typeof timestamp === "string")
return moment(parseInt(timestamp) / 1000).format("M/D/YYYY, h:mm:ssa");
Expand All @@ -33,24 +33,28 @@ export const timestampToDisplay: (timestamp: string | number) => string = (

// Convert timestamp from microseconds to milliseconds and find timeago
export const timestampToTimeago: (timestamp: string | number) => string = (
timestamp: string | number
timestamp: string | number,
) => {
if (typeof timestamp === "string")
return moment(parseInt(timestamp) / 1000).fromNow();
else return moment(timestamp / 1000).fromNow();
};

export const qaToZilSimplified: (amount: string | number) => number | string = (
amount: string | number
amount: string | number,
) => {
return units.fromQa(new BN(amount), units.Units.Zil);
};

// Convert from Qa to Zil
export const qaToZil: (
amount: string | number,
numOfDigits?: number
numOfDigits?: number,
) => string = (amount: string | number, numOfDigits?: number) => {
// Check if the amount is a number and convert to string if necessary
if (typeof amount === "number") {
amount = amount.toString();
}
let parsedAmt = "";
const splitAmt = units.fromQa(new BN(amount), units.Units.Zil).split(".");
if (splitAmt.length === 1) {
Expand All @@ -73,23 +77,23 @@ export const qaToZil: (

// Strips hex prefix if exists
export const stripHexPrefix: (inputHex: string) => string = (
inputHex: string
inputHex: string,
) => {
if (inputHex.substring(0, 2) === "0x") return inputHex.substring(2);
return inputHex;
};

// Add hex prefix if not already
export const addHexPrefix: (inputHex: string) => string = (
inputHex: string
inputHex: string,
) => {
if (inputHex.substring(0, 2) !== "0x") return "0x" + inputHex;
return inputHex;
};

// Check whether is valid addr (regardless of bech32 or hex format)
export const isValidAddr: (inputStr: string) => boolean = (
inputStr: string
inputStr: string,
) => {
const trimmedInput = inputStr.trim();
let prefixedInput = trimmedInput;
Expand Down
Loading