Skip to content

Commit

Permalink
trim WIF to make sure extra spaces don't cause errors
Browse files Browse the repository at this point in the history
  • Loading branch information
peerchemist committed May 25, 2019
1 parent ee208d3 commit 60ec392
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/components/RegisterPopup/RegisterPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ class RegisterPopup extends React.Component<{}, IState> {

{!this.state.fee && <form className="form" onSubmit={this.handleFee}>
<label>Insert your WIF:</label>
<textarea className="form-field" autoCorrect="false" placeholder="Type WIF here..." value={this.state.wif} onChange={this.handleWIF} />
<textarea className="form-field" autoCorrect="false" placeholder="Type WIF here..." value={this.state.wif.trim()} onChange={this.handleWIF} />

This comment has been minimized.

Copy link
@willyfromtheblock

willyfromtheblock May 25, 2019

Member

as this is a controlled input, trimming would be better in onChange={this.handleWIF}

{this.state.errorMsg && <div className="error-msg">{this.state.errorMsg}</div>}
<button className="form-submit" disabled={this.state.isLoading || this.state.isSuccess}>Calculate Fee</button>
</form>}

{this.state.fee && <form className="form" onSubmit={this.handleForm}>
<label>Insert your WIF:</label>
<textarea className="form-field" autoCorrect="false" placeholder="Type WIF here..." value={this.state.wif} onChange={this.handleWIF} />
<textarea className="form-field" autoCorrect="false" placeholder="Type WIF here..." value={this.state.wif.trim()} onChange={this.handleWIF} />
{this.state.errorMsg && <div className="error-msg">{this.state.errorMsg}</div>}
<button className="form-submit" disabled={this.state.isLoading || this.state.isSuccess}>{this.state.originalHash ? 'Update' : 'Register'} Document</button>
</form>}
Expand Down
6 changes: 3 additions & 3 deletions src/services/Perpera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ export default class PerperaService {

public async setDocument(hash: string, wif: string) {
const doc = new this.perpera.Document(hash, this.network);
const spender = this.perpera.Spender.fromWIF(wif, this.network);
const spender = this.perpera.Spender.fromWIF(wif.trim(), this.network);
await spender.sync();
return await doc.updateContent({'sha2-256': hash}, spender);
}

public async updateDocument(originalHash: string, hash: string, wif: string) {
const doc = new this.perpera.Document(hash, this.network);
const spender = this.perpera.Spender.fromWIF(wif, this.network);
const spender = this.perpera.Spender.fromWIF(wif.trim(), this.network);
await spender.sync();
return await doc.updateContent({'sha2-256': hash}, spender);
}

public async getFee(hash: string, wif: string) {
const doc = new this.perpera.Document(hash, this.network);
const spender = this.perpera.Spender.fromWIF(wif, this.network);
const spender = this.perpera.Spender.fromWIF(wif.trim(), this.network);
await spender.sync();
const update = await doc.considerUpdatingContent({'sha2-256': hash}, spender);
return {
Expand Down

0 comments on commit 60ec392

Please sign in to comment.