Skip to content

Commit

Permalink
feat(contract): check balance by querying the contract directly
Browse files Browse the repository at this point in the history
, instead of using `scan.crossbell.io`
  • Loading branch information
runjuu committed Aug 23, 2023
1 parent e5cc6e9 commit e5c4970
Show file tree
Hide file tree
Showing 3 changed files with 3,935 additions and 9,422 deletions.
1 change: 0 additions & 1 deletion packages/contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"./package.json": "./package.json"
},
"dependencies": {
"@crossbell/indexer": "^1.5.10",
"@crossbell/util-hooks": "^1.5.10",
"crossbell": "^1.5.10",
"viem": "^1.6.4"
Expand Down
6 changes: 4 additions & 2 deletions packages/contract/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Contract, Numberish } from "crossbell";
import { isCrossbellMainnet } from "crossbell/network";
import { parseEther } from "viem";
import { getCsbBalance } from "@crossbell/indexer";
import { handleActions } from "@crossbell/util-hooks";
import { type Address } from "viem";

Expand Down Expand Up @@ -34,7 +33,10 @@ export function injectContractChecker({

if (address) {
// check if $CSB is enough to pay for the transaction
const balance = await getCsbBalance(address);
const { data: balance } = await contract.csb.getBalance({
owner: address,
});

if (!hasEnoughCsb(balance)) {
openFaucetHintModel();
throw new BizError("Not enough $CSB.", ERROR_CODES.NO_CHARACTER);
Expand Down

0 comments on commit e5c4970

Please sign in to comment.