diff --git a/src/components/BlockTransactionsTable.vue b/src/components/BlockTransactionsTable.vue new file mode 100644 index 00000000..118cfdd0 --- /dev/null +++ b/src/components/BlockTransactionsTable.vue @@ -0,0 +1,989 @@ + + + + + diff --git a/src/components/TransactionsTable.vue b/src/components/TransactionsTable.vue index 41cf2b53..d83e682c 100644 --- a/src/components/TransactionsTable.vue +++ b/src/components/TransactionsTable.vue @@ -251,8 +251,9 @@ export default defineComponent({ const filterRows = () => { filteredRows.value = rows.value; }; + const loadTableData = async (): Promise => { - let tableData: Action[] = []; + let tableData: Action[]; if (isTransaction.value) { tableData = (await api.getTransaction(account.value)).actions; } else if (hasActions.value) { @@ -260,21 +261,46 @@ export default defineComponent({ } else { const page = paginationSettings.value.page; let limit = paginationSettings.value.rowsPerPage; - const notified = accountsModel.value ?? ''; - const after = fromDateModel.value !== '' ? new Date(fromDateModel.value).toISOString() : ''; - const before = toDateModel.value !== now ? new Date(toDateModel.value).toISOString() : ''; - const sort = paginationSettings.value.descending ? 'desc' : 'asc'; - const extras: {[key:string]:string} = {}; - if (tokenModel.value) { - extras['act.account'] = tokenModel.value.contract; - // Increase limit to allow for filtering - limit = limit * 3; + let notified = accountsModel.value ?? ''; + let after = ''; + let before = ''; + if (toDateModel.value !== now) { + before = new Date(toDateModel.value).toISOString(); + } + if (fromDateModel.value !== '') { + after = new Date(fromDateModel.value).toISOString(); } + const sort = paginationSettings.value.descending ? 'desc' : 'asc'; + + let extras: {[key:string]:string} | null = tokenModel.value ? { 'act.account': tokenModel.value.contract } : null; if (actionsModel.value) { - extras['act.name'] = actionsModel.value; + extras = extras ? { + ...extras, + 'act.name': actionsModel.value, + } : { + 'act.name': actionsModel.value, + }; + } + + if (page > 1 && currentFirstAction.value === 0) { + currentFirstAction.value = rows.value[0]?.action.global_sequence; } + if (currentFirstAction.value > 0) { + extras = extras ? { + ...extras, + 'global_sequence': '0-' + currentFirstAction.value.toString(), + } : { + 'global_sequence': '0-' + currentFirstAction.value.toString(), + }; + } + + // if token is selected, we need to get all transactions and filter them + // so we eventually will need more than the current page size + if (tokenModel.value) { + limit = 100; + } const response = await api.getTransactions({ page, limit, @@ -292,42 +318,36 @@ export default defineComponent({ if (tableData) { if (tokenModel.value) { tableData = tableData.filter( - item => (item.act.data as {quantity?:string})?.quantity?.includes(tokenModel.value.symbol), + item => (item.act.data as {quantity?:string}).quantity?.includes(tokenModel.value.symbol), ); - } - const flattenedData: TransactionTableRow[] = []; - tableData.forEach((action) => { - const actionsArray = action.act?.data ? [action] : []; - actionsArray.forEach((act) => { - flattenedData.push({ - name: act.trx_id, - transaction: { id: act.trx_id, type: 'transaction' }, - timestamp: act['@timestamp'] || act.timestamp, - action: act, - data: { - data: act.act.data, - name: act.act.name, - }, - actions: actionsArray.map(a => ({ - name: a.trx_id, - transaction: { id: a.trx_id, type: 'transaction' }, - timestamp: a['@timestamp'] || a.timestamp, - action: a, - data: { - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - data: a.act.data, - name: a.act.name, - }, - })), - }); - }); - }); + // take only the first aginationSettings.value.rowsPerPage items + tableData = tableData.slice(0, paginationSettings.value.rowsPerPage); + } - // Apply pagination after filtering - const startIndex = (paginationSettings.value.page - 1) * paginationSettings.value.rowsPerPage; - rows.value = flattenedData.slice(startIndex, startIndex + paginationSettings.value.rowsPerPage); - totalRows.value = flattenedData.length; + rows.value = tableData.map(item => ({ + name: item.trx_id, + transaction: { id: item.trx_id, type: 'transaction' }, + timestamp: item['@timestamp'] || item.timestamp, + action: item, + data: hasActions.value + ? { data: item.data, name: item.account } + : { data: item.act.data, name: item.act.name }, + actions: [ + { + name: item.trx_id, + transaction: { id: item.trx_id, type: 'transaction' }, + timestamp: item['@timestamp'], + action: item, + data: hasActions.value + ? { + data: item.data, + name: item.account, + } + : { data: item.act.data as unknown, name: item.act.name }, + }, + ], + })); } void filterRows(); }; diff --git a/src/pages/Block.vue b/src/pages/Block.vue index 221c1328..ae32134f 100644 --- a/src/pages/Block.vue +++ b/src/pages/Block.vue @@ -1,6 +1,6 @@