Skip to content

Commit

Permalink
using helpers from sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
dan13ram committed Oct 7, 2022
1 parent 846dd65 commit c3abb40
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 125 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@emotion/react": "^11.10.4",
"@emotion/styled": "^11.10.4",
"@gnosis.pm/safe-apps-web3modal": "^17.0.0",
"@quest-chains/sdk": "^0.1.11",
"@quest-chains/sdk": "^0.1.12",
"@react-three/drei": "9.26.1",
"@react-three/fiber": "8.7.1",
"@walletconnect/web3-provider": "^1.8.0",
Expand Down
4 changes: 0 additions & 4 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ import React, { useEffect } from 'react';
import { Toaster } from 'react-hot-toast';

import { AppLayout } from '@/components/Layout/AppLayout';
import { initGraphHealthStore } from '@/stores/graphHealth';
import { globalStyles, theme } from '@/utils/theme';
import { WalletProvider } from '@/web3';

const App = ({ Component, pageProps }: AppProps): JSX.Element => {
const router = useRouter();
useEffect(() => {
initGraphHealthStore();
}, []);

function ForceDarkMode(props: { children: JSX.Element }) {
const { colorMode, toggleColorMode } = useColorMode();
Expand Down
74 changes: 0 additions & 74 deletions stores/graphHealth.ts

This file was deleted.

45 changes: 3 additions & 42 deletions utils/graphHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,5 @@
/* eslint-disable no-await-in-loop */
import { helpers } from '@quest-chains/sdk';

import { Log, TransactionReceipt } from '@ethersproject/abstract-provider';
import { ethers } from 'ethers';
export const waitUntilBlock = helpers.waitUntilSubgraphIndexed;

import { getGraphLatestBlock } from '@/stores/graphHealth';
import { sleep } from '@/utils/helpers';

const UPDATE_INTERVAL = 10000;

const MAX_RETRIES = 6;

export const waitUntilBlock = async (
chainId: string,
block: number,
): Promise<boolean> => {
let latestBlock = getGraphLatestBlock(chainId);
let tries = 0;
while (latestBlock < block && tries < MAX_RETRIES) {
await sleep(UPDATE_INTERVAL);
tries += 1;
latestBlock = getGraphLatestBlock(chainId);
}
return latestBlock >= block;
};

export const awaitQuestChainAddress = async (receipt: TransactionReceipt) => {
if (!receipt || !receipt.logs) return '';
const abi = new ethers.utils.Interface([
'event QuestChainCreated(uint256 id, address questChain)',
]);
const eventFragment = abi.events[Object.keys(abi.events)[0]];
const eventTopic = abi.getEventTopic(eventFragment);
const event = receipt.logs.find((e: Log) => e.topics[0] === eventTopic);
if (event) {
const decodedLog = abi.decodeEventLog(
eventFragment,
event.data,
event.topics,
);
return decodedLog.questChain;
}
return '';
};
export const awaitQuestChainAddress = helpers.getQuestChainAddressFromTx;
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2083,10 +2083,10 @@
resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.11.2.tgz#830beaec4b4091a9e9398ac50f865ddea52186b9"
integrity sha512-92FRmppjjqz29VMJ2dn+xdyXZBrMlE42AV6Kq6BwjWV7CNUW1hs2FtxSNLQE+gJhaZ6AAmYuO9y8dshhcBl7vA==

"@quest-chains/sdk@^0.1.11":
version "0.1.11"
resolved "https://registry.yarnpkg.com/@quest-chains/sdk/-/sdk-0.1.11.tgz#fec53258b4c16d1ceb037eadd0565d392003da78"
integrity sha512-EVKK9CeMUTKMqyQEnYtYFvv3YLQhA9TDoHwjf673xGrfONW5jp8LWf2/lBTZtWmzHaca5KUM/+UqZo4HEtZk7A==
"@quest-chains/sdk@^0.1.12":
version "0.1.12"
resolved "https://registry.yarnpkg.com/@quest-chains/sdk/-/sdk-0.1.12.tgz#c4baa1a51be23997a2520d7c51901736e395b673"
integrity sha512-xt6vDa+mSEw4I6En407utHEac91ynUmVebe6r5DqRwbHLIbbZXqf1H9U+mBcTtDyOKhGukeOjF/kGVltjc+MhQ==
dependencies:
ajv "^8.11.0"
axios "^1.1.1"
Expand Down

0 comments on commit c3abb40

Please sign in to comment.