-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: resolve merge conflicts from main into dev
- Loading branch information
Showing
16 changed files
with
5,288 additions
and
1,992 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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 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 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 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 |
---|---|---|
@@ -1,3 +1,18 @@ | ||
/** | ||
* Trims a given string to a specified number of symbols, adding ellipsis in the | ||
* middle if necessary. | ||
* | ||
* @param {string} str - The string to be trimmed. | ||
* @param {number} [symbols=8] - The total number of symbols to retain in the | ||
* trimmed string, including the ellipsis. Defaults to 8 if not provided. | ||
* @returns {string} - The trimmed string with ellipsis in the middle if the | ||
* original string length exceeds the specified symbol count. | ||
*/ | ||
export const trim = (str: string, symbols: number = 8) => { | ||
if (str.length <= symbols) { | ||
return str; | ||
} else if (symbols === 0) { | ||
return "..."; | ||
} | ||
return `${str.slice(0, symbols / 2)}...${str.slice(-symbols / 2)}`; | ||
}; |
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 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 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 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,44 @@ | ||
import { durationTillNow } from "@/utils/formatTime"; | ||
|
||
describe("durationTillNow", () => { | ||
const currentTime = new Date("2024-01-01T12:00:00Z").getTime(); | ||
|
||
it('should return "Ongoing" if time is empty', () => { | ||
expect(durationTillNow("", currentTime)).toBe("Ongoing"); | ||
}); | ||
|
||
it('should return "Ongoing" if time starts with "000"', () => { | ||
expect(durationTillNow("0000-00-00T00:00:00Z", currentTime)).toBe( | ||
"Ongoing", | ||
); | ||
}); | ||
|
||
it("should return the correct duration in days, hours, and minutes", () => { | ||
const pastTime = new Date("2023-12-31T10:00:00Z").toISOString(); | ||
expect(durationTillNow(pastTime, currentTime)).toBe("1 day 2 hours ago"); | ||
}); | ||
|
||
it("should return the correct duration in hours", () => { | ||
const pastTime = new Date("2024-01-01T10:00:00Z").toISOString(); | ||
expect(durationTillNow(pastTime, currentTime)).toBe("2 hours ago"); | ||
}); | ||
|
||
it("should return the correct duration in minutes", () => { | ||
const pastTime = new Date("2024-01-01T11:50:00Z").toISOString(); | ||
expect(durationTillNow(pastTime, currentTime)).toBe("10 minutes ago"); | ||
}); | ||
|
||
it("should return the correct duration in seconds if less than a minute", () => { | ||
const pastTime = new Date("2024-01-01T11:59:30Z").toISOString(); | ||
expect(durationTillNow(pastTime, currentTime)).toBe("30 seconds ago"); | ||
}); | ||
|
||
it('should return "Just now" if the duration is less than a second', () => { | ||
let pastTime = new Date("2024-01-01T12:00:00Z").toISOString(); | ||
expect(durationTillNow(pastTime, currentTime)).toBe("Just now"); | ||
|
||
// test the ms | ||
pastTime = new Date("2024-01-01T11:59:59.999Z").toISOString(); | ||
expect(durationTillNow(pastTime, currentTime)).toBe("Just now"); | ||
}); | ||
}); |
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,44 @@ | ||
import { getFeeRateFromMempool } from "@/utils/getFeeRateFromMempool"; | ||
import { Fees } from "@/utils/wallet/wallet_provider"; | ||
|
||
describe("getFeeRateFromMempool", () => { | ||
const mempoolFeeRates: Fees = { | ||
hourFee: 10, | ||
fastestFee: 100, | ||
halfHourFee: 50, | ||
economyFee: 5, | ||
minimumFee: 1, | ||
}; | ||
|
||
it("should return 0 for min, default, and max fee rates when mempoolFeeRates is undefined", () => { | ||
const result = getFeeRateFromMempool(); | ||
expect(result).toEqual({ | ||
minFeeRate: 0, | ||
defaultFeeRate: 0, | ||
maxFeeRate: 0, | ||
}); | ||
}); | ||
|
||
it("should return the correct min, default, and max fee rates from mempoolFeeRates", () => { | ||
const result = getFeeRateFromMempool(mempoolFeeRates); | ||
expect(result).toEqual({ | ||
minFeeRate: mempoolFeeRates.hourFee, | ||
defaultFeeRate: mempoolFeeRates.fastestFee, | ||
maxFeeRate: 256, // Ensures that the max fee rate is the next power of two | ||
}); | ||
}); | ||
|
||
it("should return max fee rate of at least 128 sat/vB", () => { | ||
const feeRate: Fees = { | ||
...mempoolFeeRates, | ||
fastestFee: 5, | ||
}; | ||
|
||
const result = getFeeRateFromMempool(feeRate); | ||
expect(result).toEqual({ | ||
minFeeRate: feeRate.hourFee, | ||
defaultFeeRate: feeRate.fastestFee, | ||
maxFeeRate: 128, // Ensures that the max fee rate is at least 128 | ||
}); | ||
}); | ||
}); |
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,33 @@ | ||
import { getStakingTerm } from "@/utils/getStakingTerm"; | ||
|
||
describe("getStakingTerm", () => { | ||
it("should return the fixed term when minStakingTimeBlocks equals maxStakingTimeBlocks", () => { | ||
const params: any = { | ||
minStakingTimeBlocks: 100, | ||
maxStakingTimeBlocks: 100, | ||
}; | ||
const term = 50; | ||
expect(getStakingTerm(params, term)).toBe(100); | ||
}); | ||
|
||
it("should return the input term when minStakingTimeBlocks does not equal maxStakingTimeBlocks", () => { | ||
const params: any = { | ||
minStakingTimeBlocks: 100, | ||
maxStakingTimeBlocks: 200, | ||
}; | ||
const term = 150; | ||
expect(getStakingTerm(params, term)).toBe(term); | ||
}); | ||
|
||
it("should return the input term when params is undefined", () => { | ||
const params = undefined; | ||
const term = 150; | ||
expect(getStakingTerm(params as any, term)).toBe(term); | ||
}); | ||
|
||
it("should return the input term when params is null", () => { | ||
const params = null; | ||
const term = 150; | ||
expect(getStakingTerm(params as any, term)).toBe(term); | ||
}); | ||
}); |
Oops, something went wrong.