Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

settings: network preferences #238

Merged
merged 24 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/Dashboard/Balance.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const Balance = React.memo(function Balance({
`}
>
{loading ? (
<Loading height={150} />
<Loading height={86} />
) : (
<animated.div
style={springProps}
Expand Down
2 changes: 1 addition & 1 deletion src/components/GlobalPreferences/Network/Network.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function Network() {
)}`
}
if (networkError instanceof InvalidURI) {
return 'Must provide WebSocket endpoint to node'
return 'Must provide Http endpoint to node'
}
if (networkError instanceof NoConnection) {
return 'Could not connect to node'
Expand Down
62 changes: 0 additions & 62 deletions src/hooks/useCourtContracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,6 @@ function useCourtContract(moduleType, abi) {
return useContract(contractAddress, abi)
}

function useCourtContractReadOnly(moduleType, abi) {
const { modules } = useCourtConfig()

const contractAddress = getModuleAddress(modules, moduleType)

return useContractReadOnly(contractAddress, abi)
}

/**
* All ANJ interactions
* @returns {Object} all available functions around ANJ balances
Expand Down Expand Up @@ -633,57 +625,3 @@ export function useTotalANTStakedPolling(timeout = 1000) {

return [totalANTStaked, error]
}

export function useTotalANTStaked() {
const [totalANTStaked, setTotalANTStaked] = useState(bigNum(-1))

const jurorRegistryContract = useCourtContractReadOnly(
CourtModuleType.JurorsRegistry,
jurorRegistryAbi
)
useEffect(() => {
if (!jurorRegistryContract) {
return
}
const getTotalANTStaked = async () => {
retryMax(() => jurorRegistryContract.totalStaked())
.then(totalStaked => {
setTotalANTStaked(totalStaked)
})
.catch(err => {
console.error(`Error fetching ANT staked: ${err}`)
})
}

getTotalANTStaked()
}, [jurorRegistryContract])

return totalANTStaked
}

export function useTotalActiveBalance() {
const [totalActiveBalance, setTotalActiveBalance] = useState(bigNum(-1))
const jurorRegistryContract = useCourtContractReadOnly(
CourtModuleType.JurorsRegistry,
jurorRegistryAbi
)

useEffect(() => {
if (!jurorRegistryContract) {
return
}
const getTotalActiveBalance = async () => {
retryMax(() => jurorRegistryContract.totalActiveBalance())
.then(totalActive => {
setTotalActiveBalance(totalActive)
})
.catch(err => {
console.error(`Error fetching ANT staked: ${err}`)
})
}

getTotalActiveBalance()
}, [jurorRegistryContract])

return totalActiveBalance
}
9 changes: 4 additions & 5 deletions src/lib/web3-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const ETH_FAKE_ADDRESS = `0x${''.padEnd(40, '0')}`

const ETH_ADDRESS_SPLIT_REGEX = /(0x[a-fA-F0-9]{40}(?:\b|\.|,|\?|!|;))/g
const ETH_ADDRESS_TEST_REGEX = /(0x[a-fA-F0-9]{40}(?:\b|\.|,|\?|!|;))/g
const websocketRegex = /^wss?:\/\/.+/
const httpRegex = /^(http|https):\/\//

export function getFunctionSignature(func) {
return keccak256(func).slice(0, 10)
Expand Down Expand Up @@ -172,10 +172,9 @@ export function transformAddresses(str, callback) {
export async function checkValidEthNode(uri) {
// Must be websocket connection
const isLocalOrUnknown = isLocalOrUnknownNetwork(env('CHAIN_ID'))
if (!isLocalOrUnknown) {
if (!websocketRegex.test(uri)) {
throw new InvalidURI('The URI must use the WebSocket protocol')
}

if (!httpRegex.test(uri)) {
throw new InvalidURI('The URI must use the Http protocol')
}

try {
Expand Down