From b8bd0aa64afa8e230abe5378601397ecf46ca747 Mon Sep 17 00:00:00 2001
From: camewell <130561684+camewell071@users.noreply.github.com>
Date: Sat, 3 Feb 2024 05:29:36 +0700
Subject: [PATCH] chore: update code
---
src/modules/PublicSale/LuckyMoneyWinner/index.tsx | 3 ++-
src/utils/format.ts | 12 ++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/src/modules/PublicSale/LuckyMoneyWinner/index.tsx b/src/modules/PublicSale/LuckyMoneyWinner/index.tsx
index f84324337..1b54e718b 100644
--- a/src/modules/PublicSale/LuckyMoneyWinner/index.tsx
+++ b/src/modules/PublicSale/LuckyMoneyWinner/index.tsx
@@ -8,6 +8,7 @@ import background from '@/public/images/lucky-money-envelops/lucky-money-winner-
import Avatar from '@/components/Avatar';
import relativeTime from 'dayjs/plugin/relativeTime';
import { settingMomentFromNow } from '@/utils/helpers';
+import { formatString } from '@/utils/format';
dayjs.extend(relativeTime);
@@ -43,7 +44,7 @@ const LuckyMoneyWinner = () => {
- {winner?.user.twitter_name || '---'} just snatched
+ {formatString(winner?.user.twitter_name || '---', 6, '')} just snatched
a red packet successfully and{' '}
got {winner?.bvm_amount} BVM.
diff --git a/src/utils/format.ts b/src/utils/format.ts
index 979dee6de..0e5cbce67 100644
--- a/src/utils/format.ts
+++ b/src/utils/format.ts
@@ -3,6 +3,8 @@ import { ethers } from 'ethers';
import { MAX_DECIMAL } from '@/constants/constants';
import { compareString } from './string';
import dayjs from 'dayjs';
+import { isAddress } from '@ethersproject/address';
+import { validate } from 'bitcoin-address-validation';
export const isInValidAmount = (amount?: string | number) => {
if (!amount) return true;
@@ -168,6 +170,16 @@ export function formatString(
return str;
}
+export function formatNameOrAddress(str: string | undefined) {
+ const isEVM = isAddress(str || "");
+ const isBTC = validate(str || "");
+ const length = isBTC ? 4 : isEVM ? 6 : 12;
+ if (str?.length && str.length > length) {
+ return str.slice(0, length);
+ }
+ return str;
+}
+
export const zeroPad = (num: number, places: number) =>
String(num).padStart(places, '0');