Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Removes TODO's and fixed wallet recovery
Browse files Browse the repository at this point in the history
Fixes clear  #11278
Fixes default monthly budget
  • Loading branch information
NejcZdovc committed Oct 6, 2017
1 parent c495ba6 commit 3abcacb
Show file tree
Hide file tree
Showing 9 changed files with 274 additions and 304 deletions.
25 changes: 14 additions & 11 deletions app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -1201,8 +1201,7 @@ const recoverKeys = (state, useRecoveryKeyFile, firstKey, secondKey) => {
if (
typeof firstRecoveryKey !== 'string' ||
!firstRecoveryKey.match(UUID_REGEX) ||
typeof secondRecoveryKey !== 'string' ||
!secondRecoveryKey.match(UUID_REGEX)
typeof secondRecoveryKey !== 'string'
) {
// calling logError sets the error object
state = logError(state, true, 'recoverKeys')
Expand All @@ -1224,7 +1223,7 @@ const onWalletRecovery = (state, error, result) => {
// we reset ledgerInfo.error to what it was before (likely null)
// if ledgerInfo.error is not null, the wallet info will not display in UI
// logError sets ledgerInfo.error, so we must we clear it or UI will show an error
state = logError(state, error, 'recoveryWallet')
state = logError(state, error.toString(), 'recoveryWallet')
state = ledgerState.setInfoProp(state, 'error', existingLedgerError)
state = ledgerState.setRecoveryStatus(state, false)
} else {
Expand Down Expand Up @@ -1683,11 +1682,10 @@ const onWalletProperties = (state, body) => {
// Current currency
const info = ledgerState.getInfoProps(state)
const infoRates = info.get('rates')
const currency = info.getIn(['bravery', 'fee', 'currency'])
let rate = null
const currency = 'USD' // TODO for now it's fixed
let rate = infoRates.get(currency)

if (currency) {
rate = infoRates.get(currency)
if (rate) {
state = ledgerState.setInfoProp(state, 'currentRate', rate)
}

Expand All @@ -1698,7 +1696,7 @@ const onWalletProperties = (state, body) => {

const amount = info.get('balance')

if (currency && amount && rate) {
if (amount && rate) {
const bigProbi = new BigNumber(probi.toString()).dividedBy('1e18')
const bigRate = new BigNumber(rate.toString())
const converted = bigProbi.times(bigRate).toFormat(2)
Expand Down Expand Up @@ -2204,7 +2202,7 @@ const migration = (state) => {
}

// for synopsis variable handling only
const deleteSynopsis = (publisherKey) => {
const deleteSynopsisPublisher = (publisherKey) => {
delete synopsis.publishers[publisherKey]
}

Expand All @@ -2218,6 +2216,10 @@ const savePublisherOption = (publisherKey, prop, value) => {
}
}

const deleteSynopsis = () => {
synopsis.publishers = {}
}

module.exports = {
backupKeys,
recoverKeys,
Expand All @@ -2239,13 +2241,14 @@ module.exports = {
onBraveryProperties,
onLedgerFirstSync,
onCallback,
deleteSynopsis,
deleteSynopsisPublisher,
saveOptionSynopsis,
savePublisherOption,
onTimeUntilReconcile,
run,
onNetworkConnected,
migration,
onInitRead,
notifications
notifications,
deleteSynopsis
}
9 changes: 3 additions & 6 deletions app/browser/reducers/ledgerReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const ledgerReducer = (state, action, immutableAction) => {
const clearData = defaults ? defaults.merge(temp) : temp
if (clearData.get('browserHistory') && !getSetting(settings.PAYMENTS_ENABLED)) {
state = ledgerState.resetSynopsis(state)
ledgerApi.deleteSynopsis()
}
break
}
Expand Down Expand Up @@ -130,7 +131,7 @@ const ledgerReducer = (state, action, immutableAction) => {
case 'ledgerPaymentsShown':
{
if (action.get('value') === false) {
ledgerApi.deleteSynopsis(publisherKey)
ledgerApi.deleteSynopsisPublisher(publisherKey)
state = ledgerState.deletePublishers(state, publisherKey)
state = ledgerApi.updatePublisherInfo(state)
}
Expand Down Expand Up @@ -264,11 +265,7 @@ const ledgerReducer = (state, action, immutableAction) => {
}
case appConstants.APP_ON_CHANGE_ADD_FUNDS_DIALOG_STEP:
{
// CC Nejc move this to a helper method as needed
state = state.mergeIn(['addFunds'], {
currentPage: action.get('page'),
currency: action.get('currency')
})
state = ledgerState.saveWizardData(state, action.get('page'), action.get('currency'))
break
}
case appConstants.APP_ON_WALLET_RECOVERY:
Expand Down
6 changes: 3 additions & 3 deletions app/browser/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ const updateAboutDetails = (tab, tabValue) => {

// TODO(bridiver) - refactor these to use state helpers
const ledgerInfo = ledgerState.getInfoProps(appState)
const synopsis = appState.getIn(['ledger', 'about'])
const synopsis = ledgerState.getAboutData(appState)
const wizardData = ledgerState.geWizardData(appState)
const preferencesData = appState.getIn(['about', 'preferences'])
const appSettings = appState.get('settings')
let allSiteSettings = appState.get('siteSettings')
if (tabValue.get('incognito') === true) {
allSiteSettings = allSiteSettings.mergeDeep(appState.get('temporarySiteSettings'))
}
const extensionsValue = appState.get('extensions')
const addFundsDialogState = appState.get('addFunds')
const sync = appState.get('sync')
const braveryDefaults = siteSettings.braveryDefaults(appState, appConfig)
const history = aboutHistoryState.getHistory(appState)
Expand Down Expand Up @@ -197,7 +197,7 @@ const updateAboutDetails = (tab, tabValue) => {
const ledgerData = ledgerInfo
.merge(synopsis)
.merge(preferencesData)
.set('addFunds', addFundsDialogState)
.set('wizardData', wizardData)
tab.send(messages.LEDGER_UPDATED, ledgerData.toJS())
tab.send(messages.SETTINGS_UPDATED, appSettings.toJS())
tab.send(messages.SITE_SETTINGS_UPDATED, allSiteSettings.toJS())
Expand Down
25 changes: 22 additions & 3 deletions app/common/state/ledgerState.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,10 @@ const ledgerState = {
return state.setIn(['ledger', 'info', 'error'], null)
}

return state
.setIn(['ledger', 'info', 'error', 'caller'], caller)
.setIn(['ledger', 'info', 'error', 'error'], error)
return state.setIn(['ledger', 'info', 'error'], Immutable.fromJS({
caller: caller,
error: error
}))
},

changePinnedValues: (state, publishers) => {
Expand All @@ -307,6 +308,7 @@ const ledgerState = {
return state
},

// About page
// TODO (optimization) don't have two almost identical object in state (synopsi->publishers and about->synopsis)
saveAboutSynopsis: (state, publishers) => {
state = validateState(state)
Expand All @@ -319,6 +321,23 @@ const ledgerState = {
state = validateState(state)
return state
.setIn(['ledger', 'about', 'synopsisOptions'], ledgerState.getSynopsisOptions(state))
},

getAboutData: (state) => {
return state.getIn(['ledger', 'about']) || Immutable.Map()
},

saveWizardData: (state, page, currency) => {
state = validateState(state)
return state.mergeIn(['ledger', 'wizardData'], {
currentPage: page,
currency: currency
})
},

geWizardData: (state) => {
state = validateState(state)
return state.getIn(['ledger', 'wizardData']) || Immutable.Map()
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/renderer/components/preferences/paymentsTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class PaymentsTab extends ImmutableComponent {
const ledgerData = this.props.ledgerData || Immutable.Map()
const addresses = ledgerData.get('addresses') || Immutable.List()
const walletQR = ledgerData.get('walletQR') || Immutable.List()
const wizardData = ledgerData.get('addFunds') || Immutable.Map()
const wizardData = ledgerData.get('wizardData') || Immutable.Map()
const funds = formatCurrentBalance(ledgerData)

return <AddFundsDialog
Expand All @@ -94,7 +94,7 @@ class PaymentsTab extends ImmutableComponent {

get overlayFooter () {
const ledgerData = this.props.ledgerData || Immutable.Map()
const wizardData = ledgerData.get('addFunds') || Immutable.Map()
const wizardData = ledgerData.get('wizardData') || Immutable.Map()

return (
<AddFundsDialogFooter
Expand Down
2 changes: 1 addition & 1 deletion js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,7 @@ const appActions = {
})
},

onChangeAddFundsDialogStep: function (page, currency = 'bat') {
onChangeAddFundsDialogStep: function (page, currency = 'BAT') {
dispatch({
actionType: appConstants.APP_ON_CHANGE_ADD_FUNDS_DIALOG_STEP,
page,
Expand Down
2 changes: 1 addition & 1 deletion js/constants/appConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ module.exports = {
'general.disable-title-mode': process.platform === 'linux' || process.platform === 'win32',
// payments
'payments.allow-non-verified-publishers': true,
'payments.contribution-amount': 5, // USD
'payments.contribution-amount': 25, // BAT
'payments.enabled': false,
'payments.minimum-visit-time': 8000,
'payments.minimum-visits': 1,
Expand Down
Loading

0 comments on commit 3abcacb

Please sign in to comment.