Merge pull request #1850 from siiky/fix/lam-1057/shorten-ln-addresses

LAM-1057 feat: shorten long addresses
This commit is contained in:
Rafael Taranto 2025-05-16 07:10:16 +01:00 committed by GitHub
commit 910f996db6
4 changed files with 44 additions and 17 deletions

View file

@ -1,4 +1,26 @@
import * as R from 'ramda'
import { formatCryptoAddress } from '@lamassu/coins/lightUtils'
const shortenByEllipses = (str, contextLength, ellipsesLength) =>
str.length <= contextLength * 2
? str
: [
str.slice(0, contextLength),
'.'.repeat(ellipsesLength),
str.slice(str.length - contextLength),
].join('')
const formatAddress = (cryptoCode, address) => {
if (!cryptoCode || !address) return { address: null, addressDisplay: null }
address = formatCryptoAddress(cryptoCode, address)
let addressDisplay =
address.length > 84 /* 2*BTC */
? shortenByEllipses(address, 10, 5)
: address
addressDisplay = addressDisplay.replace(/(.{5})/g, '$1 ')
return { address, addressDisplay }
}
const formatLong = value => {
if (!value || value.length <= 20) return value
@ -30,6 +52,7 @@ const singularOrPlural = (amount, singularStr, pluralStr) =>
export {
startCase,
onlyFirstToUpper,
formatAddress,
formatLong,
singularOrPlural,
sentenceCase,