-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5737fd1
commit f84cec8
Showing
11 changed files
with
87 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,41 @@ | ||
import { cn } from '@/features/common/utils' | ||
import { PaymentTransaction } from './payment-transaction' | ||
import { TransactionResult } from '@algorandfoundation/algokit-utils/types/indexer' | ||
import { TransactionType } from 'algosdk' | ||
import { PaymentTransactionModel, TransactionType } from '../models' | ||
import algosdk from 'algosdk' | ||
import invariant from 'tiny-invariant' | ||
|
||
type Props = { | ||
transaction: TransactionResult | ||
} | ||
|
||
const asPaymentTransaction = (transaction: TransactionResult): PaymentTransactionModel => { | ||
invariant(transaction['confirmed-round'], 'confirmed-round is not set') | ||
invariant(transaction['round-time'], 'round-time is not set') | ||
invariant(transaction['payment-transaction'], 'payment-transaction is not set') | ||
|
||
// TODO: Handle notes | ||
return { | ||
id: transaction.id, | ||
type: TransactionType.Payment, | ||
confirmedRound: transaction['confirmed-round'], | ||
roundTime: new Date(transaction['round-time'] * 1000), | ||
group: transaction['group'], | ||
fee: transaction.fee.microAlgos(), | ||
sender: transaction.sender, | ||
receiver: transaction['payment-transaction']['receiver'], | ||
amount: transaction['payment-transaction']['amount'].microAlgos(), | ||
closeAmount: transaction['payment-transaction']['close-amount']?.microAlgos(), | ||
} satisfies PaymentTransactionModel | ||
} | ||
|
||
export function Transaction({ transaction }: Props) { | ||
return ( | ||
<div> | ||
<h1 className={cn('text-2xl text-primary font-bold')}>Transaction</h1> | ||
{transaction['tx-type'] === TransactionType.pay && <PaymentTransaction transaction={transaction} />} | ||
{transaction['tx-type'] === algosdk.TransactionType.pay && ( | ||
<PaymentTransaction transaction={asPaymentTransaction(transaction)} rawTransaction={transaction} /> | ||
)} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { AlgoAmount } from '@algorandfoundation/algokit-utils/types/amount' | ||
|
||
export type TransactionModel = { | ||
id: string | ||
type: TransactionType | ||
confirmedRound: number | ||
roundTime: Date | ||
group?: string | ||
fee: AlgoAmount | ||
sender: string | ||
|
||
base64Note?: string | ||
textNote?: string | ||
messagePackNote?: string | ||
} | ||
|
||
export enum TransactionType { | ||
Payment = 'Payment', | ||
} | ||
|
||
export type PaymentTransactionModel = TransactionModel & { | ||
type: TransactionType.Payment | ||
receiver: string | ||
amount: AlgoAmount | ||
closeAmount?: AlgoAmount | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,5 @@ | ||
import { MicroAlgo } from '@/features/transactions/models/models' | ||
import { format as dateFnsFormat } from 'date-fns' | ||
import Decimal from 'decimal.js' | ||
|
||
export const dateFormatter = { | ||
asLongDateTime: (date: Date) => dateFnsFormat(date, 'EEEE, dd MMMM yyyy HH:mm:ss'), | ||
} | ||
|
||
export const algoFormatter = { | ||
asAlgo: (microAlgo: MicroAlgo) => new Decimal(microAlgo).dividedBy(1_000_000).toFixed(), | ||
} |