Skip to content
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

feat: add nano contracts list #387

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import WebSocketHandler from './WebSocketHandler';
import NanoContractDetail from './screens/nano/NanoContractDetail';
import BlueprintDetail from './screens/nano/BlueprintDetail';
import BlueprintList from './screens/nano/BlueprintList';
import NanoContractsList from './screens/nano/NanoContractsList';
import {
apiLoadErrorUpdate,
dashboardUpdate,
Expand Down Expand Up @@ -169,6 +170,10 @@ function Root() {
element={<NavigationRoute internalScreen={BlueprintDetail} />}
/>
<Route path="/blueprints/" element={<NavigationRoute internalScreen={BlueprintList} />} />
<Route
path="/nano_contracts/"
element={<NavigationRoute internalScreen={NanoContractsList} />}
/>
<Route path="" element={<NavigationRoute internalScreen={DashboardTx} />} />
</Routes>
</BrowserRouter>
Expand Down
38 changes: 38 additions & 0 deletions src/api/nanoApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,44 @@ const nanoApi = {
);
});
},

/**
* Get list of nano contract creation txs
*
* @param {number | null} count Number of elements to get the list
* @param {string | null} after ID of the blueprint to get as reference for after pagination
* @param {string | null} before ID of the blueprint to get as reference for before pagination
* @param {string | null} search ID of the blueprint or nano contract creation to filter in the API
* @param {string | null} order Order of the sorting ('asc' or 'desc')
*
* For more details, see full node api docs
*/
getNanoContractCreationList(count, after, before, search, order) {
const data = {};
if (count) {
data.count = count;
}
if (after) {
data.after = after;
}
if (before) {
data.before = before;
}
if (search) {
data.search = search;
}
if (order) {
data.order = order;
}
return requestExplorerServiceV1
.get(`node_api/nc_creation_list`, { params: data })
.then(res => res.data)
.catch(err => {
throw new Error(
err?.data?.message || err?.message || `Unknown error on get nano contract creation list`
);
});
},
};

export default nanoApi;
48 changes: 29 additions & 19 deletions src/components/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ function Navigation() {
const txSearchRef = useRef(null);
const isTokensBaseEnabled = useFlag(`${UNLEASH_TOKENS_BASE_FEATURE_FLAG}.rollout`);
const isTokensBalanceEnabled = useFlag(`${UNLEASH_TOKEN_BALANCES_FEATURE_FLAG}.rollout`);
const theme = useSelector(state => state.theme);
const { serverInfo, theme } = useSelector(state => {
return {
serverInfo: state.serverInfo,
theme: state.theme,
};
});
const newUiEnabled = useNewUiEnabled();
const [showSearchInput, setShowSearchInput] = useState(false);
const [showSidebar, setShowSidebar] = useState(false);
Expand Down Expand Up @@ -147,24 +152,29 @@ function Navigation() {
</div>
</ul>
)}
<li className="nav-item dropdown">
<span
className="nav-link dropdown-toggle custom-dropdown-toggle"
id="navbarDropdown"
role="button"
data-bs-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
>
Nano
<ArrorDownNavItem className="dropdown-icon" />
</span>
<div className="dropdown-menu" aria-labelledby="navbarDropdown">
<NavLink to="/blueprints/?type=built-in" exact className="nav-link">
Blueprints List
</NavLink>
</div>
</li>
{serverInfo.nano_contracts_enabled && (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Is it possible that this component is rendered before the server info arrives? If so, it's important to protect this validation with a conditional.

Suggested change
{serverInfo.nano_contracts_enabled && (
{serverInfo?.nano_contracts_enabled && (

<li className="nav-item dropdown">
<span
className="nav-link dropdown-toggle custom-dropdown-toggle"
id="navbarDropdown"
role="button"
data-bs-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
>
Nano
<ArrorDownNavItem className="dropdown-icon" />
</span>
<div className="dropdown-menu" aria-labelledby="navbarDropdown">
<NavLink to="/nano_contracts/" className="nav-link">
Nano Contracts List
</NavLink>
<NavLink to="/blueprints/?type=built-in" className="nav-link">
Blueprints List
</NavLink>
</div>
</li>
)}
<li className="nav-item">
<NavLink
to="/network"
Expand Down
52 changes: 31 additions & 21 deletions src/components/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ function Sidebar({ close, open }) {
const isTokensBaseEnabled = useFlag(`${UNLEASH_TOKENS_BASE_FEATURE_FLAG}.rollout`);
const isTokensBalanceEnabled = useFlag(`${UNLEASH_TOKEN_BALANCES_FEATURE_FLAG}.rollout`);
const showTokensTab = isTokensBalanceEnabled || isTokensBaseEnabled;
const theme = useSelector(state => state.theme);
const { serverInfo, theme } = useSelector(state => {
return {
serverInfo: state.serverInfo,
theme: state.theme,
};
});
const sidebarRef = useRef(null);
const [tokensOpen, setTokensOpen] = useState(false);
const [nanoOpen, setNanoOpen] = useState(false);
Expand Down Expand Up @@ -96,26 +101,31 @@ function Sidebar({ close, open }) {
)}
</span>
)}
<li className="nav-item item-sidebar">
<span onClick={() => setNanoOpen(!nanoOpen)}>
Nano{' '}
<ArrorDownNavItem
style={{ marginLeft: '5px', rotate: toolsOpen ? '180deg' : '0deg' }}
className="dropdown-icon"
/>
</span>
{nanoOpen && (
<div>
<ul style={{ listStyleType: 'none', padding: 0, margin: 0 }}>
<li>
<NavLink to="/blueprints/?type=built-in" exact className="nav-link">
Blueprints List
</NavLink>
</li>
</ul>
</div>
)}
</li>
{serverInfo.nano_contracts_enabled && (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: If the protection is needed on the Navigation bar, add it here as well.

Suggested change
{serverInfo.nano_contracts_enabled && (
{serverInfo?.nano_contracts_enabled && (

<li className="nav-item item-sidebar">
<span onClick={() => setNanoOpen(!nanoOpen)}>
Nano{' '}
<ArrorDownNavItem
style={{ marginLeft: '5px', rotate: toolsOpen ? '180deg' : '0deg' }}
className="dropdown-icon"
/>
</span>
{nanoOpen && (
<div>
<ul style={{ listStyleType: 'none', padding: 0, margin: 0 }}>
<li>
<NavLink to="/nano_contracts/" exact className="nav-link">
Nano Conctracts List
</NavLink>
<NavLink to="/blueprints/?type=built-in" exact className="nav-link">
Blueprints List
</NavLink>
</li>
</ul>
</div>
)}
</li>
)}
<li className="nav-item item-sidebar">
<NavLink
to="/network"
Expand Down
57 changes: 57 additions & 0 deletions src/components/nano/NanoContractsTable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from 'react';
import SortableTable from '../SortableTable';
import EllipsiCell from '../EllipsiCell';
import dateFormatter from '../../utils/date';

// XXX We should use function component with SortableTable as a component
// but renderTableHead and renderTableBody are implemented and not
// expected as a props, so it demands a bigger refactor
class NanoContractsTable extends SortableTable {
renderTableHead() {
return (
<tr>
<th className="d-lg-table-cell">NANO CONTRACT ID</th>
<th className="d-lg-table-cell">BLUEPRINT</th>
<th className="d-lg-table-cell">LAST TRANSACTION</th>
<th className="d-lg-table-cell">TOTAL TRANSACTIONS</th>
Comment on lines +15 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question(non-blocking): Why don't we allow ordering by those columns too?

<th
className="d-lg-table-cell sortable"
onClick={e => this.props.tableHeaderClicked(e, 'created_at')}
>
CREATED AT {this.getArrow('created_at')}
</th>
</tr>
);
}

renderTableBody() {
return this.props.data.map(nano => {
return (
<tr
key={nano.nano_contract_id}
onClick={_e => this.props.handleClickRow(nano.nano_contract_id)}
>
<td className="d-lg-table-cell pe-3">
{this.props.isMobile ? (
<EllipsiCell id={nano.nano_contract_id} countBefore={10} countAfter={10} />
) : (
nano.nano_contract_id
)}
</td>
<td className="d-lg-table-cell pe-3">{nano.blueprint_name}</td>
<td className="d-lg-table-cell pe-3">
{dateFormatter.parseTimestampNewUi(nano.last_tx_timestamp)}
</td>
<td className="d-lg-table-cell pe-3">{nano.total_txs}</td>
<td className="d-lg-table-cell pe-3">
{dateFormatter.parseTimestampNewUi(nano.created_at)}
</td>
</tr>
);
});
}
}

NanoContractsTable.propTypes = SortableTable.propTypes;

export default NanoContractsTable;
3 changes: 3 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ export const NANO_CONTRACT_TX_HISTORY_COUNT = 5;
// Number of elements in the blueprint list table
export const BLUEPRINT_LIST_COUNT = 10;

// Number of elements in the nano contracts list table
export const NANO_CONTRACTS_LIST_COUNT = 10;

export const COLORS = {
danger: '#991300',
success: '#44A32E',
Expand Down
10 changes: 9 additions & 1 deletion src/newUi.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2266,7 +2266,7 @@ nav {
text-transform: uppercase;
}

.table-stylized.blueprints-table {
.table-stylized.blueprints-table, .table-stylized.nano-contracts-table {
table-layout: auto;
}

Expand Down Expand Up @@ -2690,6 +2690,14 @@ i.pointer {
margin-bottom: 2rem;
}

.nano-creation-list .search {
width: 100%;
}

.search > .search-input.nano-list-search {
width: 100%;
}

.search-input {
width: 400px;
height: 100%;
Expand Down
Loading