diff --git a/src/screens/nano/NanoContractDetail.js b/src/screens/nano/NanoContractDetail.js index d335d25..3401907 100644 --- a/src/screens/nano/NanoContractDetail.js +++ b/src/screens/nano/NanoContractDetail.js @@ -11,7 +11,8 @@ import TxRow from '../../components/tx/TxRow'; import hathorLib from '@hathor/wallet-lib'; import nanoApi from '../../api/nanoApi'; import txApi from '../../api/txApi'; -import { Link } from 'react-router-dom' +import { Link } from 'react-router-dom'; +import { useSelector } from 'react-redux'; /** @@ -37,6 +38,11 @@ function NanoContractDetail(props) { // errorMessage {string | null} Error message in case a request to get nano contract data fails const [errorMessage, setErrorMessage] = useState(null); + + const { decimalPlaces } = useSelector((state) => { + return { decimalPlaces: state.serverInfo.decimal_places } + }); + useEffect(() => { let ignore = false; @@ -56,8 +62,7 @@ function NanoContractDetail(props) { } const blueprintInformation = await nanoApi.getBlueprintInformation(transactionData.tx.nc_blueprint_id); - // TODO get all balances after hathor-core supports it - const dataState = await nanoApi.getState(ncId, Object.keys(blueprintInformation.attributes), [], []); + const dataState = await nanoApi.getState(ncId, Object.keys(blueprintInformation.attributes), ['__all__'], []); if (ignore) { // This is to prevent setting a state after the componenet has been already cleaned return; @@ -144,6 +149,33 @@ function NanoContractDetail(props) { }); } + const renderBalances = () => { + return Object.entries(ncState.balances).map(([tokenUid, data]) => ( + + {tokenUid === hathorLib.constants.NATIVE_TOKEN_UID ? tokenUid : {tokenUid}} + {hathorLib.numberUtils.prettyValue(data.value, decimalPlaces)} + + )); + } + + const renderNCBalances = () => { + return ( +
+ + + + + + + + + {renderBalances()} + +
TokenAmount
+
+ ); + } + const renderNCAttributes = () => { return (
@@ -181,8 +213,6 @@ function NanoContractDetail(props) { ); }); } - - // TODO identify that attribute is a token and show as NFT, in case it is. return (

Nano Contract Detail

@@ -191,6 +221,8 @@ function NanoContractDetail(props) {

Blueprint: {ncState.blueprint_name} ({txData.nc_blueprint_id})

Attributes

{ renderNCAttributes() } +

Balances

+ { renderNCBalances() }

History

{history && loadTable()}