Skip to content

Commit 8aa9787

Browse files
Merge pull request #785 from threshold-network/add-support-to-multiple-networks
Added multi-network support, including updated environment variables, network-specific explorer links, refactored contract integrations and connector handling, and enhanced local storage and minting flow for multi-network compatibility. Fixed ledger and subgraph issues, and centralized network logic.
2 parents 3b26f38 + 54cdb2d commit 8aa9787

File tree

197 files changed

+26068
-1593
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

197 files changed

+26068
-1593
lines changed

.env.example

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
REACT_APP_SUPPORTED_CHAIN_ID=1337
2-
REACT_APP_ETH_HOSTNAME_HTTP=http://localhost:8545
3-
REACT_APP_ETH_HOSTNAME_WS=ws://localhost:8545
1+
REACT_APP_DEFAULT_PROVIDER_CHAIN_ID=1337
2+
REACT_APP_ALCHEMY_API=$ALCHEMY_API
43
REACT_APP_MULTICALL_ADDRESS=$MULTICALL_ADDRESS
54
REACT_APP_DAPP_DEVELOPMENT_TESTNET_CONTRACTS=$DAPP_DEVELOPMENT_TESTNET_CONTRACTS
65

@@ -19,11 +18,16 @@ REACT_APP_FEATURE_FLAG_SENTRY=false
1918
REACT_APP_SENTRY_DSN=$SENTRY_DSN
2019
REACT_APP_FEATURE_FLAG_TRM=false
2120

22-
REACT_APP_ELECTRUM_PROTOCOL=$ELECTRUM_PROTOCOL
23-
REACT_APP_ELECTRUM_HOST=$ELECTRUM_HOST
24-
REACT_APP_ELECTRUM_PORT=$ELECTRUM_PORT
21+
REACT_APP_MAINNET_ELECTRUM_PROTOCOL=$MAINNET_ELECTRUM_PROTOCOL
22+
REACT_APP_MAINNET_ELECTRUM_HOST=$MAINNET_ELECTRUM_HOST
23+
REACT_APP_MAINNET_ELECTRUM_PORT=$MAINNET_ELECTRUM_PORT
24+
REACT_APP_TESTNET_ELECTRUM_PROTOCOL=$TESTNET_ELECTRUM_PROTOCOL
25+
REACT_APP_TESTNET_ELECTRUM_HOST=$TESTNET_ELECTRUM_HOST
26+
REACT_APP_TESTNET_ELECTRUM_PORT=$TESTNET_ELECTRUM_PORT
2527
REACT_APP_MOCK_BITCOIN_CLIENT=true
2628

2729
REACT_APP_WALLET_CONNECT_PROJECT_ID=$WALLET_CONNECT_PROJECT_ID
2830

31+
REACT_APP_TBTC_SUBGRAPH_API=$TBTC_SUBGRAPH_API
32+
2933
REACT_APP_TACO_DOMAIN=dashboard

.env.production

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
REACT_APP_SUPPORTED_CHAIN_ID=$CHAIN_ID
2-
REACT_APP_ETH_HOSTNAME_HTTP=$ETH_HOSTNAME_HTTP
3-
REACT_APP_ETH_HOSTNAME_WS=$ETH_HOSTNAME_WS
1+
REACT_APP_DEFAULT_PROVIDER_CHAIN_ID=$CHAIN_ID
2+
REACT_APP_ALCHEMY_API=$ALCHEMY_API
43
REACT_APP_DAPP_DEVELOPMENT_TESTNET_CONTRACTS=$DAPP_DEVELOPMENT_TESTNET_CONTRACTS
54

65
REACT_APP_FEATURE_FLAG_TBTC_V2=true
@@ -20,10 +19,16 @@ REACT_APP_FEATURE_FLAG_SENTRY=$SENTRY_SUPPORT
2019
REACT_APP_SENTRY_DSN=$SENTRY_DSN
2120
REACT_APP_FEATURE_FLAG_TRM=$TRM_SUPPORT
2221

23-
REACT_APP_ELECTRUM_PROTOCOL=$ELECTRUM_PROTOCOL
24-
REACT_APP_ELECTRUM_HOST=$ELECTRUM_HOST
25-
REACT_APP_ELECTRUM_PORT=$ELECTRUM_PORT
22+
REACT_APP_MAINNET_ELECTRUM_PROTOCOL=$MAINNET_ELECTRUM_PROTOCOL
23+
REACT_APP_MAINNET_ELECTRUM_HOST=$MAINNET_ELECTRUM_HOST
24+
REACT_APP_MAINNET_ELECTRUM_PORT=$MAINNET_ELECTRUM_PORT
25+
REACT_APP_TESTNET_ELECTRUM_PROTOCOL=$TESTNET_ELECTRUM_PROTOCOL
26+
REACT_APP_TESTNET_ELECTRUM_HOST=$TESTNET_ELECTRUM_HOST
27+
REACT_APP_TESTNET_ELECTRUM_PORT=$TESTNET_ELECTRUM_PORT
2628
REACT_APP_MOCK_BITCOIN_CLIENT=false
2729

2830
REACT_APP_WALLET_CONNECT_PROJECT_ID=$WALLET_CONNECT_PROJECT_ID
31+
32+
REACT_APP_TBTC_SUBGRAPH_API=$TBTC_SUBGRAPH_API
33+
2934
REACT_APP_TACO_DOMAIN=mainnet

.env.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
REACT_APP_SUPPORTED_CHAIN_ID=1337
2-
REACT_APP_MULTICALL_ADDRESS=0x086813525A7dC7dafFf015Cdf03896Fd276eab60
1+
REACT_APP_DEFAULT_PROVIDER_CHAIN_ID=1337
2+
REACT_APP_MULTICALL_ADDRESS=0xcA11bde05977b3631167028862bE2a173976CA11
33
REACT_APP_TACO_DOMAIN=dashboard

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ This project was bootstrapped with [Create React App](https://github.com/faceboo
1111
## Update the `.env` file:
1212

1313
```
14-
REACT_APP_SUPPORTED_CHAIN_ID=11155111
15-
REACT_APP_ETH_HOSTNAME_HTTP=<your http ETH hostname- eg. Infura>
16-
REACT_APP_ETH_HOSTNAME_WS=<your ws ETH hostname- eg. Infura>
14+
REACT_APP_DEFAULT_PROVIDER_CHAIN_ID=11155111
15+
REACT_APP_ALCHEMY_API=<your Alchemy API key>
1716
// We can skip this env variable- the dapp uses the correct address
1817
// of Multicall contract for Sepolia under the hood.
1918
REACT_APP_MULTICALL_ADDRESS=$MULTICALL_ADDRESS
@@ -109,9 +108,8 @@ The following procedure allows to deploy T token dashboard to production:
109108
Update `.env` to contain:
110109

111110
```
112-
REACT_APP_SUPPORTED_CHAIN_ID=11155111
113-
REACT_APP_ETH_HOSTNAME_HTTP=https://sepolia.infura.io/v3/<your API key here>
114-
REACT_APP_ETH_HOSTNAME_WS=wss://sepolia.infura.io/v3/<your API key here>
111+
REACT_APP_DEFAULT_PROVIDER_CHAIN_ID=11155111
112+
REACT_APP_ALCHEMY_API=<your Alchemy API key here>
115113
REACT_APP_MULTICALL_ADDRESS=$MULTICALL_ADDRESS
116114
117115
REACT_APP_FEATURE_FLAG_TBTC_V2=true
@@ -129,13 +127,18 @@ REACT_APP_FEATURE_FLAG_SENTRY=false
129127
REACT_APP_SENTRY_DSN=$SENTRY_DSN
130128
REACT_APP_FEATURE_FLAG_TRM=false
131129
132-
REACT_APP_ELECTRUM_PROTOCOL=wss
133-
REACT_APP_ELECTRUM_HOST=electrumx-server.test.tbtc.network
134-
REACT_APP_ELECTRUM_PORT=8443
130+
REACT_APP_MAINNET_ELECTRUM_PROTOCOL=$MAINNET_ELECTRUM_PROTOCOL
131+
REACT_APP_MAINNET_ELECTRUM_HOST=$MAINNET_ELECTRUM_HOST
132+
REACT_APP_MAINNET_ELECTRUM_PORT=$MAINNET_ELECTRUM_PORT
133+
REACT_APP_TESTNET_ELECTRUM_PROTOCOL=wss
134+
REACT_APP_TESTNET_ELECTRUM_HOST=electrumx-server.test.tbtc.network
135+
REACT_APP_TESTNET_ELECTRUM_PORT=8443
135136
REACT_APP_MOCK_BITCOIN_CLIENT=false
136137
137138
REACT_APP_WALLET_CONNECT_PROJECT_ID=$WALLET_CONNECT_PROJECT_ID
138139
140+
REACT_APP_TBTC_SUBGRAPH_API=$TBTC_SUBGRAPH_API
141+
139142
REACT_APP_TACO_DOMAIN=dashboard
140143
```
141144

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
"@keep-network/keep-ecdsa": "development",
1919
"@keep-network/random-beacon": "development",
2020
"@keep-network/tbtc": "development",
21-
"@keep-network/tbtc-v2.ts": "^2.4.1",
21+
"@keep-network/tbtc-v2.ts": "2.4.5",
2222
"@ledgerhq/connect-kit-loader": "1.1.8",
2323
"@ledgerhq/wallet-api-client": "^1.2.0",
2424
"@ledgerhq/wallet-api-client-react": "^1.1.1",
25-
"@nucypher/nucypher-contracts": "0.13.0",
25+
"@nucypher/nucypher-contracts": "0.23.0",
2626
"@reduxjs/toolkit": "^1.6.1",
2727
"@rehooks/local-storage": "^2.4.4",
2828
"@sentry/react": "^7.33.0",

src/App.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import { useSubscribeToToppedUpEvent } from "./hooks/useSubscribeToToppedUpEvent
3838
import { pages } from "./pages"
3939
import { useCheckBonusEligibility } from "./hooks/useCheckBonusEligibility"
4040
import { useFetchStakingRewards } from "./hooks/useFetchStakingRewards"
41-
import { isSameChainId, isSameETHAddress } from "./web3/utils"
41+
import { isSameETHAddress } from "./web3/utils"
4242
import { ThresholdProvider } from "./contexts/ThresholdContext"
4343
import { LedgerLiveAppProvider } from "./contexts/LedgerLiveAppContext"
4444
import {
@@ -63,6 +63,9 @@ import { useIsEmbed } from "./hooks/useIsEmbed"
6363
import TBTC from "./pages/tBTC"
6464
import { useDetectIfEmbed } from "./hooks/useDetectIfEmbed"
6565
import { useGoogleTagManager } from "./hooks/google-tag-manager"
66+
import { hexToNumber, isSameChainId } from "./networks/utils"
67+
import { walletConnected } from "./store/account"
68+
import { useIsActive } from "./hooks/useIsActive"
6669

6770
const Web3EventHandlerComponent = () => {
6871
useSubscribeToVendingMachineContractEvents()
@@ -133,15 +136,19 @@ const useSubscribeToVendingMachineContractEvents = () => {
133136

134137
const AppBody = () => {
135138
const dispatch = useDispatch()
136-
const { connector, account, chainId, deactivate } = useWeb3React()
139+
const { connector, account, chainId } = useIsActive()
137140

138141
useEffect(() => {
139142
const updateHandler = (update: ConnectorUpdate) => {
140-
// if chain is changed then just deactivate the current provider and reset
141-
// store
143+
// if chain is changed then just update the redux store for the wallet
144+
// connection
142145
if (update.chainId && !isSameChainId(update.chainId, chainId as number)) {
143-
dispatch(resetStoreAction())
144-
deactivate()
146+
dispatch(
147+
walletConnected({
148+
address: account || "",
149+
chainId: hexToNumber(update.chainId),
150+
})
151+
)
145152
} else if (
146153
update.account &&
147154
!isSameETHAddress(update.account, account as string)
@@ -169,7 +176,7 @@ const AppBody = () => {
169176
connector?.removeListener(ConnectorEvent.Update, updateHandler)
170177
connector?.removeListener(ConnectorEvent.Deactivate, deactivateHandler)
171178
}
172-
}, [connector, dispatch, account])
179+
}, [connector, dispatch, account, chainId])
173180

174181
useEffect(() => {
175182
dispatch(fetchETHPriceUSD())

src/components/CopyToClipboard/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import shortenAddress from "../../utils/shortenAddress"
1212
import ViewInBlockExplorer, {
1313
ViewInBlockExplorerProps,
1414
} from "../ViewInBlockExplorer"
15-
import { ExplorerDataType } from "../../utils/createEtherscanLink"
15+
import { ExplorerDataType } from "../../networks/enums/networks"
1616

1717
type CopyToClipboardProps = {
1818
textToCopy: string
Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
import { FC } from "react"
2-
import { FormErrorMessage, FormHelperText } from "@threshold-network/components"
2+
import {
3+
Box,
4+
FormErrorMessage,
5+
FormHelperText,
6+
} from "@threshold-network/components"
37

48
const HelperErrorText: FC<{
59
errorMsgText?: string | JSX.Element
610
hasError?: boolean
711
helperText?: string | JSX.Element
812
}> = ({ errorMsgText, helperText, hasError }) => {
9-
if (hasError) {
10-
return (
11-
<FormErrorMessage>
12-
{errorMsgText || "Please enter a valid value"}
13-
</FormErrorMessage>
14-
)
15-
}
16-
17-
return helperText ? <FormHelperText>{helperText}</FormHelperText> : null
13+
return (
14+
<Box mt={2} maxWidth="100%" overflow="hidden" textOverflow="ellipsis">
15+
{hasError ? (
16+
<FormErrorMessage>
17+
{errorMsgText || "Please enter a valid value"}
18+
</FormErrorMessage>
19+
) : helperText ? (
20+
<FormHelperText>{helperText}</FormHelperText>
21+
) : null}
22+
</Box>
23+
)
1824
}
1925

2026
export default HelperErrorText

src/components/Link/SharedLinks.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useColorModeValue } from "@chakra-ui/react"
33
import { BodySm } from "@threshold-network/components"
44
import ViewInBlockExplorer from "../ViewInBlockExplorer"
55
import { useTStakingContract } from "../../web3/hooks"
6-
import { ExplorerDataType } from "../../utils/createEtherscanLink"
6+
import { ExplorerDataType } from "../../networks/enums/networks"
77

88
type StakingContractLearnMoreProps = ComponentProps<typeof BodySm>
99

src/components/MintDurationTiers/MintDurationTiers.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ const MintDurationTiers: FC<MintDurationTiersProps> = ({
5555
// is returned as is.
5656
const confirmations = getNumberOfConfirmationsByAmount(safeAmount)
5757
const durationInMinutes =
58-
getDurationByNumberOfConfirmations(confirmations)
59-
// Round up the minutes to the nearest half-hour
60-
const hours = (Math.round(durationInMinutes / 30) * 30) / 60
58+
getDurationByNumberOfConfirmations(confirmations) * 1.5
59+
// Round down the minutes to the nearest half-hour
60+
const hours = (Math.floor(durationInMinutes / 30) * 30) / 60
6161
const formattedAmount = amount.toFixed(2)
6262

6363
const hoursSuffix = hours === 1 ? "hour" : "hours"

src/components/Modal/ClaimingRewards/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { useModal } from "../../../hooks/useModal"
3434
import { ModalType } from "../../../enums"
3535
import ModalCloseButton from "../ModalCloseButton"
3636
import SubmitTxButton from "../../SubmitTxButton"
37+
import { useMerkleDropContract } from "../../../web3/hooks/useMerkleDropContract"
3738

3839
const ClaimingRewardsBase: FC<
3940
BaseModalProps & {
@@ -44,6 +45,7 @@ const ClaimingRewardsBase: FC<
4445
const { openModal } = useModal()
4546
const beneficiaryRewards = useSelector(selectAccumulatedRewardsPerBeneficiary)
4647
const rewards = useSelector(selectInterimRewards)
48+
const merkleDropContract = useMerkleDropContract()
4749

4850
const onClaimSuccess = useCallback<OnSuccessCallback>(
4951
(receipt) => {
@@ -99,6 +101,7 @@ const ClaimingRewardsBase: FC<
99101
Cancel
100102
</Button>
101103
<SubmitTxButton
104+
isDisabled={!merkleDropContract}
102105
onSubmit={() => {
103106
claim(Object.keys(rewards))
104107
}}

src/components/Modal/ConfirmStakingParams/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { useStakeTransaction } from "../../../web3/hooks/useStakeTransaction"
3030
import { formatTokenAmount } from "../../../utils/formatAmount"
3131
import ModalCloseButton from "../ModalCloseButton"
3232
import SubmitTxButton from "../../SubmitTxButton"
33+
import { useTStakingContract } from "../../../web3/hooks"
3334

3435
const ConfirmStakingParamsModal: FC<
3536
BaseModalProps & { stakeAmount: string }
@@ -40,6 +41,7 @@ const ConfirmStakingParamsModal: FC<
4041
const { account } = useWeb3React()
4142
const { updateState } = useStakingState()
4243
const checkIfProviderUsed = useCheckDuplicateProviderAddress()
44+
const stakingContract = useTStakingContract()
4345

4446
// stake transaction, opens success modal on success callback
4547
// not needed once MAS is launched
@@ -129,7 +131,11 @@ const ConfirmStakingParamsModal: FC<
129131
<Button onClick={closeModal} variant="outline" mr={2}>
130132
Cancel
131133
</Button>
132-
<SubmitTxButton type="submit" form="advanced-staking-params-form">
134+
<SubmitTxButton
135+
isDisabled={!stakingContract}
136+
type="submit"
137+
form="advanced-staking-params-form"
138+
>
133139
{featureFlags.MULTI_APP_STAKING ? "Continue" : "Stake"}
134140
</SubmitTxButton>
135141
</ModalFooter>

0 commit comments

Comments
 (0)