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

create for number of stamp #2

Open
codingshot opened this issue Feb 23, 2024 · 0 comments
Open

create for number of stamp #2

codingshot opened this issue Feb 23, 2024 · 0 comments

Comments

@codingshot
Copy link
Member

show total number of stamp

reference code here (from nada.bot home page)

`
import { useState, useEffect } from "react";
import Big from "big.js";
import * as nearAPI from "near-api-js";

const { keyStores, connect, Contract } = nearAPI;

const Status = () => {
const [statsData, setStatsData] = useState({
verified_providers: "-",
total_checks: "-",
verified_humans: "-",
});
useEffect(() => {
(async function () {
const myKeyStore = new keyStores.InMemoryKeyStore();

  const connectionConfig = {
    networkId: "mainnet",
    keyStore: myKeyStore,
    nodeUrl: "https://rpc.mainnet.near.org",
    walletUrl: "https://wallet.mainnet.near.org",
    helperUrl: "https://helper.mainnet.near.org",
    explorerUrl: "https://explorer.mainnet.near.org",
  };

  // connect to NEAR
  const nearConnection = await connect(connectionConfig);
  const account = await nearConnection.account();
  const contract = new Contract(account, "v1.nadabot.near", {
    viewMethods: ["get_providers", "get_users_for_stamp", "is_human"],
  });

  //   get Active Provdiers
  const activeProviders = await contract.get_providers({
    status: "Active",
  });

  //   get Total Checks
  const providers = await contract.get_providers();
  let totalStamps = 0;
  providers.forEach((provider) => (totalStamps += provider.stamp_count));

  //   get Humans Verified

  // Get All Users
  let totalUsers = [];
  for (const provider of providers) {
    const users = await contract.get_users_for_stamp({
      provider_id: provider.provider_id,
    });
    totalUsers.push(...users);
  }
  totalUsers = [...new Set(totalUsers)];
  // Verify Users
  let humanVerified = 0;
  for (const user of totalUsers) {
    const isHuman = await contract.is_human({
      account_id: user,
    });
    if (isHuman) humanVerified += 1;
  }

  const statsData = {
    verified_providers: activeProviders.length,
    total_checks: totalStamps,
    verified_humans: humanVerified,
  };
  setStatsData(statsData);
})();

}, []);
return (





{statsData.verified_humans}

Humans Verified




{statsData.verified_providers}

Verified Providers




{statsData.total_checks}

Total Checks




);
};

export default Status;
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant