forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transaction Events Tab (MystenLabs#3596)
* add beginning event types * lint changes * add the rest of the event types * lint changes * suieventtype -> suievent * get event types compiling on frontend * lint changes * move event types to TS sdk * eventTypes -> events * export type guards for event types * move SuiEvent to ts sdk * lint changes * update moveEvent type * Update mock_data.json * add itemfieldstitle style * make package and transaction module non optional on moveEvent * move event display types to eventDisplay.tsx * remove newObject debug warn * remove new object event log * add basic TransferObject event display * lint changes * add object and address content display helpers * lint changes * handle null event data * lint changes * move eventToDisplay function * lint changes * add display support for publish events * lint changes * add support for deleteObject event display * lint changes * add epochChange & checkpoint event display * lint changes * progress on one-line sender->recipient * lint change * remove extra debug log * truncate from->to addresses in events * tweak sender, recipient labels * add Event display types * unlink publish package event field * add contentLine event display helper * add contentLine display helper * Update eventDisplay.tsx * move eventContent->Link[] mapping to function * lint changes * add event titles list to transactions * hide left event column on narrower screens * lint changes * add missing licenses * max event sidebar text grayer * don't mutate object provided via props * lint changes * remove excess console.log * remove console.log * remove ternary * remove console.log
- Loading branch information
Stella Cannefax
authored
Aug 11, 2022
1 parent
db66b03
commit c5ec447
Showing
11 changed files
with
547 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,226 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { | ||
isMoveEvent, | ||
isNewObjectEvent, | ||
isTransferObjectEvent, | ||
isDeleteObjectEvent, | ||
isPublishEvent, | ||
} from '@mysten/sui.js'; | ||
|
||
import { isBigIntOrNumber } from '../../utils/numberUtil'; | ||
import { getOwnerStr } from '../../utils/objectUtils'; | ||
import { truncate } from '../../utils/stringUtils'; | ||
|
||
import type { Category } from '../../pages/transaction-result/TransactionResultType'; | ||
import type { Link } from '../table/TableCard'; | ||
import type { | ||
MoveEvent, | ||
NewObjectEvent, | ||
ObjectId, | ||
SuiAddress, | ||
SuiEvent, | ||
TransferObjectEvent, | ||
DeleteObjectEvent, | ||
PublishEvent, | ||
} from '@mysten/sui.js'; | ||
|
||
export type ContentItem = { | ||
label: string; | ||
value: string; | ||
monotypeClass: boolean; | ||
link?: boolean; | ||
category?: Category; | ||
}; | ||
|
||
export type EventDisplayData = { | ||
top: { | ||
title: string; | ||
content: (ContentItem | ContentItem[])[]; | ||
}; | ||
fields?: { | ||
title: string; | ||
// css class name to apply to the 'Fields' sub-header | ||
titleStyle?: string; | ||
content: (ContentItem | ContentItem[])[]; | ||
}; | ||
}; | ||
|
||
function addressContent(label: string, addr: SuiAddress) { | ||
return { | ||
label: label, | ||
value: addr, | ||
link: true, | ||
category: 'addresses' as Category, | ||
monotypeClass: true, | ||
}; | ||
} | ||
|
||
function objectContent(label: string, id: ObjectId) { | ||
return { | ||
label: label, | ||
value: id, | ||
link: true, | ||
category: 'objects' as Category, | ||
monotypeClass: true, | ||
}; | ||
} | ||
|
||
function fieldsContent(fields: { [key: string]: any }) { | ||
return Object.keys(fields).map((k) => { | ||
return { | ||
label: k, | ||
value: fields[k].toString(), | ||
monotypeClass: true, | ||
}; | ||
}); | ||
} | ||
|
||
function contentLine( | ||
label: string, | ||
value: string, | ||
monotypeClass: boolean = false | ||
) { | ||
return { | ||
label, | ||
value, | ||
monotypeClass, | ||
}; | ||
} | ||
|
||
export function moveEventDisplay(event: MoveEvent): EventDisplayData { | ||
return { | ||
top: { | ||
title: 'Move Event', | ||
content: [ | ||
contentLine('Type', event.type, true), | ||
addressContent('Sender', event.sender as string), | ||
contentLine('BCS', event.bcs, true), | ||
], | ||
}, | ||
fields: { | ||
title: 'Fields', | ||
titleStyle: 'itemfieldstitle', | ||
content: fieldsContent(event.fields), | ||
}, | ||
}; | ||
} | ||
|
||
export function newObjectEventDisplay(event: NewObjectEvent): EventDisplayData { | ||
const packMod = `${event.packageId}::${event.transactionModule}`; | ||
|
||
return { | ||
top: { | ||
title: 'New Object', | ||
content: [ | ||
contentLine('Module', packMod, true), | ||
[ | ||
addressContent('', event.sender), | ||
addressContent('', getOwnerStr(event.recipient)), | ||
], | ||
], | ||
}, | ||
}; | ||
} | ||
|
||
export function transferObjectEventDisplay( | ||
event: TransferObjectEvent | ||
): EventDisplayData { | ||
return { | ||
top: { | ||
title: 'Transfer Object', | ||
content: [ | ||
contentLine('Type', event.type, true), | ||
objectContent('Object ID', event.objectId), | ||
contentLine('Version', event.version.toString()), | ||
[ | ||
addressContent('', event.sender), | ||
addressContent('', getOwnerStr(event.recipient)), | ||
], | ||
], | ||
}, | ||
}; | ||
} | ||
|
||
export function getAddressesLinks(item: ContentItem[]): Link[] { | ||
return item.map((content) => { | ||
return { | ||
url: content.value, | ||
name: truncate(content.value, 20), | ||
copy: false, | ||
category: content.category, | ||
isLink: true, | ||
} as Link; | ||
}); | ||
} | ||
|
||
export function deleteObjectEventDisplay( | ||
event: DeleteObjectEvent | ||
): EventDisplayData { | ||
const packMod = `${event.packageId}::${event.transactionModule}`; | ||
return { | ||
top: { | ||
title: 'Delete Object', | ||
content: [ | ||
contentLine('Module', packMod, true), | ||
objectContent('Object ID', event.objectId), | ||
addressContent('Sender', event.sender), | ||
], | ||
}, | ||
}; | ||
} | ||
|
||
export function publishEventDisplay(event: PublishEvent): EventDisplayData { | ||
return { | ||
top: { | ||
title: 'Publish', | ||
content: [ | ||
addressContent('Sender', event.sender), | ||
contentLine('Package', event.packageId, true), | ||
], | ||
}, | ||
}; | ||
} | ||
|
||
export function bigintDisplay( | ||
title: string, | ||
label: string, | ||
value: bigint | ||
): EventDisplayData { | ||
return { | ||
top: { | ||
title: title, | ||
content: [contentLine(label, value.toString())], | ||
}, | ||
}; | ||
} | ||
|
||
export function eventToDisplay(event: SuiEvent) { | ||
if ('moveEvent' in event && isMoveEvent(event.moveEvent)) | ||
return moveEventDisplay(event.moveEvent); | ||
|
||
if ('newObject' in event && isNewObjectEvent(event.newObject)) | ||
return newObjectEventDisplay(event.newObject); | ||
|
||
if ( | ||
'transferObject' in event && | ||
isTransferObjectEvent(event.transferObject) | ||
) | ||
return transferObjectEventDisplay(event.transferObject); | ||
|
||
if ('deleteObject' in event && isDeleteObjectEvent(event.deleteObject)) | ||
return deleteObjectEventDisplay(event.deleteObject); | ||
|
||
if ('publish' in event && isPublishEvent(event.publish)) | ||
return publishEventDisplay(event.publish); | ||
|
||
// TODO - once epoch and checkpoint pages exist, make these links | ||
if ('epochChange' in event && isBigIntOrNumber(event.epochChange)) | ||
return bigintDisplay('Epoch Change', 'Epoch ID', event.epochChange); | ||
|
||
if ('checkpoint' in event && isBigIntOrNumber(event.checkpoint)) | ||
return bigintDisplay('Checkpoint', 'Sequence #', event.checkpoint); | ||
|
||
return null; | ||
} |
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
Oops, something went wrong.