Compare commits
8 Commits
30973616b9
...
d6df9784d2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d6df9784d2 | ||
|
|
b922278b49 | ||
| 82a7db63b5 | |||
| 7c53c48cb1 | |||
| 4d9a8a49b9 | |||
|
|
996003fd79 | ||
|
|
2c9a34aff6 | ||
|
|
173d75c57a |
@@ -186,10 +186,14 @@ function renderTransactions(txs) {
|
|||||||
let html = "";
|
let html = "";
|
||||||
let i = 0;
|
let i = 0;
|
||||||
for (const tx of txs) {
|
for (const tx of txs) {
|
||||||
|
// For swap transactions, show the user's own labelled wallet
|
||||||
|
// address instead of the contract address (see issue #55).
|
||||||
const counterparty =
|
const counterparty =
|
||||||
tx.direction === "sent" || tx.direction === "contract"
|
tx.direction === "contract" && tx.directionLabel === "Swap"
|
||||||
? tx.to
|
? tx.from
|
||||||
: tx.from;
|
: tx.direction === "sent" || tx.direction === "contract"
|
||||||
|
? tx.to
|
||||||
|
: tx.from;
|
||||||
const ensName = ensNameMap.get(counterparty) || null;
|
const ensName = ensNameMap.get(counterparty) || null;
|
||||||
const title = addressTitle(counterparty, state.wallets);
|
const title = addressTitle(counterparty, state.wallets);
|
||||||
const dirLabel = tx.directionLabel;
|
const dirLabel = tx.directionLabel;
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ function show() {
|
|||||||
|
|
||||||
// Determine token symbol and balance
|
// Determine token symbol and balance
|
||||||
let symbol, amount, price;
|
let symbol, amount, price;
|
||||||
|
const knownToken = TOKEN_BY_ADDRESS.get(tokenId.toLowerCase());
|
||||||
if (tokenId === "ETH") {
|
if (tokenId === "ETH") {
|
||||||
symbol = "ETH";
|
symbol = "ETH";
|
||||||
amount = parseFloat(addr.balance || "0");
|
amount = parseFloat(addr.balance || "0");
|
||||||
@@ -95,7 +96,14 @@ function show() {
|
|||||||
const tb = (addr.tokenBalances || []).find(
|
const tb = (addr.tokenBalances || []).find(
|
||||||
(t) => t.address.toLowerCase() === tokenId.toLowerCase(),
|
(t) => t.address.toLowerCase() === tokenId.toLowerCase(),
|
||||||
);
|
);
|
||||||
symbol = tb ? tb.symbol : "?";
|
const tracked = (state.trackedTokens || []).find(
|
||||||
|
(t) => t.address.toLowerCase() === tokenId.toLowerCase(),
|
||||||
|
);
|
||||||
|
symbol =
|
||||||
|
(tb && tb.symbol) ||
|
||||||
|
(tracked && tracked.symbol) ||
|
||||||
|
(knownToken && knownToken.symbol) ||
|
||||||
|
"?";
|
||||||
amount = tb ? parseFloat(tb.balance || "0") : 0;
|
amount = tb ? parseFloat(tb.balance || "0") : 0;
|
||||||
price = getPrice(symbol);
|
price = getPrice(symbol);
|
||||||
}
|
}
|
||||||
@@ -138,13 +146,32 @@ function show() {
|
|||||||
const tb = (addr.tokenBalances || []).find(
|
const tb = (addr.tokenBalances || []).find(
|
||||||
(t) => t.address.toLowerCase() === tokenId.toLowerCase(),
|
(t) => t.address.toLowerCase() === tokenId.toLowerCase(),
|
||||||
);
|
);
|
||||||
const tokenName = tb && tb.name ? escapeHtml(tb.name) : null;
|
const tracked = (state.trackedTokens || []).find(
|
||||||
const tokenSymbol = tb && tb.symbol ? escapeHtml(tb.symbol) : null;
|
(t) => t.address.toLowerCase() === tokenId.toLowerCase(),
|
||||||
const tokenDecimals = tb && tb.decimals != null ? tb.decimals : null;
|
);
|
||||||
|
const rawName =
|
||||||
|
(tb && tb.name) ||
|
||||||
|
(tracked && tracked.name) ||
|
||||||
|
(knownToken && knownToken.name) ||
|
||||||
|
null;
|
||||||
|
const rawSymbol =
|
||||||
|
(tb && tb.symbol) ||
|
||||||
|
(tracked && tracked.symbol) ||
|
||||||
|
(knownToken && knownToken.symbol) ||
|
||||||
|
null;
|
||||||
|
const tokenName = rawName ? escapeHtml(rawName) : null;
|
||||||
|
const tokenSymbol = rawSymbol ? escapeHtml(rawSymbol) : null;
|
||||||
|
const tokenDecimals =
|
||||||
|
tb && tb.decimals != null
|
||||||
|
? tb.decimals
|
||||||
|
: tracked && tracked.decimals != null
|
||||||
|
? tracked.decimals
|
||||||
|
: knownToken && knownToken.decimals != null
|
||||||
|
? knownToken.decimals
|
||||||
|
: null;
|
||||||
const tokenHolders = tb && tb.holders != null ? tb.holders : null;
|
const tokenHolders = tb && tb.holders != null ? tb.holders : null;
|
||||||
const dot = addressDotHtml(tokenId);
|
const dot = addressDotHtml(tokenId);
|
||||||
const tokenLink = `https://etherscan.io/token/${escapeHtml(tokenId)}`;
|
const tokenLink = `https://etherscan.io/token/${escapeHtml(tokenId)}`;
|
||||||
const knownToken = TOKEN_BY_ADDRESS.get(tokenId.toLowerCase());
|
|
||||||
const projectUrl = knownToken && knownToken.url ? knownToken.url : null;
|
const projectUrl = knownToken && knownToken.url ? knownToken.url : null;
|
||||||
let infoHtml = `<div class="font-bold mb-2">Contract Address</div>`;
|
let infoHtml = `<div class="font-bold mb-2">Contract Address</div>`;
|
||||||
infoHtml +=
|
infoHtml +=
|
||||||
|
|||||||
@@ -103,10 +103,15 @@ function renderHomeTxList(ctx) {
|
|||||||
let html = "";
|
let html = "";
|
||||||
let i = 0;
|
let i = 0;
|
||||||
for (const tx of homeTxs) {
|
for (const tx of homeTxs) {
|
||||||
|
// For swap transactions, show the user's own labelled wallet
|
||||||
|
// address (the one that initiated the swap) instead of the
|
||||||
|
// contract address which is not useful in the list view.
|
||||||
const counterparty =
|
const counterparty =
|
||||||
tx.direction === "sent" || tx.direction === "contract"
|
tx.direction === "contract" && tx.directionLabel === "Swap"
|
||||||
? tx.to
|
? tx.from
|
||||||
: tx.from;
|
: tx.direction === "sent" || tx.direction === "contract"
|
||||||
|
? tx.to
|
||||||
|
: tx.from;
|
||||||
const dirLabel = tx.directionLabel;
|
const dirLabel = tx.directionLabel;
|
||||||
const amountStr = tx.value
|
const amountStr = tx.value
|
||||||
? escapeHtml(tx.value + " " + tx.symbol)
|
? escapeHtml(tx.value + " " + tx.symbol)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ const {
|
|||||||
const { state, currentAddress } = require("../../shared/state");
|
const { state, currentAddress } = require("../../shared/state");
|
||||||
let ctx;
|
let ctx;
|
||||||
const { getProvider } = require("../../shared/balances");
|
const { getProvider } = require("../../shared/balances");
|
||||||
const { KNOWN_SYMBOLS } = require("../../shared/tokenList");
|
const { KNOWN_SYMBOLS, TOKEN_BY_ADDRESS } = require("../../shared/tokenList");
|
||||||
|
|
||||||
const EXT_ICON =
|
const EXT_ICON =
|
||||||
`<span style="display:inline-block;width:10px;height:10px;margin-left:4px;vertical-align:middle">` +
|
`<span style="display:inline-block;width:10px;height:10px;margin-left:4px;vertical-align:middle">` +
|
||||||
@@ -73,7 +73,15 @@ function updateSendBalance() {
|
|||||||
const tb = (addr.tokenBalances || []).find(
|
const tb = (addr.tokenBalances || []).find(
|
||||||
(t) => t.address.toLowerCase() === token.toLowerCase(),
|
(t) => t.address.toLowerCase() === token.toLowerCase(),
|
||||||
);
|
);
|
||||||
const symbol = tb ? tb.symbol : "?";
|
const knownToken = TOKEN_BY_ADDRESS.get(token.toLowerCase());
|
||||||
|
const tracked = (state.trackedTokens || []).find(
|
||||||
|
(t) => t.address.toLowerCase() === token.toLowerCase(),
|
||||||
|
);
|
||||||
|
const symbol =
|
||||||
|
(tb && tb.symbol) ||
|
||||||
|
(tracked && tracked.symbol) ||
|
||||||
|
(knownToken && knownToken.symbol) ||
|
||||||
|
"?";
|
||||||
const bal = tb ? tb.balance || "0" : "0";
|
const bal = tb ? tb.balance || "0" : "0";
|
||||||
$("send-balance").textContent =
|
$("send-balance").textContent =
|
||||||
"Current balance: " + bal + " " + symbol;
|
"Current balance: " + bal + " " + symbol;
|
||||||
@@ -124,7 +132,15 @@ function init(_ctx) {
|
|||||||
const tb = (addr.tokenBalances || []).find(
|
const tb = (addr.tokenBalances || []).find(
|
||||||
(t) => t.address.toLowerCase() === token.toLowerCase(),
|
(t) => t.address.toLowerCase() === token.toLowerCase(),
|
||||||
);
|
);
|
||||||
tokenSymbol = tb ? tb.symbol : "?";
|
const knownTk = TOKEN_BY_ADDRESS.get(token.toLowerCase());
|
||||||
|
const trackedTk = (state.trackedTokens || []).find(
|
||||||
|
(t) => t.address.toLowerCase() === token.toLowerCase(),
|
||||||
|
);
|
||||||
|
tokenSymbol =
|
||||||
|
(tb && tb.symbol) ||
|
||||||
|
(trackedTk && trackedTk.symbol) ||
|
||||||
|
(knownTk && knownTk.symbol) ||
|
||||||
|
"?";
|
||||||
tokenBalance = tb ? tb.balance || "0" : "0";
|
tokenBalance = tb ? tb.balance || "0" : "0";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ async function fetchTokenBalances(address, blockscoutUrl, trackedTokens) {
|
|||||||
|
|
||||||
balances.push({
|
balances.push({
|
||||||
address: item.token.address_hash,
|
address: item.token.address_hash,
|
||||||
|
name: item.token.name || "",
|
||||||
symbol: item.token.symbol || "???",
|
symbol: item.token.symbol || "???",
|
||||||
decimals: decimals,
|
decimals: decimals,
|
||||||
balance: bal,
|
balance: bal,
|
||||||
|
|||||||
@@ -25,10 +25,11 @@ function hdWalletFromMnemonic(mnemonic) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function hdWalletFromXprv(xprv) {
|
function hdWalletFromXprv(xprv) {
|
||||||
const node = HDNodeWallet.fromExtendedKey(xprv);
|
const root = HDNodeWallet.fromExtendedKey(xprv);
|
||||||
if (!node.privateKey) {
|
if (!root.privateKey) {
|
||||||
throw new Error("Not an extended private key (xprv).");
|
throw new Error("Not an extended private key (xprv).");
|
||||||
}
|
}
|
||||||
|
const node = root.derivePath("44'/60'/0'/0");
|
||||||
const xpub = node.neuter().extendedKey;
|
const xpub = node.neuter().extendedKey;
|
||||||
const firstAddress = node.deriveChild(0).address;
|
const firstAddress = node.deriveChild(0).address;
|
||||||
return { xpub, firstAddress };
|
return { xpub, firstAddress };
|
||||||
@@ -58,7 +59,8 @@ function getSignerForAddress(walletData, addrIndex, decryptedSecret) {
|
|||||||
return node.deriveChild(addrIndex);
|
return node.deriveChild(addrIndex);
|
||||||
}
|
}
|
||||||
if (walletData.type === "xprv") {
|
if (walletData.type === "xprv") {
|
||||||
const node = HDNodeWallet.fromExtendedKey(decryptedSecret);
|
const root = HDNodeWallet.fromExtendedKey(decryptedSecret);
|
||||||
|
const node = root.derivePath("44'/60'/0'/0");
|
||||||
return node.deriveChild(addrIndex);
|
return node.deriveChild(addrIndex);
|
||||||
}
|
}
|
||||||
return new Wallet(decryptedSecret);
|
return new Wallet(decryptedSecret);
|
||||||
|
|||||||
Reference in New Issue
Block a user