Skip to content

Commit

Permalink
♻️ Reuse ellipsis functions for memo name
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraHuang22 committed Dec 30, 2024
1 parent 20146d6 commit 55d7476
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 26 deletions.
10 changes: 5 additions & 5 deletions src/components/NFTPage/CollectorMessageList/Identity.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
/>
<div>
<p class="text-like-green hover:underline" align="center">
{{ userDisplayNameFull | ellipsisCollectorAddress }}
{{ formattedUserDisplayNameFull }}
</p>
</div>
</component>
Expand All @@ -41,15 +41,12 @@
import { mapActions } from 'vuex';
import { createUserInfoMixin } from '~/mixins/user-info';
import { ellipsisCollectorAddress } from '~/util/ui';
import { ellipsis } from '~/util/ui';
const userInfoMixin = createUserInfoMixin({ walletKey: 'walletAddress' });
export default {
name: 'NFTPageCollectorMessageListIdentity',
filters: {
ellipsisCollectorAddress,
},
mixins: [userInfoMixin],
props: {
walletAddress: {
Expand Down Expand Up @@ -85,6 +82,9 @@ export default {
query: { tab: this.isCreatedTab ? 'created' : 'collected' },
});
},
formattedUserDisplayNameFull() {
return ellipsis(this.userDisplayNameFull, 13, 0);
},
},
watch: {
walletAddress() {
Expand Down
28 changes: 7 additions & 21 deletions src/util/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,15 @@ const largeNumFormatter = new Intl.NumberFormat('en-US', {
maximumFractionDigits: 2,
});

export function ellipsis(value) {
if (value) {
const len = value.length;
const dots = '...';
if (!value) return '';
if (value.length > 20) {
return value.substring(0, 8) + dots + value.substring(len - 6, len);
}
return value;
}
return value;
}
export function ellipsis(value, maxLength = 20, endLength = 6) {
if (!value) return '';
const len = value.length;
const dots = '...';

export function ellipsisCollectorAddress(value) {
if (value) {
const len = value.length;
const dots = '...';
if (!value) return '';
if (value.length > 10) {
return value.substring(0, 8) + dots;
}
return value;
if (len > maxLength) {
return value.substring(0, 8) + dots + value.substring(len - endLength, len);
}

return value;
}

Expand Down

0 comments on commit 55d7476

Please sign in to comment.