Skip to content

Commit

Permalink
handle if messages are less than 10
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxi-Teme committed Apr 1, 2024
1 parent 303a94b commit b91584a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ function App() {

const getLast10Messages = async () => {
const total_messages = await wallet.viewMethod({ contractId: CONTRACT_NAME, method: "total_messages" });
return wallet.viewMethod({ contractId: CONTRACT_NAME, method: "get_messages", args: { from_index: String(total_messages - 10), limit: "10" } });
const from_index = total_messages >= 10 ? total_messages - 10 : 0;
return wallet.viewMethod({ contractId: CONTRACT_NAME, method: "get_messages", args: { from_index: String(from_index), limit: "10" } });
}

const onSubmit = async (e) => {
Expand Down

0 comments on commit b91584a

Please sign in to comment.