Skip to content

Commit

Permalink
chore: update code
Browse files Browse the repository at this point in the history
  • Loading branch information
camewell071 committed Feb 2, 2024
1 parent 85cc758 commit b8bd0aa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/modules/PublicSale/LuckyMoneyWinner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -43,7 +44,7 @@ const LuckyMoneyWinner = () => {
</div>
<div>
<div className={s.textMessage}>
<strong>{winner?.user.twitter_name || '---'}</strong> just snatched
<strong>{formatString(winner?.user.twitter_name || '---', 6, '')}</strong> just snatched
a red packet successfully and{' '}
<strong>got {winner?.bvm_amount} BVM</strong>.
</div>
Expand Down
12 changes: 12 additions & 0 deletions src/utils/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit b8bd0aa

Please sign in to comment.