Skip to content

Commit

Permalink
Merge pull request #5275 from brave/fixes-9253-9254
Browse files Browse the repository at this point in the history
Binance widget no longer disconnects when offline.
  • Loading branch information
ryanml authored and bsclifton committed Apr 21, 2020
1 parent 27528d0 commit 84a2256
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
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

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

0 comments on commit 84a2256

Please sign in to comment.