Skip to content

Commit

Permalink
feat: map NftTransactions to Transaction to prepare data for Transact…
Browse files Browse the repository at this point in the history
…ionTable

Signed-off-by: Tim Schmidt <[email protected]>
  • Loading branch information
Sheng-Long committed Sep 13, 2023
1 parent 29c8419 commit 246a361
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 28 deletions.
4 changes: 1 addition & 3 deletions src/components/transaction/TransactionTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

<o-table-column v-slot="props" field="name" label="Type">
<div class="h-has-pill" style="display: inline-block">
<div class="h-is-text-size-2">{{ makeTypeLabel(props.row.name ? props.row.name : props.row.type) }}</div>
<div class="h-is-text-size-2">{{ makeTypeLabel(props.row.name) }}</div>
</div>
</o-table-column>

Expand Down Expand Up @@ -117,8 +117,6 @@ export default defineComponent({
routeManager.routeToTransaction(t, event.ctrlKey || event.metaKey)
}
console.log(props.controller.rows);
return {
isTouchDevice,
isMediumScreen,
Expand Down
38 changes: 30 additions & 8 deletions src/components/transaction/TransactionTableControllerXL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
*/

import {KeyOperator, SortOrder, TableController} from "@/utils/table/TableController";
import {NftTransaction, NftTransactionResponse, Transaction, TransactionResponse} from "@/schemas/HederaSchemas";
import {NftTransactionTransfer, NftTransactionHistory, Transaction, TransactionResponse} from "@/schemas/HederaSchemas";
import {ComputedRef, ref, Ref, watch, WatchStopHandle} from "vue";
import axios, {AxiosResponse} from "axios";
import {LocationQuery, Router} from "vue-router";
import {fetchStringQueryParam} from "@/utils/RouteManager";


export class TransactionTableControllerXL extends TableController<Transaction | NftTransaction, string> {
export class TransactionTableControllerXL extends TableController<Transaction | NftTransactionTransfer, string> {

private readonly entityId: Ref<string | null>
private readonly accountIdMandatory: boolean
Expand Down Expand Up @@ -54,13 +54,15 @@ export class TransactionTableControllerXL extends TableController<Transaction |
//

public async load(consensusTimestamp: string | null, operator: KeyOperator,
order: SortOrder, limit: number): Promise<Transaction[] | NftTransaction[] | null> {
let result: Promise<Transaction[] | NftTransaction[] | null>
order: SortOrder, limit: number): Promise<Transaction[] | null> {
let result: Promise<Transaction[] | null>

if (this.accountIdMandatory && this.entityId.value === null) {
result = Promise.resolve(null)
} else if (this.entityId.value?.includes("---")) {
const entityArray = this.entityId.value.split("---");
const tokenId = entityArray[0]
const serialNumber = entityArray[1]
const params = {} as {
limit: number
order: string
Expand All @@ -75,11 +77,29 @@ export class TransactionTableControllerXL extends TableController<Transaction |
if (consensusTimestamp !== null) {
params.timestamp = operator + ":" + consensusTimestamp
}
const cb = (r: AxiosResponse<NftTransactionResponse>): Promise<NftTransaction[] | null> => {
return Promise.resolve(r.data.transactions ?? [])
const getTransactions = async() => {
const r = await axios.get<NftTransactionHistory>(`api/v1/tokens/${tokenId}/nfts/${serialNumber}/transactions`, {params: params})
const transactions = r.data.transactions?.map(transaction => {
return <Transaction> {
consensus_timestamp: transaction.consensus_timestamp,
nonce: transaction.nonce,
transaction_id: transaction.transaction_id,
name: transaction.type,
entity_id: transaction.sender_account_id,
nft_transfers: [
{
is_approval: transaction.is_approval,
receiver_account_id: transaction.receiver_account_id,
sender_account_id: transaction.sender_account_id,
serial_number: Number(serialNumber),
token_id: tokenId,
}
],
}
})
return transactions ?? []
}
result = axios.get<NftTransactionResponse>(`api/v1/tokens/${entityArray[0]}/nfts/${entityArray[1]}/transactions`, {params: params}).then(cb)
console.log(result)
result = getTransactions()
} else {
const params = {} as {
limit: number
Expand All @@ -103,6 +123,8 @@ export class TransactionTableControllerXL extends TableController<Transaction |
return Promise.resolve(r.data.transactions ?? [])
}
result = axios.get<TransactionResponse>("api/v1/transactions", {params: params}).then(cb)
let res = await axios.get<TransactionResponse>("api/v1/transactions", {params: params})
console.log(result)
}

return result
Expand Down
58 changes: 41 additions & 17 deletions src/schemas/HederaSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ export interface TransactionResponse {
links: Links | undefined
}

export interface NftTransactionResponse {
transactions: Array<NftTransaction> | undefined
export interface NftTransactionHistory {
transactions: Array<NftTransactionTransfer> | undefined
links: Links | undefined
}

Expand All @@ -142,13 +142,15 @@ export interface TransactionByIdResponse {
}
export interface Transaction {

hello: string | null | undefined
bytes: string | null | undefined
charged_tx_fee: number | undefined
consensus_timestamp: string | undefined
entity_id: string |null | undefined // Network entity ID in the format of shard.realm.num
max_fee: string | undefined
memo_base64: string | undefined // To be checked
name: TransactionType | undefined
nft_transfers: NftTransfer[] | undefined
node: string | null | undefined // Network entity ID in the format of shard.realm.num
nonce: number | undefined
parent_consensus_timestamp: string | null | undefined
Expand All @@ -164,25 +166,15 @@ export interface Transaction {

}

export interface NftTransaction {
export interface NftTransactionTransfer {

consensus_timestamp: string | undefined
entity_id: string |null | undefined // Network entity ID in the format of shard.realm.num
max_fee: string | undefined
memo_base64: string | undefined // To be checked
type: TransactionType | undefined
node: string | null | undefined // Network entity ID in the format of shard.realm.num
nonce: number | undefined
parent_consensus_timestamp: string | null | undefined
result: string | undefined
scheduled: boolean | undefined
staking_reward_transfers: StakingRewardTransfer[] | undefined
token_transfers: TokenTransfer[] | undefined
transaction_hash: string | undefined
transaction_id: string | undefined
transfers: Transfer[] | undefined
valid_duration_seconds: string | undefined
valid_start_timestamp: string | undefined
type: TransactionType | undefined
is_approval: false
receiver_account_id: string |null | undefined // account ID in the format of shard.realm.num
sender_account_id: string |null | undefined // account ID in the format of shard.realm.num

}

Expand All @@ -195,6 +187,7 @@ export interface TransactionDetail extends Transaction {


export interface NftTransfer {
is_approval: boolean
receiver_account_id: string | null | undefined // Network entity ID in the format of shard.realm.num
sender_account_id: string | null | undefined // Network entity ID in the format of shard.realm.num
serial_number: number
Expand Down Expand Up @@ -369,6 +362,37 @@ export interface TokenInfo {
custom_fees: CustomFees
}

export interface NftInfo {

admin_key: Key | null
auto_renew_account: string | null // Network entity ID in the format of shard.realm.num
auto_renew_period: number | null
created_timestamp: string
decimals: string
deleted: boolean | null
expiry_timestamp: string | null
fee_schedule_key: Key | null
freeze_default: boolean
freeze_key: Key | null
initial_supply: string
kyc_key: Key | null
max_supply: string
modified_timestamp: string
name: string
memo: string
pause_key: Key | null
pause_status: string // NOT_APPLICABLE, PAUSED, UNPAUSED
supply_key: Key | null
supply_type: string // FINITE, INFINITE
symbol: string
token_id: string | null // Network entity ID in the format of shard.realm.num
total_supply: string
treasury_account_id: string | null // Network entity ID in the format of shard.realm.num
type: string // FUNGIBLE_COMMON, NON_FUNGIBLE_UNIQUE
wipe_key: Key | null
custom_fees: CustomFees
}

export interface CustomFees {
created_timestamp: string | undefined
fixed_fees: FixedFee[] | undefined // Network entity ID in the format of shard.realm.num
Expand Down

0 comments on commit 246a361

Please sign in to comment.