Skip to content

Commit

Permalink
Merge pull request #712 from brave/create-wallet-settings
Browse files Browse the repository at this point in the history
Panel fixes
  • Loading branch information
NejcZdovc authored Oct 24, 2018
2 parents 9b3dd76 + e88e385 commit 9ff9849
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ deps = {
"vendor/boto": "https://github.com/boto/boto@f7574aa6cc2c819430c1f05e9a1a1a666ef8169b",
"vendor/python-patch": "https://github.com/svn2github/python-patch@a336a458016ced89aba90dfc3f4c8222ae3b1403",
"vendor/sparkle": "https://github.com/brave/Sparkle.git@c0759cce415d7c0feae45005c8a013b1898711f0",
"vendor/bat-native-ledger": "https://github.com/brave-intl/bat-native-ledger@201a814e36dec9e4eca7c9c7a7f5c8d0f1f5be16",
"vendor/bat-native-ledger": "https://github.com/brave-intl/bat-native-ledger@9a4d0e00d78343de8863d60657727ae4eb5d6321",
"vendor/bat-native-rapidjson": "https://github.com/brave-intl/bat-native-rapidjson.git@86aafe2ef89835ae71c9ed7c2527e3bb3000930e",
"vendor/bip39wally-core-native": "https://github.com/brave-intl/bip39wally-core-native.git@9b119931c702d55be994117eb505d56310720b1d",
"vendor/bat-native-anonize": "https://github.com/brave-intl/bat-native-anonize.git@adeff3254bb90ccdc9699040d5a4e1cd6b8393b7",
Expand Down
7 changes: 7 additions & 0 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,13 @@ void RewardsServiceImpl::Shutdown() {
void RewardsServiceImpl::OnWalletInitialized(ledger::Result result) {
if (!ready_.is_signaled())
ready_.Signal();

if (result == ledger::Result::WALLET_CREATED) {
SetRewardsMainEnabled(true);
SetAutoContribute(true);
result = ledger::Result::LEDGER_OK;
}

TriggerOnWalletInitialized(result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ function setBadgeText (state: RewardsExtension.State): void {
})
}

const getWindowId = (id: number) => {
return `id_${id}`
}

const getNotificationId = (id: number) => {
return `n_${id}`
}

export const rewardsPanelReducer = (state: RewardsExtension.State | undefined, action: any) => {
if (state === undefined) {
state = storage.load()
Expand Down Expand Up @@ -59,14 +67,22 @@ export const rewardsPanelReducer = (state: RewardsExtension.State | undefined, a
break
}

state = { ...state }
chrome.braveRewards.getPublisherData(tab.windowId, tab.url, tab.favIconUrl || '')
const id = getWindowId(tab.windowId)
let publishers: Record<string, RewardsExtension.Publisher> = state.publishers
if (publishers[id]) {
delete publishers[id]
}
state = {
...state,
publishers
}
break
case types.ON_PUBLISHER_DATA:
{
const publisher = payload.publisher
let publishers: Record<string, RewardsExtension.Publisher> = state.publishers
const id = `id_${payload.windowId}`
const id = getWindowId(payload.windowId)

if (publisher && !publisher.publisher_key) {
delete publishers[id]
Expand Down Expand Up @@ -104,7 +120,7 @@ export const rewardsPanelReducer = (state: RewardsExtension.State | undefined, a
return
}

const id = `n_${payload.id}`
const id = getNotificationId(payload.id)
let notifications: Record<number, RewardsExtension.Notification> = state.notifications

if (!notifications) {
Expand Down Expand Up @@ -142,7 +158,7 @@ export const rewardsPanelReducer = (state: RewardsExtension.State | undefined, a
return
}

const id = `n_${payload.id}`
const id = getNotificationId(payload.id)
let notifications: Record<number, RewardsExtension.Notification> = state.notifications
delete notifications[id]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,35 @@ export class RewardsPanel extends React.Component<Props, State> {
chrome.windows.getCurrent({}, this.onWindowCallback)
}

componentDidUpdate (prevProps: Props, prevState: State) {
if (
!prevProps.rewardsPanelData.walletCreated &&
this.props.rewardsPanelData.walletCreated
) {
this.getTabData()
}
}

getTabData () {
chrome.tabs.query({
active: true,
currentWindow: true
}, (tabs) => {
if (!tabs || !tabs.length) {
return
}
this.props.actions.onTabRetrieved(tabs[0])
})
}

onWindowCallback = (window: chrome.windows.Window) => {
this.setState({
windowId: window.id
})

if (this.props.rewardsPanelData.walletCreated) {
this.getTabData()
}
}

openRewards () {
Expand Down
4 changes: 2 additions & 2 deletions components/brave_rewards/ui/reducers/wallet_reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ const createWallet = (state: Rewards.State) => {
state.enabledAds = true
state.enabledContribute = true
state.createdTimestamp = new Date().getTime()

chrome.send('brave_rewards.getReconcileStamp', [])
chrome.send('brave_rewards.getAddresses', [])
chrome.send('brave_rewards.saveSetting', ['enabledMain', 'true'])
chrome.send('brave_rewards.saveSetting', ['enabledContribute', 'true'])
chrome.send('brave_rewards.getContributionAmount', [])

return state
Expand Down Expand Up @@ -182,6 +181,7 @@ const walletReducer: Reducer<Rewards.State | undefined> = (state: Rewards.State,
}
state = { ...state }
state = createWallet(state)
state.firstLoad = false
break
}
case types.ON_CONTRIBUTION_AMOUNT:
Expand Down

0 comments on commit 9ff9849

Please sign in to comment.