Skip to content

Commit

Permalink
Add WalletRepair
Browse files Browse the repository at this point in the history
  • Loading branch information
whphhg committed May 26, 2017
1 parent 3421703 commit 32ed05e
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vcash-electron",
"productName": "Vcash Electron GUI",
"version": "0.31.6",
"version": "0.31.7",
"description": "Multi-platform and multi-node GUI for Vcash.",
"main": "src/electron.js",
"scripts": {
Expand Down
4 changes: 3 additions & 1 deletion src/components/Maintenance.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import WalletBackup from './WalletBackup'
import WalletDump from './WalletDump'
import WalletEncrypt from './WalletEncrypt'
import WalletPassphraseChange from './WalletPassphraseChange'
import WalletRepair from './WalletRepair'
import WalletSeedDump from './WalletSeedDump'

/** Load translation namespaces and delay rendering until they are loaded. */
Expand Down Expand Up @@ -68,7 +69,8 @@ export default class Maintenance extends React.Component {
<div style={{flex: 1, margin: '0 0 0 10px'}}>
<WalletEncrypt />
<WalletPassphraseChange />
{/** TODO: Implement wallet check and repair. */}
<hr />
<WalletRepair />
</div>
</div>
</div>
Expand Down
132 changes: 132 additions & 0 deletions src/components/WalletRepair.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import React from 'react'
import { translate } from 'react-i18next'
import { action, observable } from 'mobx'
import { inject, observer } from 'mobx-react'
import { Button } from 'antd'

/** Load translation namespaces and delay rendering until they are loaded. */
@translate(['wallet'], { wait: true })

/** Make the component reactive and inject MobX stores. */
@inject('gui', 'rpc') @observer

export default class WalletRepair extends React.Component {
@observable amountAffected = 0
@observable checkPassed = null
@observable mismatchedSpent = 0

constructor (props) {
super(props)
this.t = props.t
this.gui = props.gui
this.rpc = props.rpc
}

/**
* Set RPC response.
* @function setResponse
* @param {object} response - RPC response.
*/
@action setResponse = (response) => {
/** Re-check after repairing. */
if (
this.checkPassed === false &&
response.hasOwnProperty('wallet check passed') === false
) return this.repair()

/** Updated check passed status. */
this.checkPassed = response.hasOwnProperty('wallet check passed')

/** Set or reset amount affected by repair. */
this.amountAffected = this.checkPassed === true
? 0
: response['amount affected by repair']

/** Set or reset mismatched spent amount. */
this.mismatchedSpent = this.checkPassed === true
? 0
: response['mismatched spent coins']
}

/**
* Check for and repair wallet inconsistencies.
* @function repair
* @param {boolean} checkOnly - Check for inconsistencies without repairing.
*/
repair = (checkOnly = true) => {
const method = checkOnly === true
? 'checkwallet'
: 'repairwallet'

this.rpc.execute([
{ method, params: [] }
], (response) => {
/** Set checkPassed and potential mismatched & amount affected. */
if (response[0].hasOwnProperty('result') === true) {
this.setResponse(response[0].result)
}
})
}

render () {
return (
<div>
<div className='flex'>
<i className='material-icons md-16'>build</i>
<p>{this.t('wallet:repairLong')}</p>
</div>
<div style={{margin: '10px 0 0 0'}}>
{
this.checkPassed !== false && (
<div className='flex-sb'>
<div>
{
this.checkPassed !== null && (
<p>{this.t('wallet:checkPassed')}</p>
)
}
</div>
<Button onClick={() => this.repair()}>
{this.t('wallet:check')}
</Button>
</div>
)
}
{
this.checkPassed === false && (
<div className='flex-sb'>
<div>
<div className='flex-sb'>
<p style={{margin: '0 36px 0 0'}}>
{this.t('wallet:mismatched')}:&nbsp;
<span style={{fontWeight: '500'}}>
{
new Intl.NumberFormat(this.gui.language, {
maximumFractionDigits: 6
}).format(this.mismatchedSpent)
} XVC
</span>
</p>
<p>
{this.t('wallet:amountAffected')}:&nbsp;
<span style={{fontWeight: '500'}}>
{
new Intl.NumberFormat(this.gui.language, {
maximumFractionDigits: 6
}).format(this.amountAffected)
} XVC
</span>
</p>
</div>
</div>
<Button onClick={() => this.repair(false)}>
{this.t('wallet:repair')}
</Button>
</div>
)
}
</div>
</div>
)
}
}
6 changes: 6 additions & 0 deletions src/locales/en-US/wallet.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"addresses": "Addresses",
"all": "All",
"amount": "Amount",
"amountAffected": "Amount affected",
"any": "Any",
"backedUp": "Wallet backed up",
"backup": "Make a backup",
Expand All @@ -30,6 +31,8 @@
"chainBlender_start": "ChainBlender started",
"chainBlender_stop": "ChainBlender stopped",
"change": "Change",
"check": "Check",
"checkPassed": "Wallet check passed.",
"collateralBalance": "Collateral balance",
"collateralizedNodes": "Collateralized nodes",
"command": "Command",
Expand Down Expand Up @@ -84,6 +87,7 @@
"locked": "Wallet locked",
"minimumConfirmations": "Minimum confirmations",
"miningReward": "Mining reward",
"mismatched": "Mismatched",
"moneySupply": "Money supply",
"multipleOutputs": "Multiple, double-click for details",
"new": "New",
Expand Down Expand Up @@ -128,6 +132,8 @@
"recipientRemove": "Are you sure you want to remove this recipient?",
"relayedOn": "Relayed on",
"remoteDataFolder": "Remote data folder",
"repair": "Repair",
"repairLong": "Check for and repair wallet inconsistencies",
"reset": "Reset",
"rewards": "Rewards",
"rewardSpread": "Reward spread",
Expand Down
6 changes: 6 additions & 0 deletions src/locales/pt-PT/wallet.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"addresses": "Endereços",
"all": "Tudo",
"amount": "Quantidade",
"amountAffected": "Amount affected",
"any": "Qualquer uma",
"backedUp": "Backup foi realizado",
"backup": "Criar um backup",
Expand All @@ -30,6 +31,8 @@
"chainBlender_start": "ChainBlender foi iniciado com sucesso.",
"chainBlender_stop": "ChainBlender foi interrompido.",
"change": "Troco",
"check": "Check",
"checkPassed": "Wallet check passed.",
"collateralBalance": "Saldo garantido",
"collateralizedNodes": "Nós garantidos",
"command": "Comando",
Expand Down Expand Up @@ -84,6 +87,7 @@
"locked": "A carteira está trancada",
"minimumConfirmations": "Confirmações mínimas",
"miningReward": "Recompensa de mineração",
"mismatched": "Mismatched",
"moneySupply": "Moedas em circulação",
"multipleOutputs": "Clique duas vezes para obter mais detalhes",
"new": "Nova",
Expand Down Expand Up @@ -128,6 +132,8 @@
"recipientRemove": "Tem certeza que quer remover este destinatário?",
"relayedOn": "Retransmitido",
"remoteDataFolder": "Pasta de dados remota",
"repair": "Repair",
"repairLong": "Check for and repair wallet inconsistencies",
"reset": "Refazer",
"rewards": "Recompensas",
"rewardSpread": "Extensão da recompensa",
Expand Down
6 changes: 6 additions & 0 deletions src/locales/ru-RU/wallet.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"addresses": "Адреса",
"all": "Все",
"amount": "Сумма",
"amountAffected": "Amount affected",
"any": "Любые",
"backedUp": "Произведена резервная копия кошелька",
"backup": "Создать резервную копию",
Expand All @@ -30,6 +31,8 @@
"chainBlender_start": "ChainBlender включён",
"chainBlender_stop": "ChainBlender остановлен",
"change": "Изменить",
"check": "Check",
"checkPassed": "Wallet check passed.",
"collateralBalance": "Залоговый баланс",
"collateralizedNodes": "Узлы с залогом",
"command": "Команда",
Expand Down Expand Up @@ -84,6 +87,7 @@
"locked": "Кошелёк заблокирован",
"minimumConfirmations": "Минимальные подтверждения",
"miningReward": "Награда за добычу",
"mismatched": "Mismatched",
"moneySupply": "Денежная масса",
"multipleOutputs": "Несколько, подробная информация по двойному щелчку",
"new": "Новый",
Expand Down Expand Up @@ -128,6 +132,8 @@
"recipientRemove": "Вы действительно хотите удалить этого получателя?",
"relayedOn": "Переданный",
"remoteDataFolder": "Удаленная папка данных",
"repair": "Repair",
"repairLong": "Check for and repair wallet inconsistencies",
"reset": "Сброс",
"rewards": "Награды",
"rewardSpread": "Распределение вознаграждения",
Expand Down
6 changes: 6 additions & 0 deletions src/locales/sl-SI/wallet.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"addresses": "Naslovi",
"all": "Vse",
"amount": "Znesek",
"amountAffected": "Vplivan znesek",
"any": "Katerikoli",
"backedUp": "Kopija denarnice ustvarjena",
"backup": "Ustvari kopijo",
Expand All @@ -30,6 +31,8 @@
"chainBlender_start": "ChainBlender zagnan",
"chainBlender_stop": "ChainBlender ustavljen",
"change": "Preostanek",
"check": "Preveri",
"checkPassed": "Denarnica brez nedoslednosti.",
"collateralBalance": "Vsota zavarovalnine",
"collateralizedNodes": "Vozlišča z zavarovalnino",
"command": "Ukaz",
Expand Down Expand Up @@ -84,6 +87,7 @@
"locked": "Denarnica zaklenjena",
"minimumConfirmations": "Minimalno potrditev",
"miningReward": "Nagrada rudarjenja",
"mismatched": "Neusklajeno",
"moneySupply": "Kovancev v obtoku",
"multipleOutputs": "Več naslovov, dvo-klikni za podrobnosti",
"new": "Novi",
Expand Down Expand Up @@ -128,6 +132,8 @@
"recipientRemove": "Potrdi odstranitev prejemnika.",
"relayedOn": "Posredovana",
"remoteDataFolder": "Oddaljena mapa z podatki",
"repair": "Popravi",
"repairLong": "Poišči in popravi nedoslednosti denarnice",
"reset": "Ponastavi",
"rewards": "Nagrade",
"rewardSpread": "Razpršitev nagrad",
Expand Down

0 comments on commit 32ed05e

Please sign in to comment.