-
Notifications
You must be signed in to change notification settings - Fork 634
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: truncate ENS names * chore: adds changeset * Update packages/rainbowkit/src/components/ConnectButton/formatENS.test.ts Co-authored-by: Mark Dalgleish <mark.john.dalgleish@gmail.com> * WIP * fix: adds subdomain functionality Co-authored-by: Mark Dalgleish <mark.john.dalgleish@gmail.com>
- Loading branch information
1 parent
a864107
commit df6c310
Showing
5 changed files
with
53 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@rainbow-me/rainbowkit': patch | ||
--- | ||
|
||
Truncates long ENS names |
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
32 changes: 32 additions & 0 deletions
32
packages/rainbowkit/src/components/ConnectButton/formatENS.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,32 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { formatENS } from './formatENS'; | ||
|
||
describe('formatENS', () => { | ||
it('trucates ENS name over 24 characters', () => { | ||
expect(formatENS('reallylongensnameheretotestlongnames.eth')).toEqual( | ||
'reallylongensnameheretot...' | ||
); | ||
}); | ||
|
||
it(`doesn't do anything to ENS names 24 characters or less`, () => { | ||
expect(formatENS('rainbow.eth')).toEqual('rainbow.eth'); | ||
}); | ||
|
||
it(`if 24 characters, do not truncate .eth`, () => { | ||
expect(formatENS('qwertyuiopasdfghjklzxcvb.eth')).toEqual( | ||
'qwertyuiopasdfghjklzxcvb.eth' | ||
); | ||
}); | ||
|
||
it(`Subdomains are taken into account`, () => { | ||
expect(formatENS('rainbowrainbowrainbow.rainbowrainbow.eth')).toEqual( | ||
'rainbowrainbowrainbow.ra...' | ||
); | ||
}); | ||
|
||
it(`Non .eth names work`, () => { | ||
expect(formatENS('qwertyuiopasdfghjklzxcvb.xyz')).toEqual( | ||
'qwertyuiopasdfghjklzxcvb.xyz' | ||
); | ||
}); | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/rainbowkit/src/components/ConnectButton/formatENS.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,8 @@ | ||
export function formatENS(name: string): string { | ||
const parts = name.split('.'); | ||
const last = parts.pop(); | ||
if (parts.join('.').length > 24) { | ||
return `${parts.join('.').substring(0, 24)}...`; | ||
} | ||
return `${parts.join('.')}.${last}`; | ||
} |
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
df6c310
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
rainbowkit-example – ./
rainbowkit-example-git-main-rainbowdotme.vercel.app
rainbowkit-example.vercel.app
rainbowkit-example-rainbowdotme.vercel.app
df6c310
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
rainbowkit-site – ./
rainbowkit.vercel.app
rainbowkit-site-rainbowdotme.vercel.app
rainbowkit-site-git-main-rainbowdotme.vercel.app