Skip to content

Commit

Permalink
Merge pull request #4 from jplomas/master
Browse files Browse the repository at this point in the history
feat: receive command (terminal QR code)
  • Loading branch information
jplomas authored Jul 23, 2019
2 parents 9bdddde + e921e8c commit e4858ba
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 3 deletions.
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $ npm install -g @theqrl/cli
$ qrl-cli COMMAND
running command...
$ qrl-cli (-v|--version|version)
@theqrl/cli/1.1.0 darwin-x64 node-v8.11.3
@theqrl/cli/1.1.0 linux-x64 node-v12.3.1
$ qrl-cli --help [COMMAND]
USAGE
$ qrl-cli COMMAND
Expand All @@ -34,6 +34,7 @@ USAGE
* [`qrl-cli balance ADDRESS`](#qrl-cli-balance-address)
* [`qrl-cli create-wallet`](#qrl-cli-create-wallet)
* [`qrl-cli help [COMMAND]`](#qrl-cli-help-command)
* [`qrl-cli receive ADDRESS`](#qrl-cli-receive-address)
* [`qrl-cli validate ADDRESS`](#qrl-cli-validate-address)

## `qrl-cli balance ADDRESS`
Expand Down Expand Up @@ -99,6 +100,24 @@ OPTIONS

_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v2.2.0/src/commands/help.ts)_

## `qrl-cli receive ADDRESS`

Displays a QR code of the QRL address to receive a transaction

```
USAGE
$ qrl-cli receive ADDRESS
ARGUMENTS
ADDRESS address to display QR code for
DESCRIPTION
...
TODO
```

_See code: [src/commands/receive.js](https://github.com/theqrl/qrl-cli/blob/v1.1.0/src/commands/receive.js)_

## `qrl-cli validate ADDRESS`

Validate a QRL address
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"crypto": "^1.0.1",
"kleur": "^3.0.3",
"ora": "^3.4.0",
"qrcode-terminal": "^0.12.0",
"qrllib": "^1.0.4"
},
"devDependencies": {
Expand Down
5 changes: 3 additions & 2 deletions src/commands/balance.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* eslint new-cap: 0 */
const {Command, flags} = require('@oclif/command')
const {red, green} = require('kleur')
// const ora = require('ora')
// might be nice to add ora spinner whilst loading from API
const ora = require('ora')
const validateQrlAddress = require('@theqrl/validate-qrl-address')
const axios = require('axios')
const BigNumber = require('bignumber.js')
Expand All @@ -25,13 +24,15 @@ class Balance extends Command {
this.log(`${red('⨉')} Unable to get a balance: invalid QRL address`)
this.exit(1)
}
const spinner = ora({text: 'Fetching balance from API...'}).start()
let api = ''
if (flags.api) {
api = flags.api
} else {
api = 'https://brooklyn.theqrl.org/api/GetBalance'
}
const bal = await GetBalance(address, api)
spinner.stop()
if (bal.error === 1) {
this.log(`${red('⨉')} ${bal.errorMessage}`)
this.exit(1)
Expand Down
32 changes: 32 additions & 0 deletions src/commands/receive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint new-cap: 0 */
const {Command} = require('@oclif/command')
const {red} = require('kleur')
const validateQrlAddress = require('@theqrl/validate-qrl-address')
const qrcode = require('qrcode-terminal')

class Receive extends Command {
async run() {
const {args} = this.parse(Receive)
const address = args.address
if (!validateQrlAddress.hexString(address).result) {
this.log(`${red('⨉')} Invalid QRL address`)
this.exit(1)
}
this.log(qrcode.generate(address))
}
}

Receive.description = `Displays a QR code of the QRL address to receive a transaction
...
TODO
`

Receive.args = [
{
name: 'address',
description: 'address to display QR code for',
required: true,
},
]

module.exports = {Receive}
61 changes: 61 additions & 0 deletions test/commands/receive.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* global before */
const assert = require('assert')
const spawn = require('child_process').spawn

const processFlags = {
detached: true,
stdio: 'inherit',
}

describe('receive', () => {
let args = [
'receive',
]
let exitCode
before(done => {
let process = spawn('./bin/run', args, processFlags)
process.on('exit', code => {
exitCode = code
done()
})
})
it('exit code should be non-0 if passed without an argument', () => {
assert.notStrictEqual(exitCode, 0)
})
})

describe('receive', () => {
let args = [
'receive',
'Q010500bc576efa69fd6cbc854f2224f149f0b0a4d18fcb30c1feab64781245f4f27a61874227f3',
]
let exitCode
before(done => {
let process = spawn('./bin/run', args, processFlags)
process.on('exit', code => {
exitCode = code
done()
})
})
it('exit code should be 0 if passed with a valid address as argument', () => {
assert.strictEqual(exitCode, 0)
})
})

describe('receive', () => {
let args = [
'receive',
'Q010500bc576efa69fd6cbc854f2224f149f0b0a4d18fcb30c1feab64781245f4f27a61874227f4',
]
let exitCode
before(done => {
let process = spawn('./bin/run', args, processFlags)
process.on('exit', code => {
exitCode = code
done()
})
})
it('exit code should be non-0 if passed with an invalid QRL address as argument', () => {
assert.notStrictEqual(exitCode, 0)
})
})
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3003,6 +3003,11 @@ qqjs@^0.3.10:
tmp "^0.1.0"
write-json-file "^4.1.1"

qrcode-terminal@^0.12.0:
version "0.12.0"
resolved "https://registry.yarnpkg.com/qrcode-terminal/-/qrcode-terminal-0.12.0.tgz#bb5b699ef7f9f0505092a3748be4464fe71b5819"
integrity sha512-EXtzRZmC+YGmGlDFbXKxQiMZNwCLEO6BANKXG4iCtSIM0yqc/pappSx3RIKr4r0uh5JsBckOXeKrB3Iz7mdQpQ==

qrllib@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/qrllib/-/qrllib-1.0.4.tgz#06a01ef58432d7a1690579c5e0336d15e1af3572"
Expand Down

0 comments on commit e4858ba

Please sign in to comment.