Debug tools:
{
const f: FileList | null = e.currentTarget.files;
if (!f || f.length != 1) {
return Promise.reject();
}
const buf = await f[0].arrayBuffer();
const str = new Uint8Array(buf).reduce(
(data, byte) => data + String.fromCharCode(byte),
"",
);
return onImportDatabase(str);
}}
/>
{" "}
{" "}
Logging
setLogLevel(v)}
/>
{downloadedDatabase && (
)}
Coins:
{Object.keys(money_by_exchange).map((ex, idx) => {
const allcoins = money_by_exchange[ex];
allcoins.sort((a, b) => {
if (b.denom_value !== a.denom_value) {
return b.denom_value - a.denom_value;
}
return b.denom_fraction - a.denom_fraction;
});
const coins = allcoins.reduce(
(prev, cur) => {
if (cur.status === CoinStatus.Fresh) prev.usable.push(cur);
if (cur.status === CoinStatus.Dormant) prev.spent.push(cur);
return prev;
},
{
spent: [],
usable: [],
} as SplitedCoinInfo,
);
return (
);
})}
{operations && operations.length > 0 && (
Pending operations
{operations.reverse().map((o) => {
return (
-
{o.type}{" "}
-
{JSON.stringify(o, undefined, 2)}
);
})}
)}
);
}
function ShowAllCoins({
ex,
coins,
currencies,
}: {
ex: string;
coins: SplitedCoinInfo;
currencies: { [ex: string]: string };
}): VNode {
const { i18n } = useTranslationContext();
const [collapsedSpent, setCollapsedSpent] = useState(true);
const [collapsedUnspent, setCollapsedUnspent] = useState(false);
const totalUsable = coins.usable.reduce(
(prev, cur) =>
Amounts.add(prev, {
currency: "NONE",
fraction: cur.denom_fraction,
value: cur.denom_value,
}).amount,
Amounts.zeroOfCurrency("NONE"),
);
const totalSpent = coins.spent.reduce(
(prev, cur) =>
Amounts.add(prev, {
currency: "NONE",
fraction: cur.denom_fraction,
value: cur.denom_value,
}).amount,
Amounts.zeroOfCurrency("NONE"),
);
return (
{ex}: {Amounts.stringifyValue(totalUsable)} {currencies[ex]}
spent: {Amounts.stringifyValue(totalSpent)} {currencies[ex]}
setCollapsedUnspent(true)}>
usable coins
{collapsedUnspent ? (
setCollapsedUnspent(false)}>click to show
) : (
id
|
denom
|
status
|
from refresh?
|
age key count
|
{coins.usable.map((c, idx) => {
return (
{c.id.substring(0, 5)} |
{Amounts.stringifyValue({
value: c.denom_value,
fraction: c.denom_fraction,
currency: "ANY",
})}
|
{c.status} |
{c.from_refresh ? "true" : "false"} |
{String(c.ageKeysCount)} |
);
})}
)}
setCollapsedSpent(true)}>
spent coins
{collapsedSpent ? (
setCollapsedSpent(false)}>
click to show
) : (
id
|
denom
|
status
|
from refresh?
|
{coins.spent.map((c, idx) => {
return (
{c.id.substring(0, 5)} |
{c.denom_value} |
{c.status} |
{c.from_refresh ? "true" : "false"} |
);
})}
)}
);
}
function toBase64(str: string): string {
return btoa(
encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) {
return String.fromCharCode(parseInt(p1, 16));
}),
);
}
export async function confirmReset(
confirmTheResetMessage: string,
cb: () => Promise