-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from jplomas/master
feat: receive command (terminal QR code)
- Loading branch information
Showing
6 changed files
with
122 additions
and
3 deletions.
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
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
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} |
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 |
---|---|---|
@@ -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) | ||
}) | ||
}) |
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