|
1 | 1 | import { PaymentTransaction } from './payment-transaction' |
2 | | -import { TransactionResult, TransactionSignature } from '@algorandfoundation/algokit-utils/types/indexer' |
3 | | -import { LogicsigModel, MultisigModel, PaymentTransactionModel, SignatureType, SinglesigModel, TransactionType } from '../models' |
| 2 | +import { TransactionResult } from '@algorandfoundation/algokit-utils/types/indexer' |
4 | 3 | import algosdk from 'algosdk' |
5 | | -import { invariant } from '@/utils/invariant' |
6 | | -import { publicKeyToAddress } from '@/utils/publickey-to-addess' |
| 4 | +import { asPaymentTransaction } from '../mappers/transaction-mappers' |
7 | 5 |
|
8 | 6 | type Props = { |
9 | 7 | transaction: TransactionResult |
10 | 8 | } |
11 | 9 |
|
12 | | -const asPaymentTransaction = (transaction: TransactionResult): PaymentTransactionModel => { |
13 | | - invariant(transaction['confirmed-round'], 'confirmed-round is not set') |
14 | | - invariant(transaction['round-time'], 'round-time is not set') |
15 | | - invariant(transaction['payment-transaction'], 'payment-transaction is not set') |
16 | | - |
17 | | - // TODO: Handle notes |
18 | | - return { |
19 | | - id: transaction.id, |
20 | | - type: TransactionType.Payment, |
21 | | - confirmedRound: transaction['confirmed-round'], |
22 | | - roundTime: transaction['round-time'] * 1000, |
23 | | - group: transaction['group'], |
24 | | - fee: transaction.fee.microAlgos(), |
25 | | - sender: transaction.sender, |
26 | | - receiver: transaction['payment-transaction']['receiver'], |
27 | | - amount: transaction['payment-transaction']['amount'].microAlgos(), |
28 | | - closeAmount: transaction['payment-transaction']['close-amount']?.microAlgos(), |
29 | | - signature: transformSignature(transaction.signature), |
30 | | - } satisfies PaymentTransactionModel |
31 | | -} |
32 | | - |
33 | | -const transformSignature = (signature?: TransactionSignature) => { |
34 | | - if (signature?.sig) { |
35 | | - return { |
36 | | - type: SignatureType.Single, |
37 | | - signer: signature.sig, |
38 | | - } satisfies SinglesigModel |
39 | | - } |
40 | | - |
41 | | - if (signature?.multisig) { |
42 | | - return { |
43 | | - type: SignatureType.Multi, |
44 | | - version: signature.multisig.version, |
45 | | - threshold: signature.multisig.threshold, |
46 | | - subsigners: signature.multisig.subsignature.map((subsignature) => publicKeyToAddress(subsignature['public-key'])), |
47 | | - } satisfies MultisigModel |
48 | | - } |
49 | | - |
50 | | - if (signature?.logicsig) { |
51 | | - return { |
52 | | - type: SignatureType.Logic, |
53 | | - logic: signature.logicsig.logic, |
54 | | - } satisfies LogicsigModel |
55 | | - } |
56 | | -} |
57 | | - |
58 | 10 | export function Transaction({ transaction }: Props) { |
59 | 11 | if (transaction['tx-type'] === algosdk.TransactionType.pay) { |
60 | 12 | return <PaymentTransaction transaction={asPaymentTransaction(transaction)} rawTransaction={transaction} /> |
|
0 commit comments