-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.ts
100 lines (87 loc) · 2.05 KB
/
index.ts
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import {
SoulboundIdentity,
SoulboundIdentity__factory,
SoulboundCreditReport,
SoulboundCreditReport__factory,
SoulName,
SoulName__factory,
SoulLinker,
SoulLinker__factory,
SoulStore,
SoulStore__factory,
} from '@masa-finance/masa-contracts-identity';
import { ethers } from 'ethers';
import * as goerli from './goerli';
export const addresses = {
goerli,
};
export interface IIdentityContracts {
SoulboundIdentityContract: SoulboundIdentity;
SoulboundCreditReportContract: SoulboundCreditReport;
SoulNameContract: SoulName;
SoulLinkerContract: SoulLinker;
SoulStoreContract: SoulStore;
}
interface LoadContractArgs {
provider?: any;
network?: string;
}
export const loadContracts = async ({
provider,
network = 'goerli',
}: LoadContractArgs): Promise<IIdentityContracts> => {
const p =
// take provider as is if supplied
provider ||
// or try to load from the browser
new ethers.providers.Web3Provider(
// @ts-ignore
window.ethereum
);
const SoulboundIdentityContract = SoulboundIdentity__factory.connect(
addresses[network].SoulboundIdentityAddress,
p
);
const SoulboundCreditReportContract = SoulboundCreditReport__factory.connect(
addresses[network].SoulboundCreditReportAddress,
p
);
const SoulNameContract = SoulName__factory.connect(
addresses[network].SoulNameAddress,
p
);
const SoulLinkerContract = SoulLinker__factory.connect(
addresses[network].SoulLinkerAddress,
p
);
const SoulStoreContract = SoulStore__factory.connect(
addresses[network].SoulStoreAddress,
p
);
return {
SoulboundIdentityContract,
SoulboundCreditReportContract,
SoulNameContract,
SoulLinkerContract,
SoulStoreContract,
};
};
export const useContractCall = ({ method }: { method: Promise<any> }) => {
let data;
let error;
let loading = true;
method
.then((d) => {
data = d;
loading = false;
})
.catch((e) => {
error = e;
});
return {
data,
error,
loading,
getData: () => data,
};
};