This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 970
Adds clear/delete payments options #14116
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1209,12 +1209,19 @@ const onWalletRecovery = (state, error, result) => { | |
return state | ||
} | ||
|
||
const resetPublishers = (state) => { | ||
state = ledgerState.resetPublishers(state) | ||
synopsis.publishers = {} | ||
|
||
return state | ||
} | ||
|
||
const quit = (state) => { | ||
quitP = true | ||
state = addNewLocation(state, locationDefault) | ||
|
||
if (!getSetting(settings.PAYMENTS_ENABLED) && getSetting(settings.SHUTDOWN_CLEAR_HISTORY)) { | ||
state = ledgerState.resetSynopsis(state, true) | ||
if (!getSetting(settings.PAYMENTS_ENABLED) && getSetting(settings.SHUTDOWN_CLEAR_PUBLISHERS)) { | ||
resetPublishers(state) | ||
} | ||
|
||
return state | ||
|
@@ -2721,10 +2728,6 @@ const savePublisherData = (publisherKey, prop, value) => { | |
synopsis.publishers[publisherKey][prop] = value | ||
} | ||
|
||
const deleteSynopsis = () => { | ||
synopsis.publishers = {} | ||
} | ||
|
||
let currentMediaKey = null | ||
const onMediaRequest = (state, xhr, type, details) => { | ||
if (!xhr || type == null) { | ||
|
@@ -3123,6 +3126,53 @@ const activityRoundTrip = (err, response, body) => { | |
updater.checkForUpdate(false, true) | ||
} | ||
|
||
const deleteWallet = (state) => { | ||
state = ledgerState.deleteSynopsis(state) | ||
state = state.setIn(['settings', settings.PAYMENTS_ENABLED], false) | ||
|
||
client = null | ||
synopsis = null | ||
|
||
const fs = require('fs') | ||
fs.access(pathName(statePath), fs.constants.F_OK, (err) => { | ||
if (err) { | ||
return | ||
} | ||
|
||
fs.unlink(pathName(statePath), (err) => { | ||
if (err) { | ||
return console.error('read error: ' + err.toString()) | ||
} | ||
}) | ||
}) | ||
|
||
return state | ||
} | ||
|
||
const clearPaymentHistory = (state) => { | ||
state = ledgerState.setInfoProp(state, 'transactions', Immutable.List()) | ||
state = ledgerState.setInfoProp(state, 'ballots', Immutable.List()) | ||
state = ledgerState.setInfoProp(state, 'batch', Immutable.Map()) | ||
|
||
const fs = require('fs') | ||
const path = pathName(statePath) | ||
try { | ||
fs.accessSync(path, fs.constants.W_OK) | ||
let data = fs.readFileSync(path) | ||
data = JSON.parse(data) | ||
if (data) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would it be helpful to set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We would like to keep memos, because we use them for debugging if needed |
||
data.transactions = [] | ||
data.ballots = [] | ||
data.batch = {} | ||
muonWriter(statePath, data) | ||
} | ||
} catch (err) { | ||
console.error(`Problem reading ${path} when clearing payment history`) | ||
} | ||
|
||
return state | ||
} | ||
|
||
const getMethods = () => { | ||
const publicMethods = { | ||
backupKeys, | ||
|
@@ -3152,7 +3202,6 @@ const getMethods = () => { | |
onNetworkConnected, | ||
migration, | ||
onInitRead, | ||
deleteSynopsis, | ||
normalizePinned, | ||
roundToTarget, | ||
onFavIconReceived, | ||
|
@@ -3180,7 +3229,10 @@ const getMethods = () => { | |
addSiteVisit, | ||
getCaptcha, | ||
onCaptchaResponse, | ||
shouldTrackTab | ||
shouldTrackTab, | ||
deleteWallet, | ||
resetPublishers, | ||
clearPaymentHistory | ||
} | ||
|
||
let privateMethods = {} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should make sure the file is deleted successfully before disabling payments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that this is needed, because we will delete all data related to the payments in the state, so when you run it again it should override this file if still exists