Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace wallet addresses with Rave Names FNS names when possible. #1

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
39 changes: 39 additions & 0 deletions src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
import BigNumber from 'bignumber.js'
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;
} else {
// return address
return address;
}
return "Error: no idea";
}

async function ownesName(address) {
const name = fns.functions.getNameFromOwner(address)[0];
console.log("FNS Name resolved: " + name);
return name !== "";
}

export function formatCurrency(amount, decimals = 2) {
if (!isNaN(amount)) {
Expand All @@ -17,6 +37,24 @@ export function formatCurrency(amount, decimals = 2) {
}
}

/*
export function formatAddress(address, length = 'short') {
console.log("Formatting address: " + address);
if (ownesName(address)) {
return resolveAddress(address);
} else {
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 formatAddress(address, length = 'short') {
if (address && length === 'short') {
address = address.substring(0, 6) + '...' + address.substring(address.length - 4, address.length)
Expand All @@ -29,6 +67,7 @@ export function formatAddress(address, length = 'short') {
}
}


export function bnDec(decimals) {
return new BigNumber(10).pow(parseInt(decimals))
}
Expand Down