Fix history for the 100th time. Fix role resolution in the invitation screen
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import type {
|
||||
HistoryItem,
|
||||
HistoryInvitationItem,
|
||||
HistoryUtxoItem,
|
||||
WalletHistoryInput,
|
||||
WalletHistoryItem,
|
||||
WalletHistoryOutput,
|
||||
} from "../services/history.js";
|
||||
|
||||
export type HistoryColorName =
|
||||
@@ -13,10 +14,9 @@ export type HistoryColorName =
|
||||
| "text";
|
||||
|
||||
export type HistoryRowType =
|
||||
| "invitation"
|
||||
| "invitation_input"
|
||||
| "invitation_output"
|
||||
| "utxo";
|
||||
| "history_item"
|
||||
| "history_input"
|
||||
| "history_output";
|
||||
|
||||
export interface HistoryDisplayRow {
|
||||
id: string;
|
||||
@@ -25,8 +25,11 @@ export interface HistoryDisplayRow {
|
||||
description?: string;
|
||||
timestamp?: number;
|
||||
isNested: boolean;
|
||||
utxo?: HistoryUtxoItem;
|
||||
invitation?: HistoryInvitationItem;
|
||||
valueSatoshis?: bigint;
|
||||
reserved?: boolean;
|
||||
input?: WalletHistoryInput;
|
||||
output?: WalletHistoryOutput;
|
||||
item?: WalletHistoryItem;
|
||||
}
|
||||
|
||||
export function formatHistoryDate(timestamp?: number): string | undefined {
|
||||
@@ -40,61 +43,68 @@ export function buildHistoryDisplayRows(
|
||||
const rows: HistoryDisplayRow[] = [];
|
||||
|
||||
for (const item of items) {
|
||||
if (item.kind === "invitation") {
|
||||
rows.push({
|
||||
id: item.id,
|
||||
type: "invitation",
|
||||
label: item.description,
|
||||
timestamp: item.createdAtTimestamp,
|
||||
isNested: false,
|
||||
invitation: item,
|
||||
});
|
||||
|
||||
for (const input of item.inputs) {
|
||||
const satsPrefix =
|
||||
input.valueSatoshis !== undefined
|
||||
? `${input.valueSatoshis.toLocaleString()} sats `
|
||||
: "";
|
||||
rows.push({
|
||||
id: `${item.id}-input-${input.id}`,
|
||||
type: "invitation_input",
|
||||
label: `${satsPrefix}${input.outpoint.txid}:${input.outpoint.index}`,
|
||||
description: input.description,
|
||||
isNested: true,
|
||||
utxo: input,
|
||||
invitation: item,
|
||||
});
|
||||
}
|
||||
|
||||
const roles = item.roles.length > 0 ? item.roles.join(", ") : "unknown";
|
||||
if (item.source === "utxo") {
|
||||
for (const output of item.outputs) {
|
||||
rows.push({
|
||||
id: `${item.id}-output-${output.id}`,
|
||||
type: "invitation_output",
|
||||
label:
|
||||
output.valueSatoshis !== undefined
|
||||
? `${output.valueSatoshis.toLocaleString()} sats`
|
||||
: "Output",
|
||||
description: output.description,
|
||||
isNested: true,
|
||||
utxo: output,
|
||||
invitation: item,
|
||||
type: "history_output",
|
||||
label: output.outpoint
|
||||
? `${output.outpoint.txid}:${output.outpoint.index}`
|
||||
: output.outputIdentifier ?? "Output",
|
||||
description: `${item.template} | ${roles} | ${output.description}`,
|
||||
timestamp: item.createdAtTimestamp,
|
||||
isNested: false,
|
||||
valueSatoshis: output.valueSatoshis,
|
||||
reserved: output.reserved,
|
||||
output,
|
||||
item,
|
||||
});
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
rows.push({
|
||||
id: item.id,
|
||||
type: "utxo",
|
||||
label:
|
||||
item.valueSatoshis !== undefined
|
||||
? `${item.valueSatoshis.toLocaleString()} sats`
|
||||
: "UTXO",
|
||||
description: item.description,
|
||||
type: "history_item",
|
||||
label: `${item.template} | ${roles} | ${item.description}`,
|
||||
description: item.action,
|
||||
timestamp: item.createdAtTimestamp,
|
||||
isNested: false,
|
||||
utxo: item,
|
||||
valueSatoshis: item.valueSatoshis,
|
||||
item,
|
||||
});
|
||||
|
||||
if (item.source !== "invitation") continue;
|
||||
|
||||
for (const input of item.inputs) {
|
||||
rows.push({
|
||||
id: `${item.id}-input-${input.id}`,
|
||||
type: "history_input",
|
||||
label: `${input.outpoint.txid}:${input.outpoint.index}`,
|
||||
description: input.description,
|
||||
isNested: true,
|
||||
valueSatoshis: input.valueSatoshis,
|
||||
input,
|
||||
item,
|
||||
});
|
||||
}
|
||||
|
||||
for (const output of item.outputs) {
|
||||
rows.push({
|
||||
id: `${item.id}-output-${output.id}`,
|
||||
type: "history_output",
|
||||
label: output.outpoint
|
||||
? `${output.outpoint.txid}:${output.outpoint.index}`
|
||||
: output.outputIdentifier ?? "Output",
|
||||
description: output.description,
|
||||
isNested: true,
|
||||
valueSatoshis: output.valueSatoshis,
|
||||
reserved: output.reserved,
|
||||
output,
|
||||
item,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return rows;
|
||||
@@ -106,14 +116,14 @@ export function getHistoryItemColorName(
|
||||
): HistoryColorName {
|
||||
if (isSelected) return "info";
|
||||
switch (row.type) {
|
||||
case "invitation":
|
||||
return "text";
|
||||
case "invitation_input":
|
||||
case "history_input":
|
||||
return "error";
|
||||
case "invitation_output":
|
||||
return "success";
|
||||
case "utxo":
|
||||
return row.utxo?.reserved ? "warning" : "success";
|
||||
case "history_output":
|
||||
return row.reserved ? "warning" : "success";
|
||||
case "history_item":
|
||||
if ((row.valueSatoshis ?? 0n) < 0n) return "error";
|
||||
if ((row.valueSatoshis ?? 0n) > 0n) return "success";
|
||||
return "text";
|
||||
default:
|
||||
return "text";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user