Add currency settings, Settings service, and dialog to select fiat currency. Add support for non Official currencies like DOGE when using rates.

This commit is contained in:
2026-05-11 10:41:41 +00:00
parent ebe1d8acda
commit 6c01ac1c1b
28 changed files with 1102 additions and 48 deletions

View File

@@ -23,7 +23,7 @@
* 1 - Error (no output, fails silently for shell integration)
*/
import { existsSync, readdirSync, readFileSync } from "node:fs";
import { existsSync, readdirSync } from "node:fs";
import { join } from "node:path";
import { createHash } from "node:crypto";
@@ -34,6 +34,7 @@ import {
} from "../../utils/paths.js";
import { loadMnemonic } from "../mnemonic.js";
import { Storage } from "../../services/storage.js";
import { SettingsService } from "../../services/settings.js";
import { COMMAND_TREE } from "./completions.js";
// Lazy-loaded modules (only loaded when needed for dynamic completions)
@@ -103,12 +104,8 @@ function listSubcommands(command: string, prefix?: string): void {
*/
function getCurrentMnemonic(): string | null {
try {
const walletConfigPath = getWalletConfigPath();
if (!existsSync(walletConfigPath)) {
return null;
}
const mnemonicFile = readFileSync(walletConfigPath, "utf8").trim();
const settings = new SettingsService(getWalletConfigPath());
const mnemonicFile = settings.getDefaultMnemonic();
if (!mnemonicFile) {
return null;
}

View File

@@ -37,6 +37,7 @@ import { homedir } from "node:os";
* - template.ts: import, list, inspect, set-default
* - invitation.ts: create, append, sign, broadcast, requirements, import, inspect, list
* - resource.ts: list, unreserve, unreserve-all
* - settings.ts: show, get, set
*/
/** Subcommands for the mnemonic command */
@@ -56,6 +57,8 @@ const INVITATION_SUBS = [
];
/** Subcommands for the resource command */
const RESOURCE_SUBS = ["list", "unreserve", "unreserve-all"];
/** Subcommands for the settings command */
const SETTINGS_SUBS = ["show", "get", "set"];
/** Subcommands for the completions command */
const COMPLETIONS_SUBS = ["bash", "zsh", "fish"];
@@ -65,6 +68,7 @@ export const COMMAND_TREE = {
invitation: INVITATION_SUBS,
receive: [],
resource: RESOURCE_SUBS,
settings: SETTINGS_SUBS,
help: [],
completions: COMPLETIONS_SUBS,
} as const;
@@ -77,6 +81,7 @@ const GLOBAL_OPTIONS = [
"--verbose",
"-m",
"--mnemonic-file",
"--currency",
"-o",
"--output",
];

View File

@@ -201,6 +201,17 @@ _{{FUNC_NAME}}_completions() {
fi
;;
settings)
if [[ -z "${subcmd}" ]]; then
COMPREPLY=($(compgen -W "show get set" -- "${cur}"))
elif [[ "${subcmd}" == "get" || "${subcmd}" == "set" ]]; then
local pos=$((cword - subcmd_idx))
if [[ $pos -eq 1 ]]; then
COMPREPLY=($(compgen -W "currency default-mnemonic" -- "${cur}"))
fi
fi
;;
receive)
# receive <template> [output]
# Template is the first positional argument after `receive`.

View File

@@ -35,6 +35,7 @@ complete -c {{BIN_NAME}} -s v -d "Verbose output"
complete -c {{BIN_NAME}} -l verbose -d "Verbose output"
complete -c {{BIN_NAME}} -s o -d "Output file"
complete -c {{BIN_NAME}} -l output -d "Output file"
complete -c {{BIN_NAME}} -l currency -d "Set fiat display currency"
# Dynamic completion for `-m/--mnemonic-file`.
complete -c {{BIN_NAME}} -s m -l mnemonic-file -xa '(__{{FUNC_NAME}}_complete_dynamic mnemonics)'

View File

@@ -180,6 +180,17 @@ _{{FUNC_NAME}}_completions() {
fi
;;
settings)
if [[ -z "${subcmd}" ]]; then
compadd -- show get set
elif [[ "${subcmd}" == "get" || "${subcmd}" == "set" ]]; then
local pos=$((CURRENT - subcmd_idx))
if [[ $pos -eq 1 ]]; then
compadd -- currency default-mnemonic
fi
fi
;;
receive)
# receive <template> [output]
local pos=$((CURRENT - cmd_idx))