Skip to content

Commit 89c87af

Browse files
committed
fix: change networks logic
1 parent 7667d9a commit 89c87af

File tree

11 files changed

+39
-18
lines changed

11 files changed

+39
-18
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
"he": "^1.2.0",
108108
"jsonwebtoken": "^9.0.0",
109109
"juice-sdk-core": "^12.2.4-alpha",
110-
"juice-sdk-react": "^12.2.4-alpha",
110+
"juice-sdk-react": "^12.2.5-alpha",
111111
"juicebox-metadata-helper": "0.1.7",
112112
"less": "4.1.2",
113113
"lodash": "^4.17.21",

src/hooks/ContractReader/useContractReader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface ContractReaderProps<ContractName extends string, V> {
1616
}
1717

1818
export function useContractReader<ContractName extends string, V>({
19-
contract,
19+
contract, // name of the contract
2020
contracts,
2121
functionName,
2222
args,

src/hooks/ContractReader/util/useCallContractRead.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export async function callContractRead<T extends string>({
1717
contracts?: Record<T, Contract> | undefined
1818
}) {
1919
try {
20-
console.info(`📚 Read >`, functionName)
20+
console.info(`📚 Read >`, functionName, { contract: readContract, args })
2121
return await readContract[functionName](...(args ?? []))
2222
} catch (error) {
2323
console.error(`📕 Read error >`, functionName, error, {

src/hooks/Wallet/hooks/useChangeNetworks.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { useCallback } from 'react'
33

44
import { readNetwork } from 'constants/networks'
55

6+
/**
7+
* Attempts to sync the user wallet's chain with the readNetwork (hard-coded per environment)
8+
* @returns function to sync the user wallet's chain with the readNetwork
9+
*/
610
export function useChangeNetworks() {
711
const [{ chains }, setChain] = useSetChain()
812

src/hooks/Wallet/hooks/useSigner.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@ export function useSigner() {
77
const [{ wallet }] = useConnectWallet()
88
const chainUnsupported = useChainUnsupported()
99
const signerProvider = useMemo(() => {
10-
if (!wallet) return undefined
10+
if (!wallet) {
11+
return undefined
12+
}
13+
1114
return new providers.Web3Provider(wallet.provider, 'any')
1215
}, [wallet])
1316

1417
const signer = useMemo(() => {
1518
// If the provider is not available or the chain is unsupported, we
1619
// shouldn't attempt to do anything
17-
if (!signerProvider || chainUnsupported) return undefined
20+
if (!signerProvider || chainUnsupported) {
21+
return undefined
22+
}
23+
1824
return signerProvider.getSigner()
1925
}, [chainUnsupported, signerProvider])
2026

src/hooks/Wallet/useWallet.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import {
22
useChain,
3+
useChainUnsupported,
34
useChangeNetworks,
45
useDisconnect,
56
useIsConnected,
67
useSigner,
78
useUserAddress,
8-
useWalletBalance
9+
useWalletBalance,
910
} from './hooks'
1011

1112
import { useConnectWallet } from '@web3-onboard/react'
@@ -15,7 +16,7 @@ export function useWallet() {
1516
const userAddress = useUserAddress()
1617
const isConnected = useIsConnected()
1718
const chain = useChain()
18-
const chainUnsupported = false //useChainUnsupported()
19+
const chainUnsupported = useChainUnsupported()
1920
const balance = useWalletBalance()
2021

2122
const [, connect] = useConnectWallet()

src/hooks/useTransactor.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { t } from '@lingui/macro'
22
import { FEATURE_FLAGS } from 'constants/featureFlags'
3+
import { readNetwork } from 'constants/networks'
34
import { TxHistoryContext } from 'contexts/Transaction/TxHistoryContext'
45
import { Contract, providers } from 'ethers'
56
import { simulateTransaction } from 'lib/tenderly'
67
import { TransactionOptions } from 'models/transaction'
78
import { CV2V3 } from 'packages/v2v3/models/cv'
89
import { useCallback, useContext } from 'react'
910
import { featureFlagEnabled } from 'utils/featureFlags'
10-
import { emitErrorNotification } from 'utils/notifications'
11+
import {
12+
emitErrorNotification,
13+
emitInfoNotification,
14+
} from 'utils/notifications'
1115
import { useWallet } from './Wallet'
1216

1317
type TxOpts = Omit<TransactionOptions, 'value'>
@@ -91,6 +95,9 @@ export function useTransactor(): Transactor | undefined {
9195
) => {
9296
if (chainUnsupported) {
9397
await changeNetworks()
98+
emitInfoNotification(
99+
t`Your wallet has been changed to ${readNetwork.name}. Try transaction again.`,
100+
)
94101
options?.onDone?.()
95102
return false
96103
}

src/locales/messages.pot

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,6 +2228,9 @@ msgstr ""
22282228
msgid "Redeem your {tokensLabel} to reclaim a portion of the ETH not needed for payouts. Any {tokensLabel} you redeem will be burned."
22292229
msgstr ""
22302230

2231+
msgid "Your wallet has been changed to {0}. Try transaction again."
2232+
msgstr ""
2233+
22312234
msgid "<0>{tokenSymbol} ERC-20 address:</0> <1/>"
22322235
msgstr ""
22332236

src/packages/v2v3/components/V2V3Project/ProjectDashboard/components/PayRedeemCard/PayProjectModal/hooks/usePayProjectModal/usePayProjectTx.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ export const usePayProjectTx = ({
137137
)
138138
if (!success) {
139139
onTransactionErrorCallback(
140-
onError ?? new Error('Transaction failed'),
140+
onError ??
141+
new Error(
142+
'Payment failed. Make sure your wallet has funds, is set to the correct chain (e.g. mainnet) and try again. If problems persist, click "Reset Website".',
143+
),
141144
formikHelpers,
142145
)
143146
}

src/packages/v2v3/hooks/contractReader/useProjectControllerAddress.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
import { ContractConfig } from 'hooks/ContractReader/types'
21
import { V2V3ContractName } from 'packages/v2v3/models/contracts'
32
import useV2ContractReader from './useV2ContractReader'
43

54
export default function useProjectControllerAddress({
65
projectId,
7-
contract,
86
}: {
9-
projectId?: number
10-
contract?: ContractConfig<V2V3ContractName> | undefined
7+
projectId: number | undefined
118
}) {
129
return useV2ContractReader<string>({
13-
contract: contract ?? V2V3ContractName.JBDirectory,
10+
contract: V2V3ContractName.JBDirectory,
1411
functionName: 'controllerOf',
1512
args: projectId ? [projectId] : null,
1613
})

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12186,10 +12186,10 @@ juice-sdk-core@^12.2.4-alpha:
1218612186
bs58 "^5.0.0"
1218712187
fpnum "^1.0.0"
1218812188

12189-
juice-sdk-react@^12.2.4-alpha:
12190-
version "12.2.4-alpha"
12191-
resolved "https://registry.yarnpkg.com/juice-sdk-react/-/juice-sdk-react-12.2.4-alpha.tgz#2d53d1296d7d0817c3a7dda75b99570df12661f2"
12192-
integrity sha512-SX/WvlCANpgS568Ohdf7q+yC2jLY4vTUUGjgmZD2XUgCZTbfPorgUbZ4pxWwWgtfxydq6vyoPHcUUjWItMEPWw==
12189+
juice-sdk-react@^12.2.5-alpha:
12190+
version "12.2.5-alpha"
12191+
resolved "https://registry.yarnpkg.com/juice-sdk-react/-/juice-sdk-react-12.2.5-alpha.tgz#399a1a2d9a8c7142739bf5578dd2cf9d1b4b75b5"
12192+
integrity sha512-lZnWIBVvo8xwwCQwyhkmvETxIOFP1vwrmekUihwZaPsbzyvrWekvPk7YkgfEWk2W4wClt13g2i9so24vYz2DEQ==
1219312193

1219412194
juice@^10.0.0:
1219512195
version "10.0.0"

0 commit comments

Comments
 (0)