From 2325e13310f1a99276755e554eb7f741f4a4cdc9 Mon Sep 17 00:00:00 2001 From: Karolina Kosiorowska Date: Fri, 17 Nov 2023 11:52:35 +0100 Subject: [PATCH] Add a function to truncate address --- dapp/src/components/Navbar/ConnectWallet.tsx | 4 ++-- dapp/src/utils/address.ts | 3 +++ dapp/src/utils/index.ts | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 dapp/src/utils/address.ts diff --git a/dapp/src/components/Navbar/ConnectWallet.tsx b/dapp/src/components/Navbar/ConnectWallet.tsx index 09641e170..e7302cd49 100644 --- a/dapp/src/components/Navbar/ConnectWallet.tsx +++ b/dapp/src/components/Navbar/ConnectWallet.tsx @@ -10,7 +10,7 @@ import { useRequestEthereumAccount, } from "../../hooks" import { LedgerLiveAppContext } from "../../contexts/LedgerLiveAppContext" -import { formatSatoshiAmount } from "../../utils" +import { formatSatoshiAmount, truncateAddress } from "../../utils" export type ConnectButtonsProps = { leftIcon: string @@ -32,7 +32,7 @@ function ConnectButton({ rightIcon={!account ? : undefined} onClick={requestAccount} > - {account ? account.address : "Not connected"} + {account ? truncateAddress(account.address) : "Not connected"} ) } diff --git a/dapp/src/utils/address.ts b/dapp/src/utils/address.ts new file mode 100644 index 000000000..7ed3caa1a --- /dev/null +++ b/dapp/src/utils/address.ts @@ -0,0 +1,3 @@ +export function truncateAddress(address: string): string { + return `${address.slice(0, 6)}…${address.slice(-5)}` +} diff --git a/dapp/src/utils/index.ts b/dapp/src/utils/index.ts index 991e6839f..613e0f071 100644 --- a/dapp/src/utils/index.ts +++ b/dapp/src/utils/index.ts @@ -1 +1,2 @@ export * from "./numbers" +export * from "./address"