Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions frontend/src/routes/OnChain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,6 @@ const SingleTransaction = ({ tx, network }: { tx: OnChainTx, network?: string })
)
}

// Sort by timestamp, but if there's no timestamp put it first
function sortTx(a: OnChainTx, b: OnChainTx) {
if (b.confirmation_time && a.confirmation_time) {
return b.confirmation_time.timestamp - a.confirmation_time.timestamp
} else if (a.confirmation_time) {
return 1
} else if (b.confirmation_time) {
return -1
} else {
return a.txid.localeCompare(b.txid)
}
}

function OnChain() {
const { nodeManager } = useContext(NodeManagerContext);

Expand All @@ -80,7 +67,7 @@ function OnChain() {
</header>
<ScreenMain padSides={false} wontScroll={!transactions || transactions.length < 4}>
<ul className="overflow-y-scroll h-full px-8 pb-[12rem]">
{transactions?.sort(sortTx).map(tx => (
{transactions?.map(tx => (
<SingleTransaction key={tx.txid} tx={tx} network={nodeManager?.get_network()} />
))}
</ul>
Expand Down
12 changes: 11 additions & 1 deletion node-manager/src/nodemanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,17 @@ impl NodeManager {

#[wasm_bindgen]
pub async fn list_onchain(&self) -> Result<JsValue, MutinyJsError> {
let txs = self.wallet.list_transactions(false).await?;
let mut txs = self.wallet.list_transactions(false).await?;

// Sort by timestamp, but if there's no timestamp put it first,
// if timestamps are equal, compare by txid
txs.sort_by(|a, b| {
a.confirmation_time
.as_ref()
.map(|c| c.timestamp)
.cmp(&b.confirmation_time.as_ref().map(|c| c.timestamp))
.then_with(|| a.txid.cmp(&b.txid))
});

Ok(serde_wasm_bindgen::to_value(&txs)?)
}
Expand Down