Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Login with wallet though shell: command format #61

Merged
merged 5 commits into from
Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions bin/near
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ const createAccount = {
handler: (argv) => exitOnError(main.createAccount(argv))
};

const login = {
command: 'login',
desc: 'create a developer account',
builder: (yargs) => yargs,
handler: (argv) => exitOnError(main.login(argv))
};

const viewAccount = {
command: 'state <accountId>',
desc: 'view account',
Expand Down Expand Up @@ -166,10 +173,6 @@ yargs // eslint-disable-line
type: 'string',
default: `${process.env.HOME}/.near`,
})
.option('useDevAccount', {
desc: 'Forces use of special "developer" account (only works on local node)',
type: 'boolean',
})
.option('accountId', {
desc: 'Unique identifier for the account',
type: 'string',
Expand All @@ -185,6 +188,7 @@ yargs // eslint-disable-line
.command(clean)
.command(newProject)
.command(stake)
.command(login)
.config(config)
.alias({
'accountId': ['account_id'],
Expand Down
2 changes: 1 addition & 1 deletion blank_project/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
networkId: 'default',
nodeUrl: 'http://34.94.13.241:3030',
contractName: CONTRACT_NAME,
masterAccount: 'test.near',
walletUrl: 'https://wallet.nearprotocol.com',
};
case 'local':
return {
Expand Down
25 changes: 25 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const fs = require('fs');
const yargs = require('yargs');
const ncp = require('ncp').ncp;
const rimraf = require('rimraf');
const readline = require('readline')

ncp.limit = 16;

Expand Down Expand Up @@ -105,3 +106,27 @@ exports.stake = async function(options) {
const result = await account.stake(options.publicKey, BigInt(options.amount));
console.log('Result: ', JSON.stringify(result));
}

exports.login = async function(options) {
if (!options.walletUrl) {
console.log("Log in is not needed on this environment. Please use appropriate master account for shell operations.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is hard to understand for outsider. Probably makes sense to link to docs on how to run local setup.

} else {
const newUrl = new URL(options.walletUrl + "/login/");
const title = 'NEAR Shell';
newUrl.searchParams.set('title', title);
const keyPair = await KeyPair.fromRandom('ed25519');
newUrl.searchParams.set('public_key', keyPair.getPublicKey());
console.log(`Please navigate to this url and follow the insturctions to log in: ${newUrl.toString()}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/insturctions/instructions/

probably good idea to put newline before URL to make it easier to copy if not clickable in given terminal


const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

rl.question('Please enter the accountId that you logged in with:', (accountId) => {
const keyStore = new UnencryptedFileSystemKeyStore('./neardev');
keyStore.setKey(options.networkId, accountId, keyPair);
console.log(`Logged in with ${accountId}`);
});
}
}