Skip to content

Commit

Permalink
ui agent events
Browse files Browse the repository at this point in the history
  • Loading branch information
bokkypoobah committed Sep 11, 2024
1 parent fd09f83 commit 17a7a0f
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 79 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ List of offers added by the Token Agent owner

<br />

List of events emitted by this Token Agent

<kbd><img src="images/Screenshot_Agent_Events_20240911.png" width="600"/></kbd>

<br />

All offers invalidated after the Token Agent owner call's `invalidateOffers()` to increase the `nonce`

<kbd><img src="images/Screenshot_Agent_OffersInvalidated_20240911.png" width="600"/></kbd>
Expand Down
170 changes: 93 additions & 77 deletions docs/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,61 @@ const Agent = {
</template>
<template #cell(when)="data">
<font size="-1">
{{ formatTimestamp(data.item.timestamp) }}
<b-link size="sm" :href="explorer + 'tx/' + data.item.txHash + '#eventlog#' + data.item.logIndex" variant="link" v-b-popover.hover.ds500="data.item.blockNumber + ':' + data.item.txIndex + '.' + data.item.logIndex" target="_blank">
{{ formatTimestamp(data.item.timestamp) }}
</b-link>
</font>
</template>
<template #cell(eventType)="data">
<font size="-1">
<!-- <b-badge variant="light" class="m-0 p-0"> -->
{{ data.item.eventType }}
<!-- </b-badge> -->
</font>
</template>
<template #cell(taker)="data">
<font v-if="data.item.taker" size="-1">
<b-link size="sm" :href="explorer + 'address/' + data.item.taker" variant="link" v-b-popover.hover.ds500="data.item.taker" target="_blank">
{{ data.item.taker.substring(0, 10) + '...' + data.item.taker.slice(-8) }}
</b-link>
</font>
</template>
<template #cell(maker)="data">
<font v-if="data.item.maker" size="-1">
<b-link size="sm" :href="explorer + 'address/' + data.item.maker" variant="link" v-b-popover.hover.ds500="data.item.maker" target="_blank">
{{ data.item.maker.substring(0, 10) + '...' + data.item.maker.slice(-8) }}
</b-link>
</font>
</template>
<template #cell(token)="data">
<font v-if="data.item.token" size="-1">
<b-link size="sm" :href="explorer + 'token/' + data.item.token" variant="link" v-b-popover.hover.ds500="data.item.token" target="_blank">
{{ data.item.token.substring(0, 10) + '...' + data.item.token.slice(-8) }}
</b-link>
</font>
</template>
<template #cell(info)="data">
<font size="-2"><pre>
<div v-if="data.item.eventType == 'Offered'">
<font size="-1">
index: {{ data.item.index }},
type: {{ data.item.tokenType == 1 ? 'ERC-20' : (data.item.tokenType == 2 ? 'ERC-721' : 'ERC-1155') }},
buySell: {{ data.item.buySell == 0 ? 'Buy' : 'Sell' }},
expiry: {{ data.item.expiry == 0 ? '(no expiry)' : formatTimestamp(data.item.expiry) }},
count: {{ data.item.count }},
nonce: {{ data.item.nonce }},
prices: [{{ data.item.prices.map(e => formatDecimals(e, 18)).join(', ') }}]
tokenIds: [{{ data.item.tokenIds.map(e => parseInt(e)).join(', ') }}]
tokenss: [{{ data.item.tokenss.map(e => formatDecimals(e, 18)).join(', ') }}]
</font>
</div>
<div v-else-if="data.item.eventType == 'OffersInvalidated'">
<font size="-1">
newNonce: {{ data.item.newNonce }}
</font>
<!-- <font size="-2"><pre>
{{ JSON.stringify(data.item, null, 2) }}
</pre></font>
</pre></font> -->
</div>
</template>
</b-table>
</b-card>
Expand Down Expand Up @@ -502,9 +550,12 @@ const Agent = {
],
eventsFields: [
{ key: 'number', label: '#', sortable: false, thStyle: 'width: 5%;', tdClass: 'text-truncate' },
{ key: 'when', label: 'When', sortable: false, thStyle: 'width: 20%;', thClass: 'text-left', tdClass: 'text-left' },
{ key: 'type', label: 'Type', sortable: false, thStyle: 'width: 10%;', tdClass: 'text-left' },
{ key: 'info', label: 'Info', sortable: false, thStyle: 'width: 65%;', tdClass: 'text-left' },
{ key: 'when', label: 'When', sortable: false, thStyle: 'width: 12%;', thClass: 'text-left', tdClass: 'text-left' },
{ key: 'maker', label: 'Maker', sortable: false, thStyle: 'width: 12%;', tdClass: 'text-left' },
{ key: 'taker', label: 'Taker', sortable: false, thStyle: 'width: 12%;', tdClass: 'text-left' },
{ key: 'token', label: 'Token', sortable: false, thStyle: 'width: 12%;', tdClass: 'text-left' },
{ key: 'eventType', label: 'Event Type', sortable: false, thStyle: 'width: 10%;', tdClass: 'text-left' },
{ key: 'info', label: 'Info', sortable: false, thStyle: 'width: 37%;', tdClass: 'text-left' },
],
approvalsFields: [
{ key: 'number', label: '#', sortable: false, thStyle: 'width: 5%;', tdClass: 'text-truncate' },
Expand Down Expand Up @@ -666,7 +717,7 @@ const Agent = {
},

nonce() {
const events = this.events.filter(e => e.type == "OffersInvalidated");
const events = this.events.filter(e => e.eventType == "OffersInvalidated");
if (events.length > 0) {
return events[events.length - 1].newNonce;
}
Expand All @@ -675,40 +726,23 @@ const Agent = {

filteredSortedEvents() {
const results = this.events;
// console.log(JSON.stringify(results, null, 2));
// if (this.settings.sortOption == 'ownertokenagentasc') {
// results.sort((a, b) => {
// if (('' + a.owner).localeCompare(b.owner) == 0) {
// return ('' + a.transferAgent).localeCompare(b.transferAgent);
// } else {
// return ('' + a.owner).localeCompare(b.owner);
// }
// });
// } else if (this.settings.sortOption == 'ownertokenagentdsc') {
// results.sort((a, b) => {
// if (('' + a.owner).localeCompare(b.owner) == 0) {
// return ('' + a.transferAgent).localeCompare(b.transferAgent);
// } else {
// return ('' + b.owner).localeCompare(a.owner);
// }
// });
// } else if (this.settings.sortOption == 'tokenagentasc') {
// results.sort((a, b) => {
// return ('' + a.tokenAgent).localeCompare(b.tokenAgent);
// });
// } else if (this.settings.sortOption == 'tokenagentdsc') {
// results.sort((a, b) => {
// return ('' + b.tokenAgent).localeCompare(a.tokenAgent);
// });
// } else if (this.settings.sortOption == 'indexasc') {
// results.sort((a, b) => {
// return a.index - b.index;
// });
// } else if (this.settings.sortOption == 'indexdsc') {
// results.sort((a, b) => {
// return b.index - a.index;
// });
// }
if (this.settings.events.sortOption == 'txorderasc') {
results.sort((a, b) => {
if (a.blockNumber == b.blockNumber) {
return a.logIndex - b.logIndex;
} else {
return a.blockNumber - b.blockNumber;
}
});
} else if (this.settings.events.sortOption == 'txorderdsc') {
results.sort((a, b) => {
if (a.blockNumber == b.blockNumber) {
return b.logIndex - a.logIndex;
} else {
return b.blockNumber - a.blockNumber;
}
});
}
return results;
},
pagedFilteredSortedEvents() {
Expand All @@ -717,45 +751,27 @@ const Agent = {
},

offers() {
const results = this.events.filter(e => e.type == "Offered");
return results;
return this.events.filter(e => e.eventType == "Offered");
},
filteredSortedOffers() {
const results = this.offers;
// console.log(JSON.stringify(results, null, 2));
// if (this.settings.sortOption == 'ownertokenagentasc') {
// results.sort((a, b) => {
// if (('' + a.owner).localeCompare(b.owner) == 0) {
// return ('' + a.transferAgent).localeCompare(b.transferAgent);
// } else {
// return ('' + a.owner).localeCompare(b.owner);
// }
// });
// } else if (this.settings.sortOption == 'ownertokenagentdsc') {
// results.sort((a, b) => {
// if (('' + a.owner).localeCompare(b.owner) == 0) {
// return ('' + a.transferAgent).localeCompare(b.transferAgent);
// } else {
// return ('' + b.owner).localeCompare(a.owner);
// }
// });
// } else if (this.settings.sortOption == 'tokenagentasc') {
// results.sort((a, b) => {
// return ('' + a.tokenAgent).localeCompare(b.tokenAgent);
// });
// } else if (this.settings.sortOption == 'tokenagentdsc') {
// results.sort((a, b) => {
// return ('' + b.tokenAgent).localeCompare(a.tokenAgent);
// });
// } else if (this.settings.sortOption == 'indexasc') {
// results.sort((a, b) => {
// return a.index - b.index;
// });
// } else if (this.settings.sortOption == 'indexdsc') {
// results.sort((a, b) => {
// return b.index - a.index;
// });
// }
if (this.settings.offers.sortOption == 'txorderasc') {
results.sort((a, b) => {
if (a.blockNumber == b.blockNumber) {
return a.logIndex - b.logIndex;
} else {
return a.blockNumber - b.blockNumber;
}
});
} else if (this.settings.offers.sortOption == 'txorderdsc') {
results.sort((a, b) => {
if (a.blockNumber == b.blockNumber) {
return b.logIndex - a.logIndex;
} else {
return b.blockNumber - a.blockNumber;
}
});
}
return results;
},
pagedFilteredSortedOffers() {
Expand Down
4 changes: 2 additions & 2 deletions docs/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function parseTokenAgentEventLogs(logs, chainId, tokenAgentAddress, tokenAgentAb
// event Offered(Index index, Account indexed maker, Token indexed token, TokenType tokenType, BuySell buySell, Unixtime expiry, Count count, Nonce nonce, Price[] prices, TokenId[] tokenIds, Tokens[] tokenss, Unixtime timestamp);
const [index, maker, token, tokenType, buySell, expiry, count, nonce, prices, tokenIds, tokenss, timestamp] = logData.args;
eventRecord = {
type: "Offered", index, maker, token, tokenType, buySell, expiry, count, nonce,
eventType: "Offered", index, maker, token, tokenType, buySell, expiry, count, nonce,
prices: prices.map(e => ethers.BigNumber.from(e).toString()),
tokenIds: tokenIds.map(e => ethers.BigNumber.from(e).toString()),
tokenss: tokenss.map(e => ethers.BigNumber.from(e).toString()),
Expand All @@ -76,7 +76,7 @@ function parseTokenAgentEventLogs(logs, chainId, tokenAgentAddress, tokenAgentAb
} else if (logData.eventFragment.name == "OffersInvalidated") {
// event OffersInvalidated(Nonce newNonce, Unixtime timestamp);
const [newNonce, timestamp] = logData.args;
eventRecord = { type: "OffersInvalidated", newNonce, timestamp };
eventRecord = { eventType: "OffersInvalidated", newNonce, timestamp };
} else {
console.log(now() + " INFO functions:parseTokenAgentEventLogs - UNHANDLED log: " + JSON.stringify(log));
}
Expand Down
Binary file added images/Screenshot_Agent_Events_20240911.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 17a7a0f

Please sign in to comment.