Skip to content

Commit

Permalink
Merge pull request #108 from spacemeshos/tweak-drain-tx-ui
Browse files Browse the repository at this point in the history
Display drained amounts next to Drain Transaction
  • Loading branch information
brusherru authored Oct 28, 2024
2 parents 8fc2de8 + 74202fa commit 4adb800
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
13 changes: 11 additions & 2 deletions src/components/TxListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Box, Card, CardBody, Flex, Icon, Text } from '@chakra-ui/react';
import { StdMethods } from '@spacemesh/sm-codec';
import {
IconArrowBigLeftLinesFilled,
IconArrowBigRightLinesFilled,
IconArrowNarrowDown,
IconArrowNarrowLeft,
IconArrowNarrowRight,
Expand Down Expand Up @@ -41,8 +42,16 @@ function TxIcon({ tx, host }: { tx: Transaction; host: Bech32Address }) {
return IconArrowNarrowLeft;
}
}
case StdMethods.Drain:
return IconArrowBigLeftLinesFilled;
case StdMethods.Drain: {
switch (getTxType(tx, host)) {
case TxType.Received:
case TxType.Self:
return IconArrowBigRightLinesFilled;
case TxType.Spent:
default:
return IconArrowBigLeftLinesFilled;
}
}
default:
return IconQuestionMark;
}
Expand Down
28 changes: 23 additions & 5 deletions src/utils/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@ export const getDestinationAddress = <T>(
tx: Transaction<T>,
host: Bech32Address
) => {
if (!isSpendTransaction(tx)) return null;
const destination = tx.parsed?.Destination;
const parsedHost = bech32.decode(host);
const words = bech32.toWords(destination);
return bech32.encode(parsedHost.prefix, words);
if (isSpendTransaction(tx) || isDrainTransaction(tx)) {
const destination = tx.parsed?.Destination;
const parsedHost = bech32.decode(host);
const words = bech32.toWords(destination);
return bech32.encode(parsedHost.prefix, words);
}
return null;
};

export const getTxType = <T>(tx: Transaction<T>, host: Bech32Address) => {
Expand Down Expand Up @@ -151,6 +153,22 @@ export const getTxBalance = <T>(tx: Transaction<T>, host: Bech32Address) => {
}
return null;
}
case TemplateName.Vesting: {
if (isDrainTransaction(tx)) {
const type = getTxType(tx, host);
switch (type) {
case TxType.Self:
case TxType.Received:
return tx.parsed.Amount;
case TxType.Spent: {
return -1n * tx.parsed.Amount;
}
default:
return null;
}
}
return null;
}
default: {
return null;
}
Expand Down

0 comments on commit 4adb800

Please sign in to comment.