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

Binance widget no longer disconnects when offline. #5275

Merged
merged 1 commit into from
Apr 17, 2020
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
20 changes: 17 additions & 3 deletions components/brave_new_tab_ui/components/default/binance/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,7 @@ class Binance extends React.PureComponent<Props, State> {

if (this.props.userAuthed) {
this.props.onUpdateActions()
this.refreshInterval = setInterval(() => {
this.props.onUpdateActions()
}, 30000)
this.checkSetRefreshInterval()
}

if (this.props.authInProgress) {
Expand Down Expand Up @@ -246,10 +244,20 @@ class Binance extends React.PureComponent<Props, State> {
componentDidUpdate (prevProps: Props) {
if (!prevProps.userAuthed && this.props.userAuthed) {
this.props.onUpdateActions()
this.checkSetRefreshInterval()
}

if (prevProps.userAuthed && !this.props.userAuthed) {
this.getClientURL()
this.clearIntervals()
}
}

checkSetRefreshInterval = () => {
if (!this.refreshInterval) {
this.refreshInterval = setInterval(() => {
this.props.onUpdateActions()
}, 30000)
}
}

Expand All @@ -268,6 +276,11 @@ class Binance extends React.PureComponent<Props, State> {
}
}

clearIntervals = () => {
clearInterval(this.convertTimer)
clearInterval(this.refreshInterval)
}

connectBinance = () => {
const { binanceClientUrl } = this.props
window.open(binanceClientUrl, '_self')
Expand Down Expand Up @@ -313,6 +326,7 @@ class Binance extends React.PureComponent<Props, State> {
}

finishDisconnect = () => {
this.clearIntervals()
chrome.binance.revokeToken(() => {
this.props.onDisconnectBinance()
this.cancelDisconnect()
Expand Down
6 changes: 5 additions & 1 deletion components/brave_new_tab_ui/containers/newTab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,11 @@ class NewTabPage extends React.Component<Props, State> {

fetchBalance = () => {
chrome.binance.getAccountBalances((balances: Record<string, string>, success: boolean) => {
if (!success) {
const hasBalances = Object.keys(balances).length
Copy link
Contributor Author

@ryanml ryanml Apr 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will always be empty ({}) in an offline response. Also, we shouldn't set auth to invalid if balances simply just don't come in anyway. The success parameter is the correct thing to go off of for that.


if (!hasBalances) {
return
} else if (!success) {
this.setAuthInvalid()
return
}
Expand Down