Skip to content

Commit

Permalink
Optimizes react queries
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Nov 18, 2019
1 parent cd6e4e8 commit 379fd37
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,20 @@ export class RewardsPanel extends React.Component<Props, State> {
})

chrome.windows.getCurrent({}, this.onWindowCallback)

chrome.braveRewards.getRewardsMainEnabled(((enabled: boolean) => {
this.props.actions.onEnabledMain(enabled)
}))

chrome.braveRewards.getACEnabled(((enabled: boolean) => {
this.props.actions.onEnabledAC(enabled)
}))

chrome.braveRewards.getRecurringTips((tips: RewardsExtension.RecurringTips) => {
this.props.actions.onRecurringTips(tips)
})

chrome.braveRewards.getAllNotifications((list: RewardsExtension.Notification[]) => {
this.props.actions.onAllNotifications(list)
})

if (!this.props.rewardsPanelData.enabledMain) {
const { externalWallet } = this.props.rewardsPanelData
utils.getExternalWallet(this.actions, externalWallet)
}
const { externalWallet } = this.props.rewardsPanelData
utils.getExternalWallet(this.actions, externalWallet)

this.handleGrantNotification()
this.getBalance()
}

componentDidUpdate (prevProps: Props, prevState: State) {
Expand All @@ -79,9 +71,16 @@ export class RewardsPanel extends React.Component<Props, State> {
}
if (!prevProps.rewardsPanelData.enabledMain && this.props.rewardsPanelData.enabledMain) {
chrome.windows.getCurrent({}, this.onWindowCallback)
this.getBalance()
}
}

getBalance () {
chrome.braveRewards.fetchBalance((balance: RewardsExtension.Balance) => {
this.actions.onBalance(balance)
})
}

handleGrantNotification = () => {
const hash = window && window.location && window.location.hash

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ export class Panel extends React.Component<Props, State> {
})
}

this.getBalance()
chrome.braveRewards.getACEnabled((enabled: boolean) => {
this.props.actions.onEnabledAC(enabled)
})

this.actions.getGrants()
this.actions.getWalletProperties()
this.actions.getCurrentReport()
Expand All @@ -71,8 +74,9 @@ export class Panel extends React.Component<Props, State> {
this.actions.OnPendingContributionsTotal(amount)
}))

const { externalWallet } = this.props.rewardsPanelData
utils.getExternalWallet(this.actions, externalWallet)
chrome.braveRewards.getRecurringTips((tips: RewardsExtension.RecurringTips) => {
this.props.actions.onRecurringTips(tips)
})
}

componentDidUpdate (prevProps: Props, prevState: State) {
Expand All @@ -92,17 +96,10 @@ export class Panel extends React.Component<Props, State> {
}

if (!prevProps.rewardsPanelData.enabledMain && this.props.rewardsPanelData.enabledMain) {
this.getBalance()
this.actions.getGrants()
}
}

getBalance () {
chrome.braveRewards.fetchBalance((balance: RewardsExtension.Balance) => {
this.actions.onBalance(balance)
})
}

componentWillUnmount () {
clearTimeout(this.delayTimer)
}
Expand Down

0 comments on commit 379fd37

Please sign in to comment.