-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
9 changed files
with
239 additions
and
65 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
35 changes: 35 additions & 0 deletions
35
packages/ui/src/__tests__/widgets/token-upgrade-utils.test.ts
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,35 @@ | ||
import { | ||
getVariantByIndex, | ||
shortenAddress, | ||
} from "../../widgets/token-upgrade/utils" | ||
import { expect, test } from "vitest" | ||
|
||
test("should shorten address", () => { | ||
expect(shortenAddress("Bk9ErfcwzZ8MgSPdEgfmkreNHad9ik8jYP8um")).toEqual( | ||
"Bk9..8um", | ||
) | ||
expect( | ||
shortenAddress("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", "USDC"), | ||
).toEqual("USDC") | ||
expect( | ||
shortenAddress("Bk9ErfcwzZ8MgSPdEgfmkreNHad9ik8jYP8um", undefined, 2), | ||
).toEqual("Bk..um") | ||
expect(shortenAddress("Bk9")).toEqual("Bk9") | ||
}) | ||
|
||
test("should get variant by index", () => { | ||
const variants = ["a", "b", "c", "d"] | ||
expect(getVariantByIndex(variants, 0)).toEqual("a") | ||
expect(getVariantByIndex(variants, 1)).toEqual("b") | ||
expect(getVariantByIndex(variants, 2)).toEqual("c") | ||
expect(getVariantByIndex(variants, 3)).toEqual("d") | ||
expect(getVariantByIndex(variants, 4)).toEqual("a") | ||
expect(getVariantByIndex(variants, 5)).toEqual("b") | ||
expect(getVariantByIndex(variants, 6)).toEqual("c") | ||
expect(getVariantByIndex(variants, 7)).toEqual("d") | ||
expect(getVariantByIndex(variants, 8)).toEqual("a") | ||
expect(getVariantByIndex(variants, 9)).toEqual("b") | ||
expect(getVariantByIndex(variants, 10)).toEqual("c") | ||
expect(getVariantByIndex(variants, 11)).toEqual("d") | ||
expect(getVariantByIndex(variants, 12)).toEqual("a") | ||
}) |
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
57 changes: 44 additions & 13 deletions
57
packages/ui/src/widgets/token-upgrade/token-extensions.tsx
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,15 +1,21 @@ | ||
export function getVariantByIndex(variants: string[], variant: number) { | ||
const len = variants.length | ||
const base = Math.floor(variant / len) | ||
return variants[variant - base * len] | ||
} | ||
|
||
export function shortenAddress( | ||
address: string, | ||
symbol?: string, | ||
length = 3, | ||
): string { | ||
let s = symbol | ||
if (!s && address?.length > length) { | ||
let s | ||
if (!symbol && address.length > length) { | ||
s = address.slice(0, length) + ".." + address.slice(-1 * length) | ||
} else if (!s && address?.length <= length) { | ||
} else if (!symbol && address.length <= length) { | ||
s = address | ||
} else { | ||
s = address.slice(0, length - 1) + ".." | ||
s = symbol || address.slice(0, length - 1) + ".." | ||
} | ||
return s | ||
} |
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
Oops, something went wrong.