Skip to content

Commit

Permalink
Updated SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
flashburst committed Mar 10, 2022
1 parent 6fc7f09 commit 1191b24
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 126 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@fontsource/poppins": "4.5.0",
"@fontsource/sora": "4.5.0",
"@headlessui/react": "^1.4.2",
"@neptunemutual/sdk": "^0.3.6-beta",
"@neptunemutual/sdk": "^0.3.8-beta",
"@web3-react/core": "^6.1.9",
"@web3-react/injected-connector": "^6.0.7",
"bignumber.js": "^9.0.2",
Expand Down
45 changes: 26 additions & 19 deletions src/components/ProtocolContracts.jsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
import { getAddressLink } from "@/lib/connect-wallet/utils/explorer";
import { useNetwork } from "@/src/context/network";
import { useWeb3React } from "@web3-react/core";
import { Fragment } from "react";

export const ProtocolContracts = ({ addresses }) => {
const { network } = useNetwork();
const { account } = useWeb3React();

return (
<>
<h3 className="text-xs font-inter font-bold pt-4 pb-2 text-gray-800">
Protocol Contracts
</h3>
<p className="font-inter max-w-fit">
{Object.keys(addresses)
.sort()
.map((k, idx) => {
return (
<Fragment key={k}>
<a
href={getAddressLink(network, addresses[k])}
rel="noreferrer"
target="_blank"
className="text-36309D hover:text-red-600 underline underline-offset-1 text-sm"
>
{k}
</a>
{idx !== Object.keys(addresses).length - 1 && (
<span className="text-36309D">, </span>
)}
</Fragment>
);
})}
{!account && (
<span className="text-red-600">Please connect your wallet</span>
)}
{account &&
Object.keys(addresses)
.sort()
.map((k, idx) => {
return (
<Fragment key={k}>
<a
href={getAddressLink(network, addresses[k])}
rel="noreferrer"
target="_blank"
className="text-36309D hover:text-red-600 underline underline-offset-1 text-sm"
>
{k}
</a>
{idx !== Object.keys(addresses).length - 1 && (
<span className="text-36309D">, </span>
)}
</Fragment>
);
})}
</p>
</>
);
Expand Down
22 changes: 22 additions & 0 deletions src/components/icons/CopyIcon.jsx
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;
219 changes: 117 additions & 102 deletions src/hooks/useProtocolContracts.jsx
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 };
};
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -800,10 +800,10 @@
resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz#b520529ec21d8e5945a1851dfd1c32e94e39ff45"
integrity sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==

"@neptunemutual/sdk@^0.3.6-beta":
version "0.3.6-beta"
resolved "https://registry.yarnpkg.com/@neptunemutual/sdk/-/sdk-0.3.6-beta.tgz#4d7d3bd091397fedc48babf0c6b1ad892672c548"
integrity sha512-j/F2oUvMedUYxUxQ7CAjyvuXmfZH2iuWhTu2VHX1uDaKYIW6gsYKOXDO2NntMJHheKn6/GHN/G29M/C2HJorgQ==
"@neptunemutual/sdk@^0.3.8-beta":
version "0.3.8-beta"
resolved "https://registry.yarnpkg.com/@neptunemutual/sdk/-/sdk-0.3.8-beta.tgz#beae15449d489a465dbdb1811ed6f1865aeb78d3"
integrity sha512-AQWuMr7HJFDZrclg1J81U7OFimw08z9z1v1yjy/Pxk6RcOYZORX+oa/a13+wuEVYuFqGk9aJooJD5RQ8yW2d3Q==
dependencies:
axios "0.26.0"
bs58 "4.0.1"
Expand Down

0 comments on commit 1191b24

Please sign in to comment.