Skip to content

fix: currency balance loading, firefox bugs #14

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

Merged
merged 7 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 8 additions & 6 deletions src/components/CurrencyInputPanel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ const GAS_MARGIN = ethers.utils.bigNumberify(1000)

const SubCurrencySelect = styled.button`
${({ theme }) => theme.flexRowNoWrap}
background: ${({ theme }) => theme.zumthorBlue};

border: 1px solid ${({ theme }) => theme.royalBlue};
color: ${({ theme }) => theme.royalBlue};
padding: 4px 50px 4px 15px;
margin-right: -40px;
line-height: 0;
height: 2rem;
padding: 10px 50px 10px 15px;
margin-right: -40px;
align-items: center;
border-radius: 2.5rem;
outline: none;
cursor: pointer;
user-select: none;
background: ${({ theme }) => theme.zumthorBlue};
border: 1px solid ${({ theme }) => theme.royalBlue};
color: ${({ theme }) => theme.royalBlue};
`

const InputRow = styled.div`
Expand All @@ -54,6 +54,7 @@ const Input = styled(BorderlessInput)`
font-size: 1.5rem;
color: ${({ error, theme }) => error && theme.salmonRed};
background-color: ${({ theme }) => theme.inputBackground};
-moz-appearance: textfield;
`

const StyledBorderlessInput = styled(BorderlessInput)`
Expand Down Expand Up @@ -336,6 +337,7 @@ export default function CurrencyInputPanel({
min="0"
error={!!errorMessage}
placeholder="0.0"
step="0.000000000000000001"
onChange={e => onValueChange(e.target.value)}
onKeyPress={e => {
const charCode = e.which ? e.which : e.keyCode
Expand Down
22 changes: 15 additions & 7 deletions src/components/Web3ReactManager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ const SpinnerWrapper = styled(Spinner)`
`

function tryToSetConnector(setConnector, setError) {
setConnector('Injected', { suppressAndThrowErrors: true }).catch(error => {
setConnector('Network')
setConnector('Injected', { suppressAndThrowErrors: true }).catch(() => {
setConnector('Network', { suppressAndThrowErrors: true }).catch(error => {
setError(error)
})
})
}

Expand All @@ -54,25 +56,31 @@ export default function Web3ReactManager({ children }) {
if (accounts.length >= 1) {
tryToSetConnector(setConnector, setError)
} else {
setConnector('Network')
setConnector('Network', { suppressAndThrowErrors: true }).catch(error => {
setError(error)
})
}
})
}
} else {
setConnector('Network')
setConnector('Network', { suppressAndThrowErrors: true }).catch(error => {
setError(error)
})
}
}
}, [active, error, setConnector, setError])
})

// parse the error
useEffect(() => {
if (error) {
// if the user changes to the wrong network, unset the connector
if (error.code === Connector.errorCodes.UNSUPPORTED_NETWORK) {
setConnector('Network')
setConnector('Network', { suppressAndThrowErrors: true }).catch(error => {
setError(error)
})
}
}
}, [error, setConnector])
})

const [showLoader, setShowLoader] = useState(false)
useEffect(() => {
Expand Down
37 changes: 24 additions & 13 deletions src/contexts/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,35 @@ export function Updater() {
const globalBlockNumber = useBlockNumber()
const [, { updateBlockNumber, updateUSDPrice }] = useApplicationContext()

// slow down polling interval
// if (library && connectorName === 'Network' && library.pollingInterval !== 15) {
// library.pollingInterval = 15
// } else if (library && library.pollingInterval !== 5) {
// library.pollingInterval = 5
// }

// update usd price
useEffect(() => {
let stale = false
if (library) {
let stale = false

getUSDPrice(library)
.then(([price]) => {
if (!stale) {
updateUSDPrice(networkId, price)
}
})
.catch(() => {
if (!stale) {
updateUSDPrice(networkId, null)
}
})
getUSDPrice(library)
.then(([price]) => {
if (!stale) {
updateUSDPrice(networkId, price)
}
})
.catch(() => {
if (!stale) {
updateUSDPrice(networkId, null)
}
})
}
}, [globalBlockNumber, library, networkId, updateUSDPrice])

// update block number
useEffect(() => {
if ((networkId || networkId === 0) && library) {
if (library) {
let stale = false

function update() {
Expand Down