Skip to content

Commit

Permalink
Merge pull request #8 from nedrise27/main
Browse files Browse the repository at this point in the history
handle if messages are less than 10
  • Loading branch information
gagdiez authored Apr 2, 2024
2 parents b47ab7b + b91584a commit 7995dc9
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 7995dc9

Please sign in to comment.