-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6fc7f09
commit 1191b24
Showing
5 changed files
with
170 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as React from "react"; | ||
|
||
const CopyIcon = (props) => ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="24" | ||
height="24" | ||
fill="none" | ||
viewBox="0 0 24 24" | ||
stroke="currentColor" | ||
{...props} | ||
> | ||
<path | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth={2} | ||
d="M8 16H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v2m-6 12h8a2 2 0 0 0 2-2v-8a2 2 0 0 0-2-2h-8a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2z" | ||
/> | ||
</svg> | ||
); | ||
|
||
export default CopyIcon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,137 +1,152 @@ | ||
import { useEffect, useState } from "react"; | ||
import { ChainId, registry } from "@neptunemutual/sdk"; | ||
import { registry } from "@neptunemutual/sdk"; | ||
import { AddressZero } from "@ethersproject/constants"; | ||
import { useWeb3React } from "@web3-react/core"; | ||
import { getProviderOrSigner } from "@/lib/connect-wallet/utils/web3"; | ||
import { useNetwork } from "@/src/context/network"; | ||
|
||
export const useProtocolContracts = () => { | ||
const [data, setData] = useState({}); | ||
|
||
const { library, account } = useWeb3React(); | ||
const { network } = useNetwork(); | ||
|
||
useEffect(() => { | ||
[ | ||
ChainId.BinanceSmartChainTestnet, | ||
ChainId.Mumbai, | ||
ChainId.Ropsten, | ||
ChainId.Kovan, | ||
].forEach((chain) => { | ||
registry.ClaimsProcessor.getAddress(chain).then((addr) => { | ||
if (!network || !account) { | ||
return; | ||
} | ||
|
||
const chain = parseInt(network, 10); | ||
const signerOrProvider = getProviderOrSigner( | ||
library, | ||
account || AddressZero, | ||
chain | ||
); | ||
|
||
registry.ClaimsProcessor.getAddress(chain, signerOrProvider).then( | ||
(addr) => { | ||
setData((prev) => ({ | ||
...prev, | ||
[chain]: { | ||
...prev[chain], | ||
ClaimsProcessor: addr, | ||
}, | ||
})); | ||
}); | ||
} | ||
); | ||
|
||
registry.Reassurance.getAddress(chain).then((addr) => { | ||
setData((prev) => ({ | ||
...prev, | ||
[chain]: { | ||
...prev[chain], | ||
Reassurance: addr, | ||
}, | ||
})); | ||
}); | ||
registry.Reassurance.getAddress(chain, signerOrProvider).then((addr) => { | ||
setData((prev) => ({ | ||
...prev, | ||
[chain]: { | ||
...prev[chain], | ||
Reassurance: addr, | ||
}, | ||
})); | ||
}); | ||
|
||
registry.Cover.getAddress(chain).then((addr) => { | ||
setData((prev) => ({ | ||
...prev, | ||
[chain]: { | ||
...prev[chain], | ||
Cover: addr, | ||
}, | ||
})); | ||
}); | ||
registry.Cover.getAddress(chain, signerOrProvider).then((addr) => { | ||
setData((prev) => ({ | ||
...prev, | ||
[chain]: { | ||
...prev[chain], | ||
Cover: addr, | ||
}, | ||
})); | ||
}); | ||
|
||
registry.Governance.getAddress(chain).then((addr) => { | ||
setData((prev) => ({ | ||
...prev, | ||
[chain]: { | ||
...prev[chain], | ||
Governance: addr, | ||
}, | ||
})); | ||
}); | ||
registry.Governance.getAddress(chain, signerOrProvider).then((addr) => { | ||
setData((prev) => ({ | ||
...prev, | ||
[chain]: { | ||
...prev[chain], | ||
Governance: addr, | ||
}, | ||
})); | ||
}); | ||
|
||
registry.Stablecoin.getAddress(chain).then((addr) => { | ||
setData((prev) => ({ | ||
...prev, | ||
[chain]: { | ||
...prev[chain], | ||
Stablecoin: addr, | ||
}, | ||
})); | ||
}); | ||
registry.Stablecoin.getAddress(chain, signerOrProvider).then((addr) => { | ||
setData((prev) => ({ | ||
...prev, | ||
[chain]: { | ||
...prev[chain], | ||
Stablecoin: addr, | ||
}, | ||
})); | ||
}); | ||
|
||
registry.NPMToken.getAddress(chain).then((addr) => { | ||
setData((prev) => ({ | ||
...prev, | ||
[chain]: { | ||
...prev[chain], | ||
NPMToken: addr, | ||
}, | ||
})); | ||
}); | ||
registry.NPMToken.getAddress(chain, signerOrProvider).then((addr) => { | ||
setData((prev) => ({ | ||
...prev, | ||
[chain]: { | ||
...prev[chain], | ||
NPMToken: addr, | ||
}, | ||
})); | ||
}); | ||
|
||
registry.PolicyContract.getAddress(chain).then((addr) => { | ||
setData((prev) => ({ | ||
...prev, | ||
[chain]: { | ||
...prev[chain], | ||
PolicyContract: addr, | ||
}, | ||
})); | ||
}); | ||
registry.PolicyContract.getAddress(chain, signerOrProvider).then((addr) => { | ||
setData((prev) => ({ | ||
...prev, | ||
[chain]: { | ||
...prev[chain], | ||
PolicyContract: addr, | ||
}, | ||
})); | ||
}); | ||
|
||
registry.ProvisionContract.getAddress(chain).then((addr) => { | ||
registry.ProvisionContract.getAddress(chain, signerOrProvider).then( | ||
(addr) => { | ||
setData((prev) => ({ | ||
...prev, | ||
[chain]: { | ||
...prev[chain], | ||
ProvisionContract: addr, | ||
}, | ||
})); | ||
}); | ||
} | ||
); | ||
|
||
registry.Staking.getAddress(chain).then((addr) => { | ||
setData((prev) => ({ | ||
...prev, | ||
[chain]: { | ||
...prev[chain], | ||
Staking: addr, | ||
}, | ||
})); | ||
}); | ||
registry.Staking.getAddress(chain, signerOrProvider).then((addr) => { | ||
setData((prev) => ({ | ||
...prev, | ||
[chain]: { | ||
...prev[chain], | ||
Staking: addr, | ||
}, | ||
})); | ||
}); | ||
|
||
registry.Protocol.getAddress(chain).then((addr) => { | ||
setData((prev) => ({ | ||
...prev, | ||
[chain]: { | ||
...prev[chain], | ||
Protocol: addr, | ||
}, | ||
})); | ||
}); | ||
registry.Protocol.getAddress(chain, signerOrProvider).then((addr) => { | ||
setData((prev) => ({ | ||
...prev, | ||
[chain]: { | ||
...prev[chain], | ||
Protocol: addr, | ||
}, | ||
})); | ||
}); | ||
|
||
registry.BondPool.getAddress(chain).then((addr) => { | ||
setData((prev) => ({ | ||
...prev, | ||
[chain]: { | ||
...prev[chain], | ||
BondPool: addr, | ||
}, | ||
})); | ||
}); | ||
registry.BondPool.getAddress(chain, signerOrProvider).then((addr) => { | ||
setData((prev) => ({ | ||
...prev, | ||
[chain]: { | ||
...prev[chain], | ||
BondPool: addr, | ||
}, | ||
})); | ||
}); | ||
|
||
registry.StakingPools.getAddress(chain).then((addr) => { | ||
setData((prev) => ({ | ||
...prev, | ||
[chain]: { | ||
...prev[chain], | ||
StakingPools: addr, | ||
}, | ||
})); | ||
}); | ||
registry.StakingPools.getAddress(chain, signerOrProvider).then((addr) => { | ||
setData((prev) => ({ | ||
...prev, | ||
[chain]: { | ||
...prev[chain], | ||
StakingPools: addr, | ||
}, | ||
})); | ||
}); | ||
}, []); | ||
}, [account, library, network]); | ||
|
||
return { data }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters