From 3596bdb4dd7880ba86c4537d5736e46bda72494d Mon Sep 17 00:00:00 2001 From: Pokesi <81540683+Pokesi@users.noreply.github.com> Date: Wed, 30 Mar 2022 10:28:49 +1100 Subject: [PATCH 1/8] Update index.js --- src/utils/index.js | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/utils/index.js b/src/utils/index.js index 9f05c71..f0563a1 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -1,4 +1,22 @@ import BigNumber from 'bignumber.js' +import { fns } from 'fns-helper' + +async function resolveAddress(address) { + const name = fns.functions.getNameFromOwner(address); + if (name.split('').length > 0) { + // return name + return name; + } else { + // return address + return address; + } + return "Error: no idea"; +} + +async function ownesName(address) { + const name = fns.functions.getNameFromOwner(address); + return name.split('').length > 0; +} export function formatCurrency(amount, decimals = 2) { if (!isNaN(amount)) { @@ -18,16 +36,19 @@ export function formatCurrency(amount, decimals = 2) { } export function formatAddress(address, length = 'short') { - if (address && length === 'short') { - address = address.substring(0, 6) + '...' + address.substring(address.length - 4, address.length) - return address - } else if (address && length === 'long') { - address = address.substring(0, 12) + '...' + address.substring(address.length - 8, address.length) - return address + if (ownesName(address)) { + return resolveAddress(address); } else { - return null - } -} + if (address && length === 'short') { + address = address.substring(0, 6) + '...' + address.substring(address.length - 4, address.length) + return address + } else if (address && length === 'long') { + address = address.substring(0, 12) + '...' + address.substring(address.length - 8, address.length) + return address + } else { + return null + } + } export function bnDec(decimals) { return new BigNumber(10).pow(parseInt(decimals)) From 2cfc5a91e43ae5b44e63e190a16fa05384c1408d Mon Sep 17 00:00:00 2001 From: Pokesi <81540683+Pokesi@users.noreply.github.com> Date: Wed, 30 Mar 2022 10:32:53 +1100 Subject: [PATCH 2/8] Update package.json --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index e346115..a902d5a 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "@web3-react/walletlink-connector": "^6.2.5", "bignumber.js": "^9.0.2", "flux": "^4.0.3", + "fns-helper": ">=1.0.2", "lottie-react": "^2.2.1", "moment": "^2.29.1", "next": "^12.0.3", From b7be84a05516ecc2f1ff05d2a163b7c20cb83a2a Mon Sep 17 00:00:00 2001 From: Pokesi <81540683+Pokesi@users.noreply.github.com> Date: Wed, 30 Mar 2022 10:34:32 +1100 Subject: [PATCH 3/8] Update index.js --- src/utils/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/utils/index.js b/src/utils/index.js index f0563a1..5354712 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -47,8 +47,9 @@ export function formatAddress(address, length = 'short') { return address } else { return null - } - } + } + } +} export function bnDec(decimals) { return new BigNumber(10).pow(parseInt(decimals)) From 4d274f715faf758df3cd20fb6556e99523d10937 Mon Sep 17 00:00:00 2001 From: Pokesi <81540683+Pokesi@users.noreply.github.com> Date: Wed, 30 Mar 2022 12:06:58 +1100 Subject: [PATCH 4/8] Update index.js --- src/utils/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/index.js b/src/utils/index.js index 5354712..cb9de75 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -3,7 +3,7 @@ import { fns } from 'fns-helper' async function resolveAddress(address) { const name = fns.functions.getNameFromOwner(address); - if (name.split('').length > 0) { + if (name !== "") { // return name return name; } else { @@ -15,7 +15,7 @@ async function resolveAddress(address) { async function ownesName(address) { const name = fns.functions.getNameFromOwner(address); - return name.split('').length > 0; + return name !== ""; } export function formatCurrency(amount, decimals = 2) { From 0215bf649de57239021a0857ea226a0332eaba11 Mon Sep 17 00:00:00 2001 From: Pokesi <81540683+Pokesi@users.noreply.github.com> Date: Wed, 30 Mar 2022 12:07:46 +1100 Subject: [PATCH 5/8] Update index.js --- src/utils/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/index.js b/src/utils/index.js index cb9de75..689fe46 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -2,7 +2,7 @@ import BigNumber from 'bignumber.js' import { fns } from 'fns-helper' async function resolveAddress(address) { - const name = fns.functions.getNameFromOwner(address); + const name = fns.functions.getNameFromOwner(address)[0]; if (name !== "") { // return name return name; @@ -14,7 +14,7 @@ async function resolveAddress(address) { } async function ownesName(address) { - const name = fns.functions.getNameFromOwner(address); + const name = fns.functions.getNameFromOwner(address)[0]; return name !== ""; } From 339bf0b128c6a9cd7b0409c0f7b56ea068ea7b24 Mon Sep 17 00:00:00 2001 From: Pokesi <81540683+Pokesi@users.noreply.github.com> Date: Wed, 30 Mar 2022 12:12:57 +1100 Subject: [PATCH 6/8] Update index.js --- src/utils/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils/index.js b/src/utils/index.js index 689fe46..a13efed 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -3,6 +3,7 @@ import { fns } from 'fns-helper' async function resolveAddress(address) { const name = fns.functions.getNameFromOwner(address)[0]; + console.log("FNS Name resolved: " + name); if (name !== "") { // return name return name; @@ -15,6 +16,7 @@ async function resolveAddress(address) { async function ownesName(address) { const name = fns.functions.getNameFromOwner(address)[0]; + console.log("FNS Name resolved: " + name); return name !== ""; } From a33d1c9d49d7b65432a3c869c9ee605361da2e99 Mon Sep 17 00:00:00 2001 From: Pokesi <81540683+Pokesi@users.noreply.github.com> Date: Wed, 30 Mar 2022 12:18:20 +1100 Subject: [PATCH 7/8] Update index.js --- src/utils/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/index.js b/src/utils/index.js index a13efed..3b199d3 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -38,6 +38,7 @@ export function formatCurrency(amount, decimals = 2) { } export function formatAddress(address, length = 'short') { + console.log("Formatting address: " + address); if (ownesName(address)) { return resolveAddress(address); } else { From 153204bd9a56d133ffd19e0290aa7278b0f4441d Mon Sep 17 00:00:00 2001 From: Pokesi <81540683+Pokesi@users.noreply.github.com> Date: Wed, 30 Mar 2022 12:25:28 +1100 Subject: [PATCH 8/8] Update index.js --- src/utils/index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/utils/index.js b/src/utils/index.js index 3b199d3..0df1d3e 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -37,6 +37,7 @@ export function formatCurrency(amount, decimals = 2) { } } +/* export function formatAddress(address, length = 'short') { console.log("Formatting address: " + address); if (ownesName(address)) { @@ -53,6 +54,19 @@ export function formatAddress(address, length = 'short') { } } } +*/ +export function formatAddress(address, length = 'short') { + if (address && length === 'short') { + address = address.substring(0, 6) + '...' + address.substring(address.length - 4, address.length) + return address + } else if (address && length === 'long') { + address = address.substring(0, 12) + '...' + address.substring(address.length - 8, address.length) + return address + } else { + return null + } +} + export function bnDec(decimals) { return new BigNumber(10).pow(parseInt(decimals))