-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuseGameContractNodeDefinitions.ts
More file actions
67 lines (63 loc) · 1.79 KB
/
useGameContractNodeDefinitions.ts
File metadata and controls
67 lines (63 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { NodeDefinition } from '@oveddan-behave-graph/core';
import { useMemo } from 'react';
import { useChainId } from 'wagmi';
import {
bullBearABI,
bullBearTokenABI,
useBullBear,
useBullBearBullBearToken
} from '../generated';
import {
makeSmartContractNodeDefinitions,
useCurrentAddressNodeDefinition
} from '../nodes/makeSmartContractNodeDefintions';
export const makeAllContractDefinitions = ({
chainId,
bullBearAddress,
// bullBearFoodAddress
bullBearTokenAddress
}: {
chainId: number;
bullBearAddress: `0x${string}`;
bullBearTokenAddress: `0x${string}`;
// bullBearFoodAddress: `0x${string}`;
}): Record<string, NodeDefinition> => ({
...makeSmartContractNodeDefinitions({
chainId,
abi: bullBearABI,
contractName: 'bullBear',
contractAddress: bullBearAddress
}),
...makeSmartContractNodeDefinitions({
chainId,
abi: bullBearTokenABI,
contractName: 'bullBearToken',
contractAddress: bullBearTokenAddress
})
});
export const useGameContractNodeDefinitions = ():
| Record<string, NodeDefinition>
| undefined => {
const bullBearContract = useBullBear();
const { data: bullBearTokenAddress } = useBullBearBullBearToken();
const bullBearContractAddress = bullBearContract?.address;
const chainId = useChainId();
const currentAddressDefinition = useCurrentAddressNodeDefinition();
return useMemo(() => {
if (!bullBearContractAddress || !bullBearTokenAddress) return;
const result: Record<string, NodeDefinition> = {
...currentAddressDefinition,
...makeAllContractDefinitions({
chainId,
bullBearAddress: bullBearContractAddress,
bullBearTokenAddress
})
};
return result;
}, [
bullBearContractAddress,
bullBearTokenAddress,
chainId,
currentAddressDefinition
]);
};