Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
Prettier v2
Browse files Browse the repository at this point in the history
  • Loading branch information
gre committed May 12, 2020
1 parent 468d571 commit f0da659
Show file tree
Hide file tree
Showing 349 changed files with 5,099 additions and 5,029 deletions.
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@ledgerhq/hw-transport-node-hid": "5.15.0",
"@ledgerhq/hw-transport-node-speculos": "^5.15.0",
"@ledgerhq/ledger-core": "^6.3.0",
"@ledgerhq/live-common": "^12.20.0",
"@ledgerhq/live-common": "^12.21.0",
"@ledgerhq/logs": "5.15.0",
"asciichart": "^1.5.17",
"bignumber.js": "^9.0.0",
Expand Down
51 changes: 26 additions & 25 deletions cli/src/accountFormatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ import {
toAccountRaw,
getAccountCurrency,
getAccountName,
getAccountUnit
getAccountUnit,
} from "@ledgerhq/live-common/lib/account";
import type { Account } from "@ledgerhq/live-common/lib/types";
import { getOperationAmountNumberWithInternals } from "@ledgerhq/live-common/lib/operation";
import { formatCurrencyUnit } from "@ledgerhq/live-common/lib/currencies";
import { getOperationAmountNumber } from "@ledgerhq/live-common/lib/operation";

// TODO move to live common
const isSignificantAccount = acc =>
const isSignificantAccount = (acc) =>
acc.balance.gt(10 ** (getAccountUnit(acc).magnitude - 6));

const formatOp = unitByAccountId => {
const formatOp = (unitByAccountId) => {
const format = (op, level = 0) => {
const amount = formatCurrencyUnit(
unitByAccountId(op.accountId),
getOperationAmountNumber(op),
{
showCode: true,
alwaysShowSign: true
alwaysShowSign: true,
}
);
const spaces = Array((level + 1) * 2)
Expand All @@ -35,11 +35,11 @@ const formatOp = unitByAccountId => {
)}${extra}`;
const sub = (op.subOperations || [])
.concat(op.internalOperations || [])
.map(subop => format(subop, level + 1))
.map((subop) => format(subop, level + 1))
.join("");
return `\n${head}${sub}`;
};
return op => format(op, 0);
return (op) => format(op, 0);
};

const cliFormat = (account, summaryOnly) => {
Expand All @@ -50,25 +50,26 @@ const cliFormat = (account, summaryOnly) => {
derivationMode,
index,
xpub,
operations
operations,
} = account;

const balance = formatCurrencyUnit(account.unit, account.balance, {
showCode: true
showCode: true,
});

const opsCount = `${operations.length} operations`;
const freshInfo = `${freshAddress} on ${freshAddressPath}`;
const derivationInfo = `${derivationMode}#${index}`;
const head = `${name}: ${balance} (${opsCount}) (${freshInfo}) (${derivationInfo} ${xpub ||
""})`;
const head = `${name}: ${balance} (${opsCount}) (${freshInfo}) (${derivationInfo} ${
xpub || ""
})`;

const subAccounts = account.subAccounts || [];
const ops = operations
.map(
formatOp(id => {
formatOp((id) => {
if (account.id === id) return account.unit;
const ta = subAccounts.find(a => a.id === id);
const ta = subAccounts.find((a) => a.id === id);
if (ta) return getAccountUnit(ta);
throw new Error("unexpected missing token account");
})
Expand All @@ -77,15 +78,15 @@ const cliFormat = (account, summaryOnly) => {

const tokens = subAccounts
.map(
ta =>
(ta) =>
"\n " +
ta.type +
" " +
getAccountName(ta) +
": " +
formatCurrencyUnit(getAccountUnit(ta), ta.balance, {
showCode: true,
disableRounding: true
disableRounding: true,
}) +
" (" +
ta.operations.length +
Expand All @@ -96,7 +97,7 @@ const cliFormat = (account, summaryOnly) => {
return head + tokens + (summaryOnly ? "" : ops);
};

const stats = account => {
const stats = (account) => {
const { subAccounts, operations } = account;

const sumOfAllOpsNumber = operations.reduce(
Expand All @@ -105,31 +106,31 @@ const stats = account => {
);

const sumOfAllOps = formatCurrencyUnit(account.unit, sumOfAllOpsNumber, {
showCode: true
showCode: true,
});

const balance = formatCurrencyUnit(account.unit, account.balance, {
showCode: true
showCode: true,
});

return {
balance,
sumOfAllOps,
opsCount: operations.length,
subAccountsCount: (subAccounts || []).length
subAccountsCount: (subAccounts || []).length,
};
};

const all: { [_: string]: (Account) => any } = {
json: account => JSON.stringify(toAccountRaw(account)),
default: account => cliFormat(account),
summary: account => cliFormat(account, true),
stats: account => stats(account),
significantTokenTickers: account =>
json: (account) => JSON.stringify(toAccountRaw(account)),
default: (account) => cliFormat(account),
summary: (account) => cliFormat(account, true),
stats: (account) => stats(account),
significantTokenTickers: (account) =>
(account.subAccounts || [])
.filter(isSignificantAccount)
.map(ta => getAccountCurrency(ta).ticker)
.join("\n")
.map((ta) => getAccountCurrency(ta).ticker)
.join("\n"),
};

export default all;
14 changes: 7 additions & 7 deletions cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ import perFamily from "@ledgerhq/live-common/lib/generated/cli-transaction";
const commands = {
...Object.values(perFamily)
// @ts-ignore
.map(m => typeof m === "object" && m && m.commands)
.map((m) => typeof m === "object" && m && m.commands)
.reduce((acc, c) => ({ ...acc, ...c }), {}),
...commandsMain
...commandsMain,
};

const mainOptions = commandLineArgs(
[
{ name: "command", defaultOption: true },
{ name: "help", alias: "h", type: Boolean }
{ name: "help", alias: "h", type: Boolean },
],
{
stopAtFirstUnknown: true
stopAtFirstUnknown: true,
}
);

Expand Down Expand Up @@ -87,16 +87,16 @@ if (!cmd) {
const argv = mainOptions._unknown || [];
const options = commandLineArgs(cmd.args, { argv });
from(cmd.job(options)).subscribe({
next: log => {
next: (log) => {
if (log !== undefined) console.log(log);
},
error: error => {
error: (error) => {
const e = error instanceof Error ? error : deserializeError(error);
if (process.env.VERBOSE || process.env.VERBOSE_FILE) console.error(e);
else console.error(String(e.message || e));
process.exit(1);
},
complete: () => {
closeAllDevices();
}
},
});
34 changes: 17 additions & 17 deletions cli/src/commands/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,63 +19,63 @@ export default {
name: "verbose",
alias: "v",
type: Boolean,
desc: "enable verbose logs"
desc: "enable verbose logs",
},
{
name: "install",
alias: "i",
type: String,
desc: "install an application by its name",
multiple: true
multiple: true,
},
{
name: "uninstall",
alias: "u",
type: String,
desc: "uninstall an application by its name",
multiple: true
multiple: true,
},
{
name: "open",
alias: "o",
type: String,
desc: "open an application by its display name"
desc: "open an application by its display name",
},
{
name: "quit",
alias: "q",
type: Boolean,
desc: "close current application"
}
desc: "close current application",
},
],
job: ({
device,
verbose,
install,
uninstall,
open,
quit
quit,
}: $Shape<{
device: string,
verbose: boolean,
install: string[],
uninstall: string[],
open: string,
quit: string
quit: string,
}>) =>
withDevice(device || "")(t => {
withDevice(device || "")((t) => {
if (quit) return from(quitApp(t));
if (open) return from(openApp(t, inferManagerApp(open)));

return from(getDeviceInfo(t)).pipe(
mergeMap(deviceInfo =>
mergeMap((deviceInfo) =>
from(manager.getAppsList(deviceInfo, true)).pipe(
mergeMap(list =>
mergeMap((list) =>
concat(
...(uninstall || []).map(application => {
...(uninstall || []).map((application) => {
const { targetId } = deviceInfo;
const app = list.find(
item =>
(item) =>
item.name.toLowerCase() ===
inferManagerApp(application).toLowerCase()
);
Expand All @@ -86,10 +86,10 @@ export default {
}
return uninstallApp(t, targetId, app);
}),
...(install || []).map(application => {
...(install || []).map((application) => {
const { targetId } = deviceInfo;
const app = list.find(
item =>
(item) =>
item.name.toLowerCase() ===
inferManagerApp(application).toLowerCase()
);
Expand All @@ -104,7 +104,7 @@ export default {
)
)
),
verbose ? map(a => a) : ignoreElements()
verbose ? map((a) => a) : ignoreElements()
);
})
}),
};
Loading

1 comment on commit f0da659

@vercel
Copy link

@vercel vercel bot commented on f0da659 May 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.