Skip to content

feat: improve UI/UX for nano state detail and tx data with new custom types #654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"private": true,
"dependencies": {
"@hathor/wallet-lib": "1.8.0",
"@hathor/wallet-lib": "1.10.0",
"@ledgerhq/hw-transport-node-hid": "6.28.1",
"@reduxjs/toolkit": "2.2.3",
"@sentry/electron": "3.0.7",
Expand Down
15 changes: 12 additions & 3 deletions src/components/TxData.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ class TxData extends React.Component {

const network = hathorLib.config.getNetwork();
const ncData = this.props.transaction;
const deserializer = new hathorLib.NanoContractTransactionParser(ncData.nc_blueprint_id, ncData.nc_method, ncData.nc_pubkey, ncData.nc_args);
deserializer.parseAddress(network);
const deserializer = new hathorLib.NanoContractTransactionParser(ncData.nc_blueprint_id, ncData.nc_method, ncData.nc_pubkey, network, ncData.nc_args);
deserializer.parseAddress();
await deserializer.parseArguments();
this.setState({ ncDeserializer: deserializer, ncLoading: false });
}
Expand Down Expand Up @@ -952,10 +952,19 @@ class TxData extends React.Component {
}

const renderArgValue = (arg) => {
if (arg.type === 'bytes') {
const typeBytesOrigin = ['bytes', 'TxOutputScript', 'TokenUid', 'VertexId', 'ContractId'];
if (typeBytesOrigin.includes(arg.type)) {
return arg.parsed.toString('hex');
}

if (arg.type === 'Timestamp') {
return hathorLib.dateFormatter.parseTimestamp(arg.parsed);
}

if (arg.type === 'Amount') {
return numberUtils.prettyValue(arg.parsed, this.props.decimalPlaces);
}

return arg.parsed;
}

Expand Down
30 changes: 23 additions & 7 deletions src/screens/nano/NanoContractDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ function NanoContractDetail() {
const context = useContext(GlobalModalContext);
const wallet = getGlobalWallet();

const { nanoContracts, blueprintsData, tokenMetadata, decimalPlaces } = useSelector((state) => {
const {
nanoContracts,
blueprintsData,
tokenMetadata,
decimalPlaces,
} = useSelector((state) => {
return {
nanoContracts: state.nanoContracts,
blueprintsData: state.blueprintsData,
Expand Down Expand Up @@ -170,12 +175,23 @@ function NanoContractDetail() {
return get(blueprintInformation.attributes, field);
}

// Some fields should be better parsed, e.g., timestamp, address
// however we don't have a simple and generic way to knowing it
// this was discussed and we will have this in the future, so
// for now we keep this UI and when we have this feature in the
// hathor-core, we can improve the user UI
return value === null ? ' - ' : value;
if (value == null) {
// If value is null or undefined, we show empty string
return null;
}

// Get type of value but removing possible optional mark (?) to format the value correctly
const type = blueprintInformation.attributes[field].replace('?', '');

if (type === 'Timestamp') {
return hathorLib.dateUtils.parseTimestamp(value);
}

if (type === 'Amount') {
return hathorLib.numberUtils.prettyValue(value, decimalPlaces);
}

return value;
}

/**
Expand Down