From e2bc3c92638f6e17b85cfaaf2c611c79413bdf53 Mon Sep 17 00:00:00 2001 From: Jane Degtiareva Date: Wed, 15 Apr 2020 17:19:03 -0700 Subject: [PATCH 01/23] Initial stab at dev event tracking (E2E with mixpanel works) --- eventtracking.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ index.js | 18 +++++++++++++++--- package.json | 4 ++++ 3 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 eventtracking.js diff --git a/eventtracking.js b/eventtracking.js new file mode 100644 index 00000000..ef395b1f --- /dev/null +++ b/eventtracking.js @@ -0,0 +1,44 @@ +const MIXPANEL_TOKEN = '9aa8926fbcb03eb5d6ce787b5e8fa6eb'; +var mixpanel = require('mixpanel').init(MIXPANEL_TOKEN); +const homedir = require('os').homedir(); +const fs = require('fs'); +const path = require('path'); +const uuid = require('uuid'); + +const track = () => { + const nearPath = path.join(homedir, '.near-config'); + console.log(nearPath) + if (!fs.existsSync(nearPath)) { // TODO: make a util for .near + //create near path if it doesn't already exist + fs.mkdirSync(nearPath); + } + + const shellSettingsPath = path.join(nearPath, 'shellSettings'); + if (!fs.existsSync(shellSettingsPath)) { + //Ask if it's ok to collect feedback + console.log("We would like to collect data on near shell usage to improve developer experience. Would you like to opt in?") + } + + //TODO: unhardcode + const shellSettings = { + trackingEnabled: true, + trackingSessionId: uuid.v4() + }; + + if (shellSettings.trackingEnabled) { + mixpanel.track('test_event', { + distinct_id: shellSettings.trackingSessionId, + property_1: 'value 1', + property_2: 'value 2', + property_3: 'value 3' + }); + } + + /* */ + console.log("test done") +}; + + +track(); + +module.exports = { track }; \ No newline at end of file diff --git a/index.js b/index.js index a785ca52..b5722bb4 100644 --- a/index.js +++ b/index.js @@ -15,6 +15,9 @@ const capture = require('./utils/capture-login-success'); const inspectResponse = require('./utils/inspect-response'); +const MIXPANEL_TOKEN = '9aa8926fbcb03eb5d6ce787b5e8fa6eb'; +var mixpanel = require('mixpanel').init(MIXPANEL_TOKEN); + // TODO: Fix promisified wrappers to handle error properly // For smart contract: @@ -47,6 +50,13 @@ exports.callViewFunction = async function(options) { // For account: exports.login = async function(options) { + mixpanel.track('test_event', { + distinct_id: 'unique client id', + property_1: 'value 1', + property_2: 'value 2', + property_3: 'value 3' + }); + if (!options.walletUrl) { console.log('Log in is not needed on this environment. Please use appropriate master account for shell operations.'); } else { @@ -126,15 +136,17 @@ exports.login = async function(options) { .catch(reject); }); } - rl.close(); - capture.cancel(); - + // verify the accountId if we captured it or ... try { await verify(accountId, keyPair, options); } catch (error) { console.error('Failed to verify accountId.', error.message); } + + rl.close(); + capture.cancel(); + } }; diff --git a/package.json b/package.json index cdc57137..ae58c8f9 100644 --- a/package.json +++ b/package.json @@ -37,13 +37,17 @@ "flagged-respawn": "^1.0.1", "is-ci": "^2.0.0", "jest-environment-node": "^25.1.0", + "mixpanel": "^0.11.0", "ncp": "^2.0.0", "near-api-js": "^0.23.1", "open": "^7.0.1", + "os": "^0.1.1", + "path": "^0.12.7", "rimraf": "^3.0.0", "stoppable": "^1.1.0", "tcp-port-used": "^1.0.1", "update-notifier": "^4.0.0", + "uuid": "^7.0.3", "v8flags": "^3.1.3", "yargs": "^15.0.1" }, From d98676166f558bbd1539a6c3d9859b60cef64799 Mon Sep 17 00:00:00 2001 From: Jane Degtiareva Date: Fri, 17 Apr 2020 11:05:51 -0700 Subject: [PATCH 02/23] Clean up eventtracking util class --- eventtracking.js | 44 -------------------- package.json | 2 - utils/eventtracking.js | 94 ++++++++++++++++++++++++++++++++++++++++++ yarn.lock | 46 +++++++++++++++++++++ 4 files changed, 140 insertions(+), 46 deletions(-) delete mode 100644 eventtracking.js create mode 100644 utils/eventtracking.js diff --git a/eventtracking.js b/eventtracking.js deleted file mode 100644 index ef395b1f..00000000 --- a/eventtracking.js +++ /dev/null @@ -1,44 +0,0 @@ -const MIXPANEL_TOKEN = '9aa8926fbcb03eb5d6ce787b5e8fa6eb'; -var mixpanel = require('mixpanel').init(MIXPANEL_TOKEN); -const homedir = require('os').homedir(); -const fs = require('fs'); -const path = require('path'); -const uuid = require('uuid'); - -const track = () => { - const nearPath = path.join(homedir, '.near-config'); - console.log(nearPath) - if (!fs.existsSync(nearPath)) { // TODO: make a util for .near - //create near path if it doesn't already exist - fs.mkdirSync(nearPath); - } - - const shellSettingsPath = path.join(nearPath, 'shellSettings'); - if (!fs.existsSync(shellSettingsPath)) { - //Ask if it's ok to collect feedback - console.log("We would like to collect data on near shell usage to improve developer experience. Would you like to opt in?") - } - - //TODO: unhardcode - const shellSettings = { - trackingEnabled: true, - trackingSessionId: uuid.v4() - }; - - if (shellSettings.trackingEnabled) { - mixpanel.track('test_event', { - distinct_id: shellSettings.trackingSessionId, - property_1: 'value 1', - property_2: 'value 2', - property_3: 'value 3' - }); - } - - /* */ - console.log("test done") -}; - - -track(); - -module.exports = { track }; \ No newline at end of file diff --git a/package.json b/package.json index ae58c8f9..c73bff2a 100644 --- a/package.json +++ b/package.json @@ -41,8 +41,6 @@ "ncp": "^2.0.0", "near-api-js": "^0.23.1", "open": "^7.0.1", - "os": "^0.1.1", - "path": "^0.12.7", "rimraf": "^3.0.0", "stoppable": "^1.1.0", "tcp-port-used": "^1.0.1", diff --git a/utils/eventtracking.js b/utils/eventtracking.js new file mode 100644 index 00000000..a570b529 --- /dev/null +++ b/utils/eventtracking.js @@ -0,0 +1,94 @@ +const MIXPANEL_TOKEN = '9aa8926fbcb03eb5d6ce787b5e8fa6eb'; +var mixpanel = require('mixpanel').init(MIXPANEL_TOKEN); +const homedir = require('os').homedir(); +const fs = require('fs'); +const {promisify} = require('util'); +const path = require('path'); +const uuid = require('uuid'); +const chalk = require('chalk'); // colorize output +const readline = require('readline'); + +// TODO: pull out into separate file. Remove DBG console printouts +const getShellSettings = () => { + const nearPath = path.join(homedir, '.near-config'); + try { + if (!fs.existsSync(nearPath)) { + fs.mkdirSync(nearPath); + } + const shellSettingsPath = path.join(nearPath, 'shellSettings'); + if (!fs.existsSync(shellSettingsPath)) { + return {}; + } else { + return JSON.parse(fs.readFileSync(shellSettingsPath, 'utf8')); + } + } catch (e) { + console.log(e); + } + return {}; +} + +const saveShellSettings = (settings) => { + const nearPath = path.join(homedir, '.near-config'); + try { + if (!fs.existsSync(nearPath)) { + fs.mkdirSync(nearPath); + } + const shellSettingsPath = path.join(nearPath, 'shellSettings'); + fs.writeFileSync(shellSettingsPath, JSON.stringify(settings)); + } catch (e) { + console.log(e); + } +} + + +const track = async (eventType, eventProperties) => { + const shellSettings = getShellSettings(); + // if the appropriate option is not in settings, ask now and save settings. + if (!('trackingEnabled' in shellSettings)) { + const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout + }); + const getEventTrackingConsent = async () => { + for (var attempts = 0; attempts < 10; attempts++) { + const answer = await new Promise((resolve) => { + + rl.question( + chalk`We would like to collect data on near shell usage to improve developer experience. {bold.yellow Would you like to opt in (y/n)?}`, + async (consentToEventTracking) => { + if (consentToEventTracking == 'y' || consentToEventTracking == 'Y') { + resolve(true); + } + else if (consentToEventTracking == 'n' || consentToEventTracking == 'N') { + resolve(false); + } + resolve(undefined); + }); + }); + if (answer !== undefined) { + return answer; + } + } + return false; // If they can't figure it out in this many attempts, just opt out + }; + + shellSettings['trackingEnabled'] = await getEventTrackingConsent(); + shellSettings['trackingSessionId'] = shellSettings['trackingEnabled'] ? uuid.v4() : undefined; + rl.close(); + saveShellSettings(shellSettings); + } + + if (!shellSettings.trackingEnabled) { + return; + } + + if (shellSettings.trackingEnabled) { + const mixPanelProperties = { + distinct_id: shellSettings.trackingSessionId + }; + Object.assign(mixPanelProperties, eventProperties); + mixpanel.track(eventType, mixPanelProperties); + } +}; + +module.exports = { track }; \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index da591e25..e41d97a3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -580,6 +580,13 @@ acorn@^7.1.0, acorn@^7.1.1: resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.1.1.tgz#e35668de0b402f359de515c5482a1ab9f89a69bf" integrity sha512-add7dgA5ppRPxCFJoAGfMDi7PIBXq1RtGo7BhbLaxwrXPOmw8gq48Y9ozT01hUKy9byMjlR20EJhu5zlkErEkg== +agent-base@^4.3.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-4.3.0.tgz#8165f01c436009bccad0b1d122f05ed770efc6ee" + integrity sha512-salcGninV0nPrwpGNn4VTXBb1SOuXQBiqbrNXoeizJsHrsL6ERFM2Ne3JUSBWRE6aeNJI2ROP/WEEIDUiDe3cg== + dependencies: + es6-promisify "^5.0.0" + ajv@^6.10.0, ajv@^6.10.2, ajv@^6.5.5: version "6.12.0" resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.0.tgz#06d60b96d87b8454a5adaba86e7854da629db4b7" @@ -1215,6 +1222,13 @@ debug@^2.2.0, debug@^2.3.3: dependencies: ms "2.0.0" +debug@^3.1.0: + version "3.2.6" + resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b" + integrity sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ== + dependencies: + ms "^2.1.1" + debug@^4.0.1, debug@^4.1.0, debug@^4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791" @@ -1368,6 +1382,18 @@ error-polyfill@^0.1.2: o3 "^1.0.3" u3 "^0.1.0" +es6-promise@^4.0.3: + version "4.2.8" + resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.2.8.tgz#4eb21594c972bc40553d276e510539143db53e0a" + integrity sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w== + +es6-promisify@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/es6-promisify/-/es6-promisify-5.0.0.tgz#5109d62f3e56ea967c4b63505aef08291c8a5203" + integrity sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM= + dependencies: + es6-promise "^4.0.3" + escape-goat@^2.0.0: version "2.1.1" resolved "https://registry.yarnpkg.com/escape-goat/-/escape-goat-2.1.1.tgz#1b2dc77003676c457ec760b2dc68edb648188675" @@ -1956,6 +1982,14 @@ http-signature@~1.2.0: jsprim "^1.2.2" sshpk "^1.7.0" +https-proxy-agent@3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-3.0.0.tgz#0106efa5d63d6d6f3ab87c999fa4877a3fd1ff97" + integrity sha512-y4jAxNEihqvBI5F3SaO2rtsjIOnnNA8sEbuiP+UhJZJHeM2NRm6c09ax2tgqme+SgUUvjao2fJXF4h3D6Cb2HQ== + dependencies: + agent-base "^4.3.0" + debug "^3.1.0" + human-signals@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-1.1.1.tgz#c5b1cd14f50aeae09ab6c59fe63ba3395fe4dfa3" @@ -3011,6 +3045,13 @@ mixin-deep@^1.2.0: for-in "^1.0.2" is-extendable "^1.0.1" +mixpanel@^0.11.0: + version "0.11.0" + resolved "https://registry.yarnpkg.com/mixpanel/-/mixpanel-0.11.0.tgz#22f2351f9bef81a7da519aff55ef580e48417b52" + integrity sha512-TS7AkCmfC+vGshlCOjEcITFoFxlt5fdSEqmN+d+pTXAhE5v+jPQW2uUcn9W+Oq4NVXz+kdskU09dsm9vmNl0ig== + dependencies: + https-proxy-agent "3.0.0" + mkdirp@^0.5.1: version "0.5.5" resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.5.tgz#d91cefd62d1436ca0f41620e251288d420099def" @@ -4385,6 +4426,11 @@ uuid@^3.3.2: resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee" integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A== +uuid@^7.0.3: + version "7.0.3" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-7.0.3.tgz#c5c9f2c8cf25dc0a372c4df1441c41f5bd0c680b" + integrity sha512-DPSke0pXhTZgoF/d+WSt2QaKMCFSfx7QegxEWT+JOuHF5aWrKEn0G+ztjuJg/gG8/ItK+rbPCD/yNv8yyih6Cg== + v8-compile-cache@^2.0.3: version "2.1.0" resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.1.0.tgz#e14de37b31a6d194f5690d67efc4e7f6fc6ab30e" From b229756d503e733c5ae542e6a6e3104f09950ce1 Mon Sep 17 00:00:00 2001 From: Jane Degtiareva Date: Fri, 17 Apr 2020 11:08:20 -0700 Subject: [PATCH 03/23] Add error handling to the mixpanel calls --- utils/eventtracking.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/utils/eventtracking.js b/utils/eventtracking.js index a570b529..774c0cd9 100644 --- a/utils/eventtracking.js +++ b/utils/eventtracking.js @@ -82,13 +82,16 @@ const track = async (eventType, eventProperties) => { return; } - if (shellSettings.trackingEnabled) { + try { const mixPanelProperties = { distinct_id: shellSettings.trackingSessionId }; Object.assign(mixPanelProperties, eventProperties); mixpanel.track(eventType, mixPanelProperties); } + catch (e) { + console.log("Warning: problem while sending developer event tracking data. This is not critical. Error: ", e); + } }; module.exports = { track }; \ No newline at end of file From c799108409367e313eab10df71540d311fbdd0d8 Mon Sep 17 00:00:00 2001 From: Jane Degtiareva Date: Mon, 20 Apr 2020 17:18:44 -0700 Subject: [PATCH 04/23] Pull out settings keys into constants --- utils/eventtracking.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/utils/eventtracking.js b/utils/eventtracking.js index 774c0cd9..767146ca 100644 --- a/utils/eventtracking.js +++ b/utils/eventtracking.js @@ -8,6 +8,9 @@ const uuid = require('uuid'); const chalk = require('chalk'); // colorize output const readline = require('readline'); +const TRACKING_ENABLED_KEY = 'trackingEnaled'; +const TRACKING_SESSION_ID_KEY = 'trackingSessionId'; + // TODO: pull out into separate file. Remove DBG console printouts const getShellSettings = () => { const nearPath = path.join(homedir, '.near-config'); @@ -15,7 +18,7 @@ const getShellSettings = () => { if (!fs.existsSync(nearPath)) { fs.mkdirSync(nearPath); } - const shellSettingsPath = path.join(nearPath, 'shellSettings'); + const shellSettingsPath = path.join(nearPath, 'settings'); if (!fs.existsSync(shellSettingsPath)) { return {}; } else { @@ -33,7 +36,7 @@ const saveShellSettings = (settings) => { if (!fs.existsSync(nearPath)) { fs.mkdirSync(nearPath); } - const shellSettingsPath = path.join(nearPath, 'shellSettings'); + const shellSettingsPath = path.join(nearPath, 'settings'); fs.writeFileSync(shellSettingsPath, JSON.stringify(settings)); } catch (e) { console.log(e); @@ -44,7 +47,7 @@ const saveShellSettings = (settings) => { const track = async (eventType, eventProperties) => { const shellSettings = getShellSettings(); // if the appropriate option is not in settings, ask now and save settings. - if (!('trackingEnabled' in shellSettings)) { + if (!(TRACKING_ENABLED_KEY in shellSettings)) { const rl = readline.createInterface({ input: process.stdin, output: process.stdout @@ -72,13 +75,13 @@ const track = async (eventType, eventProperties) => { return false; // If they can't figure it out in this many attempts, just opt out }; - shellSettings['trackingEnabled'] = await getEventTrackingConsent(); - shellSettings['trackingSessionId'] = shellSettings['trackingEnabled'] ? uuid.v4() : undefined; + shellSettings[TRACKING_ENABLED_KEY] = await getEventTrackingConsent(); + shellSettings[TRACKING_SESSION_ID_KEY] = shellSettings[TRACKING_ENABLED_KEY] ? uuid.v4() : undefined; rl.close(); saveShellSettings(shellSettings); } - if (!shellSettings.trackingEnabled) { + if (!shellSettings[TRACKING_ENABLED_KEY]) { return; } @@ -94,4 +97,6 @@ const track = async (eventType, eventProperties) => { } }; +track('test_event', { p1: 'a'}) + module.exports = { track }; \ No newline at end of file From fd64c970c09a91e7195063d82928a1355d5cb20a Mon Sep 17 00:00:00 2001 From: Jane Degtiareva Date: Mon, 20 Apr 2020 17:20:40 -0700 Subject: [PATCH 05/23] Fix lint errors --- utils/eventtracking.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/utils/eventtracking.js b/utils/eventtracking.js index 767146ca..a1ab985d 100644 --- a/utils/eventtracking.js +++ b/utils/eventtracking.js @@ -2,7 +2,6 @@ const MIXPANEL_TOKEN = '9aa8926fbcb03eb5d6ce787b5e8fa6eb'; var mixpanel = require('mixpanel').init(MIXPANEL_TOKEN); const homedir = require('os').homedir(); const fs = require('fs'); -const {promisify} = require('util'); const path = require('path'); const uuid = require('uuid'); const chalk = require('chalk'); // colorize output @@ -93,10 +92,9 @@ const track = async (eventType, eventProperties) => { mixpanel.track(eventType, mixPanelProperties); } catch (e) { - console.log("Warning: problem while sending developer event tracking data. This is not critical. Error: ", e); + console.log('Warning: problem while sending developer event tracking data. This is not critical. Error: ', e); } }; -track('test_event', { p1: 'a'}) module.exports = { track }; \ No newline at end of file From 96ddf5a3c0c24b7ee19580c5288c934105f3bfe3 Mon Sep 17 00:00:00 2001 From: Jane Degtiareva Date: Mon, 20 Apr 2020 17:26:25 -0700 Subject: [PATCH 06/23] Remove extra test code from main login command. --- index.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/index.js b/index.js index b5722bb4..8daae78e 100644 --- a/index.js +++ b/index.js @@ -50,13 +50,6 @@ exports.callViewFunction = async function(options) { // For account: exports.login = async function(options) { - mixpanel.track('test_event', { - distinct_id: 'unique client id', - property_1: 'value 1', - property_2: 'value 2', - property_3: 'value 3' - }); - if (!options.walletUrl) { console.log('Log in is not needed on this environment. Please use appropriate master account for shell operations.'); } else { From 1025c64c9cb186c1988901af61612770ed8641fd Mon Sep 17 00:00:00 2001 From: Jane Degtiareva Date: Mon, 20 Apr 2020 17:59:46 -0700 Subject: [PATCH 07/23] Add example of tracking usage in viewState --- index.js | 14 +++++--------- utils/eventtracking.js | 14 +++++++++++--- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 8daae78e..ecdbfcff 100644 --- a/index.js +++ b/index.js @@ -14,9 +14,7 @@ const verify = require('./utils/verify-account'); const capture = require('./utils/capture-login-success'); const inspectResponse = require('./utils/inspect-response'); - -const MIXPANEL_TOKEN = '9aa8926fbcb03eb5d6ce787b5e8fa6eb'; -var mixpanel = require('mixpanel').init(MIXPANEL_TOKEN); +const eventtracking = require('./utils/eventtracking'); // TODO: Fix promisified wrappers to handle error properly @@ -103,7 +101,6 @@ exports.login = async function(options) { input: process.stdin, output: process.stdout }); - const getAccountFromConsole = async () => { return await new Promise((resolve) => { rl.question( @@ -114,6 +111,8 @@ exports.login = async function(options) { }); }); }; + rl.close(); + capture.cancel(); let accountId; if (!tempUrl) { @@ -136,11 +135,7 @@ exports.login = async function(options) { } catch (error) { console.error('Failed to verify accountId.', error.message); } - - rl.close(); - capture.cancel(); - - } + } }; exports.viewAccount = async function(options) { @@ -152,6 +147,7 @@ exports.viewAccount = async function(options) { } console.log(`Account ${options.accountId}`); console.log(inspectResponse(state)); + await eventtracking.track(eventtracking.EVENT_ID_ACCOUNT_STATE, { 'accountId' : options.accountId }); }; exports.deleteAccount = async function(options) { diff --git a/utils/eventtracking.js b/utils/eventtracking.js index a1ab985d..87a90946 100644 --- a/utils/eventtracking.js +++ b/utils/eventtracking.js @@ -25,7 +25,7 @@ const getShellSettings = () => { } } catch (e) { console.log(e); - } + }; return {}; } @@ -39,7 +39,7 @@ const saveShellSettings = (settings) => { fs.writeFileSync(shellSettingsPath, JSON.stringify(settings)); } catch (e) { console.log(e); - } + }; } @@ -96,5 +96,13 @@ const track = async (eventType, eventProperties) => { } }; +module.exports = { + track, -module.exports = { track }; \ No newline at end of file + // Event ids used in mixpanel. Note that we want to mention shell to make it very easy to tell that an event came from shell, + // since mixpanel might be used for other components as well. + EVENT_ID_ACCOUNT_STATE: 'shell_account_state', + EVENT_ID_LOGIN: 'shell_login', + EVENT_ID_DEPLOY: 'shell_deploy', + EVENT_ID_DEV_DEPLOY: 'shell_dev_deploy' +}; \ No newline at end of file From fc93a27c1ef81e2fa4b255751a7e055eadf1e078 Mon Sep 17 00:00:00 2001 From: Jane Degtiareva Date: Mon, 20 Apr 2020 18:03:56 -0700 Subject: [PATCH 08/23] Undo accidental change in login --- index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index ecdbfcff..87c12284 100644 --- a/index.js +++ b/index.js @@ -111,8 +111,6 @@ exports.login = async function(options) { }); }); }; - rl.close(); - capture.cancel(); let accountId; if (!tempUrl) { @@ -128,14 +126,15 @@ exports.login = async function(options) { .catch(reject); }); } - + rl.close(); + capture.cancel(); // verify the accountId if we captured it or ... try { await verify(accountId, keyPair, options); } catch (error) { console.error('Failed to verify accountId.', error.message); } - } + } }; exports.viewAccount = async function(options) { From 83b5c5167e0b394c47a39b4ca44f61306cce4724 Mon Sep 17 00:00:00 2001 From: Jane Degtiareva Date: Mon, 20 Apr 2020 22:04:01 -0700 Subject: [PATCH 09/23] Fix lint errors --- utils/eventtracking.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/utils/eventtracking.js b/utils/eventtracking.js index 87a90946..f9e54d9a 100644 --- a/utils/eventtracking.js +++ b/utils/eventtracking.js @@ -25,9 +25,9 @@ const getShellSettings = () => { } } catch (e) { console.log(e); - }; + } return {}; -} +}; const saveShellSettings = (settings) => { const nearPath = path.join(homedir, '.near-config'); @@ -39,8 +39,8 @@ const saveShellSettings = (settings) => { fs.writeFileSync(shellSettingsPath, JSON.stringify(settings)); } catch (e) { console.log(e); - }; -} + } +}; const track = async (eventType, eventProperties) => { From 62b82888d4c206149b0dbb3b3f418ca4a4149ec7 Mon Sep 17 00:00:00 2001 From: Jane Degtiareva Date: Tue, 21 Apr 2020 13:31:24 -0700 Subject: [PATCH 10/23] Pull out saving settings into a separate util --- utils/eventtracking.js | 42 ++++-------------------------------------- utils/settings.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 38 deletions(-) create mode 100644 utils/settings.js diff --git a/utils/eventtracking.js b/utils/eventtracking.js index f9e54d9a..626512df 100644 --- a/utils/eventtracking.js +++ b/utils/eventtracking.js @@ -1,50 +1,16 @@ const MIXPANEL_TOKEN = '9aa8926fbcb03eb5d6ce787b5e8fa6eb'; var mixpanel = require('mixpanel').init(MIXPANEL_TOKEN); -const homedir = require('os').homedir(); -const fs = require('fs'); -const path = require('path'); + const uuid = require('uuid'); const chalk = require('chalk'); // colorize output const readline = require('readline'); +const settings = require('./settings'); const TRACKING_ENABLED_KEY = 'trackingEnaled'; const TRACKING_SESSION_ID_KEY = 'trackingSessionId'; -// TODO: pull out into separate file. Remove DBG console printouts -const getShellSettings = () => { - const nearPath = path.join(homedir, '.near-config'); - try { - if (!fs.existsSync(nearPath)) { - fs.mkdirSync(nearPath); - } - const shellSettingsPath = path.join(nearPath, 'settings'); - if (!fs.existsSync(shellSettingsPath)) { - return {}; - } else { - return JSON.parse(fs.readFileSync(shellSettingsPath, 'utf8')); - } - } catch (e) { - console.log(e); - } - return {}; -}; - -const saveShellSettings = (settings) => { - const nearPath = path.join(homedir, '.near-config'); - try { - if (!fs.existsSync(nearPath)) { - fs.mkdirSync(nearPath); - } - const shellSettingsPath = path.join(nearPath, 'settings'); - fs.writeFileSync(shellSettingsPath, JSON.stringify(settings)); - } catch (e) { - console.log(e); - } -}; - - const track = async (eventType, eventProperties) => { - const shellSettings = getShellSettings(); + const shellSettings = settings.getShellSettings(); // if the appropriate option is not in settings, ask now and save settings. if (!(TRACKING_ENABLED_KEY in shellSettings)) { const rl = readline.createInterface({ @@ -77,7 +43,7 @@ const track = async (eventType, eventProperties) => { shellSettings[TRACKING_ENABLED_KEY] = await getEventTrackingConsent(); shellSettings[TRACKING_SESSION_ID_KEY] = shellSettings[TRACKING_ENABLED_KEY] ? uuid.v4() : undefined; rl.close(); - saveShellSettings(shellSettings); + settings.saveShellSettings(shellSettings); } if (!shellSettings[TRACKING_ENABLED_KEY]) { diff --git a/utils/settings.js b/utils/settings.js new file mode 100644 index 00000000..2668e623 --- /dev/null +++ b/utils/settings.js @@ -0,0 +1,42 @@ +const fs = require('fs'); +const homedir = require('os').homedir(); +const path = require('path'); + + +// Persistent shell settings + +const getShellSettings = () => { + const nearPath = path.join(homedir, '.near-config'); + try { + if (!fs.existsSync(nearPath)) { + fs.mkdirSync(nearPath); + } + const shellSettingsPath = path.join(nearPath, 'settings'); + if (!fs.existsSync(shellSettingsPath)) { + return {}; + } else { + return JSON.parse(fs.readFileSync(shellSettingsPath, 'utf8')); + } + } catch (e) { + console.log(e); + } + return {}; +}; + +const saveShellSettings = (settings) => { + const nearPath = path.join(homedir, '.near-config'); + try { + if (!fs.existsSync(nearPath)) { + fs.mkdirSync(nearPath); + } + const shellSettingsPath = path.join(nearPath, 'settings'); + fs.writeFileSync(shellSettingsPath, JSON.stringify(settings)); + } catch (e) { + console.log(e); + } +}; + +module.exports = { + getShellSettings, + saveShellSettings +}; \ No newline at end of file From e306f5cb757c8efa4719490e5ebd4a60cea06d93 Mon Sep 17 00:00:00 2001 From: Jane Degtiareva Date: Tue, 21 Apr 2020 13:48:25 -0700 Subject: [PATCH 11/23] Add test settings file to init with on ci --- test/index.sh | 2 ++ test/testsettings | 1 + 2 files changed, 3 insertions(+) create mode 100644 test/testsettings diff --git a/test/index.sh b/test/index.sh index 3b524965..09f2478f 100755 --- a/test/index.sh +++ b/test/index.sh @@ -1,5 +1,7 @@ #!/bin/bash OVERALL_RESULT=0 +mdkir ~/.near-config +cp ./test/testsettings ~/.near-config/settings for test in ./test/test_*; do echo "" echo "Running $test" diff --git a/test/testsettings b/test/testsettings new file mode 100644 index 00000000..5684644c --- /dev/null +++ b/test/testsettings @@ -0,0 +1 @@ +{"trackingEnaled":false} \ No newline at end of file From eec706506699e52c612c78ffb49eb1c505e7347f Mon Sep 17 00:00:00 2001 From: Jane Degtiareva Date: Tue, 21 Apr 2020 13:50:04 -0700 Subject: [PATCH 12/23] Remove accountId from view state tracking (PII) --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 87c12284..c277b983 100644 --- a/index.js +++ b/index.js @@ -146,7 +146,7 @@ exports.viewAccount = async function(options) { } console.log(`Account ${options.accountId}`); console.log(inspectResponse(state)); - await eventtracking.track(eventtracking.EVENT_ID_ACCOUNT_STATE, { 'accountId' : options.accountId }); + await eventtracking.track(eventtracking.EVENT_ID_ACCOUNT_STATE, {}); }; exports.deleteAccount = async function(options) { From 1e0a592edf2e242fdb013048a64566fa2e763214 Mon Sep 17 00:00:00 2001 From: Jane Degtiareva Date: Tue, 21 Apr 2020 14:21:18 -0700 Subject: [PATCH 13/23] Fix typo in test settings setup --- test/index.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/index.sh b/test/index.sh index 09f2478f..1a59bf74 100755 --- a/test/index.sh +++ b/test/index.sh @@ -1,6 +1,6 @@ #!/bin/bash OVERALL_RESULT=0 -mdkir ~/.near-config +mkdir ~/.near-config cp ./test/testsettings ~/.near-config/settings for test in ./test/test_*; do echo "" From e6684afbaec9bd2c59ff2345a00424551072f438 Mon Sep 17 00:00:00 2001 From: Jane Degtiareva Date: Tue, 21 Apr 2020 16:56:14 -0700 Subject: [PATCH 14/23] Adding more events in tracking --- commands/create-account.js | 4 ++++ commands/tx-status.js | 3 +++ index.js | 7 ++++++- utils/eventtracking.js | 13 +++++++++++-- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/commands/create-account.js b/commands/create-account.js index 1dc7aea9..8b59b14c 100644 --- a/commands/create-account.js +++ b/commands/create-account.js @@ -2,6 +2,7 @@ const exitOnError = require('../utils/exit-on-error'); const connect = require('../utils/connect'); const { KeyPair, utils } = require('near-api-js'); +const eventtracking = require('../utils/eventtracking'); module.exports = { command: 'create_account ', @@ -31,6 +32,8 @@ module.exports = { }; async function createAccount(options) { + await eventtracking.track(eventtracking.EVENT_ID_CREATE_ACCOUNT_START, {}); + console.log("?") options.initialBalance = utils.format.parseNearAmount(options.initialBalance); // NOTE: initialBalance is passed as part of config here let near = await connect(options); @@ -47,4 +50,5 @@ async function createAccount(options) { await near.connection.signer.keyStore.setKey(options.networkId, options.accountId, keyPair); } console.log(`Account ${options.accountId} for network "${options.networkId}" was created.`); + await eventtracking.track(eventtracking.EVENT_ID_CREATE_ACCOUNT_SUCCESS, {}); } diff --git a/commands/tx-status.js b/commands/tx-status.js index f36730c5..49eae5fa 100644 --- a/commands/tx-status.js +++ b/commands/tx-status.js @@ -2,6 +2,7 @@ const exitOnError = require('../utils/exit-on-error'); const connect = require('../utils/connect'); const inspectResponse = require('../utils/inspect-response'); const bs58 = require('bs58'); +const eventtracking = require('../utils/eventtracking'); module.exports = { command: 'tx-status ', @@ -13,6 +14,7 @@ module.exports = { required: true }), handler: exitOnError(async (argv) => { + await eventtracking.track(eventtracking.EVENT_ID_TX_STATUS_START, {}); const near = await connect(argv); const hashParts = argv.hash.split(':'); @@ -33,5 +35,6 @@ module.exports = { const status = await near.connection.provider.txStatus(bs58.decode(hash), accountId); console.log(`Transaction ${accountId}:${hash}`); console.log(inspectResponse(status)); + await eventtracking.track(eventtracking.EVENT_ID_TX_STATUS_SUCCESS, {}); }) }; diff --git a/index.js b/index.js index c277b983..4779925d 100644 --- a/index.js +++ b/index.js @@ -138,6 +138,7 @@ exports.login = async function(options) { }; exports.viewAccount = async function(options) { + await eventtracking.track(eventtracking.EVENT_ID_ACCOUNT_STATE_START, {}); let near = await connect(options); let account = await near.account(options.accountId); let state = await account.state(); @@ -146,24 +147,28 @@ exports.viewAccount = async function(options) { } console.log(`Account ${options.accountId}`); console.log(inspectResponse(state)); - await eventtracking.track(eventtracking.EVENT_ID_ACCOUNT_STATE, {}); + await eventtracking.track(eventtracking.EVENT_ID_ACCOUNT_STATE_SUCCESS, {}); }; exports.deleteAccount = async function(options) { + await eventtracking.track(eventtracking.EVENT_ID_DELETE_ACCOUNT_START, {}); console.log( `Deleting account. Account id: ${options.accountId}, node: ${options.nodeUrl}, helper: ${options.helperUrl}, beneficiary: ${options.beneficiaryId}`); const near = await connect(options); const account = await near.account(options.accountId); await account.deleteAccount(options.beneficiaryId); console.log(`Account ${options.accountId} for network "${options.networkId}" was deleted.`); + await eventtracking.track(eventtracking.EVENT_ID_DELETE_ACCOUNT_SUCCESS, {}); }; exports.keys = async function(options) { + await eventtracking.track(eventtracking.EVENT_ID_ACCOUNT_KEYS_START, {}); let near = await connect(options); let account = await near.account(options.accountId); let accessKeys = await account.getAccessKeys(); console.log(`Keys for account ${options.accountId}`); console.log(inspectResponse(accessKeys)); + await eventtracking.track(eventtracking.EVENT_ID_ACCOUNT_KEYS_SUCCESS, {}); }; exports.sendMoney = async function(options) { diff --git a/utils/eventtracking.js b/utils/eventtracking.js index 626512df..70198504 100644 --- a/utils/eventtracking.js +++ b/utils/eventtracking.js @@ -67,8 +67,17 @@ module.exports = { // Event ids used in mixpanel. Note that we want to mention shell to make it very easy to tell that an event came from shell, // since mixpanel might be used for other components as well. - EVENT_ID_ACCOUNT_STATE: 'shell_account_state', + EVENT_ID_ACCOUNT_STATE_START: 'shell_account_state_start', + EVENT_ID_ACCOUNT_STATE_SUCCESS: 'shell_account_state_success', + EVENT_ID_DELETE_ACCOUNT_START: 'shell_delete_account_start', + EVENT_ID_DELETE_ACCOUNT_SUCCESS: 'shell_delete_account_success', + EVENT_ID_ACCOUNT_KEYS_START: 'shell_account_keys_start', + EVENT_ID_ACCOUNT_KEYS_SUCCESS: 'shell_account_keys_success', + EVENT_ID_TX_STATUS_START: 'shell_tx_status_start', + EVENT_ID_TX_STATUS_SUCCESS: 'shell_tx_status_success', EVENT_ID_LOGIN: 'shell_login', EVENT_ID_DEPLOY: 'shell_deploy', - EVENT_ID_DEV_DEPLOY: 'shell_dev_deploy' + EVENT_ID_DEV_DEPLOY: 'shell_dev_deploy', + EVENT_ID_CREATE_ACCOUNT_START: 'shell_create_account_start', + EVENT_ID_CREATE_ACCOUNT_SUCCESS: 'shell_create_account_success' }; \ No newline at end of file From 1f79bbdf61b2acfd7cec60b22c479872e27a9be9 Mon Sep 17 00:00:00 2001 From: Jane Degtiareva Date: Wed, 22 Apr 2020 16:00:03 -0700 Subject: [PATCH 15/23] Address code review comments --- commands/create-account.js | 1 - test/index.sh | 2 +- utils/eventtracking.js | 4 ++-- utils/settings.js | 10 ++++++---- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/commands/create-account.js b/commands/create-account.js index 8b59b14c..3678ddc3 100644 --- a/commands/create-account.js +++ b/commands/create-account.js @@ -33,7 +33,6 @@ module.exports = { async function createAccount(options) { await eventtracking.track(eventtracking.EVENT_ID_CREATE_ACCOUNT_START, {}); - console.log("?") options.initialBalance = utils.format.parseNearAmount(options.initialBalance); // NOTE: initialBalance is passed as part of config here let near = await connect(options); diff --git a/test/index.sh b/test/index.sh index 1a59bf74..7434aaa5 100755 --- a/test/index.sh +++ b/test/index.sh @@ -1,7 +1,7 @@ #!/bin/bash OVERALL_RESULT=0 mkdir ~/.near-config -cp ./test/testsettings ~/.near-config/settings +cp ./test/testsettings ~/.near-config/settings.json for test in ./test/test_*; do echo "" echo "Running $test" diff --git a/utils/eventtracking.js b/utils/eventtracking.js index 70198504..e5a86c38 100644 --- a/utils/eventtracking.js +++ b/utils/eventtracking.js @@ -6,7 +6,7 @@ const chalk = require('chalk'); // colorize output const readline = require('readline'); const settings = require('./settings'); -const TRACKING_ENABLED_KEY = 'trackingEnaled'; +const TRACKING_ENABLED_KEY = 'trackingEnabled'; const TRACKING_SESSION_ID_KEY = 'trackingSessionId'; const track = async (eventType, eventProperties) => { @@ -52,7 +52,7 @@ const track = async (eventType, eventProperties) => { try { const mixPanelProperties = { - distinct_id: shellSettings.trackingSessionId + distinct_id: shellSettings[TRACKING_SESSION_ID_KEY] }; Object.assign(mixPanelProperties, eventProperties); mixpanel.track(eventType, mixPanelProperties); diff --git a/utils/settings.js b/utils/settings.js index 2668e623..0189c033 100644 --- a/utils/settings.js +++ b/utils/settings.js @@ -4,14 +4,16 @@ const path = require('path'); // Persistent shell settings +const SETTINGS_FILE_NAME = 'settings.json'; +const SETTINGS_DIR = '.near-config'; const getShellSettings = () => { - const nearPath = path.join(homedir, '.near-config'); + const nearPath = path.join(homedir, SETTINGS_DIR); try { if (!fs.existsSync(nearPath)) { fs.mkdirSync(nearPath); } - const shellSettingsPath = path.join(nearPath, 'settings'); + const shellSettingsPath = path.join(nearPath, SETTINGS_FILE_NAME); if (!fs.existsSync(shellSettingsPath)) { return {}; } else { @@ -24,12 +26,12 @@ const getShellSettings = () => { }; const saveShellSettings = (settings) => { - const nearPath = path.join(homedir, '.near-config'); + const nearPath = path.join(homedir, SETTINGS_DIR); try { if (!fs.existsSync(nearPath)) { fs.mkdirSync(nearPath); } - const shellSettingsPath = path.join(nearPath, 'settings'); + const shellSettingsPath = path.join(nearPath, SETTINGS_FILE_NAME); fs.writeFileSync(shellSettingsPath, JSON.stringify(settings)); } catch (e) { console.log(e); From f99491dc2c4f80931dd7be040b3784718f4b17c6 Mon Sep 17 00:00:00 2001 From: Jane Degtiareva Date: Wed, 22 Apr 2020 16:13:22 -0700 Subject: [PATCH 16/23] Generate test settings file on the fly from test script This is instead of having a file in the repository --- test/index.sh | 1 + test/testsettings | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 test/testsettings diff --git a/test/index.sh b/test/index.sh index 7434aaa5..87ba5860 100755 --- a/test/index.sh +++ b/test/index.sh @@ -1,6 +1,7 @@ #!/bin/bash OVERALL_RESULT=0 mkdir ~/.near-config +echo '{"trackingEnaled":false}' > ~/.near-config/settings.json cp ./test/testsettings ~/.near-config/settings.json for test in ./test/test_*; do echo "" diff --git a/test/testsettings b/test/testsettings deleted file mode 100644 index 5684644c..00000000 --- a/test/testsettings +++ /dev/null @@ -1 +0,0 @@ -{"trackingEnaled":false} \ No newline at end of file From 2a80c731b207b148eb2b2b841a312a787bdf33ce Mon Sep 17 00:00:00 2001 From: Jane Degtiareva Date: Wed, 22 Apr 2020 16:23:11 -0700 Subject: [PATCH 17/23] Remove copying testsettings step from the test script --- test/index.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/test/index.sh b/test/index.sh index 87ba5860..cf809397 100755 --- a/test/index.sh +++ b/test/index.sh @@ -2,7 +2,6 @@ OVERALL_RESULT=0 mkdir ~/.near-config echo '{"trackingEnaled":false}' > ~/.near-config/settings.json -cp ./test/testsettings ~/.near-config/settings.json for test in ./test/test_*; do echo "" echo "Running $test" From 9ae4d968960f5af74e8f4055de709267901c1b6b Mon Sep 17 00:00:00 2001 From: Jane Degtiareva Date: Thu, 23 Apr 2020 12:18:53 -0700 Subject: [PATCH 18/23] Update text for dev event tracking opt-in question --- utils/eventtracking.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utils/eventtracking.js b/utils/eventtracking.js index e5a86c38..98ce3fa3 100644 --- a/utils/eventtracking.js +++ b/utils/eventtracking.js @@ -22,7 +22,9 @@ const track = async (eventType, eventProperties) => { const answer = await new Promise((resolve) => { rl.question( - chalk`We would like to collect data on near shell usage to improve developer experience. {bold.yellow Would you like to opt in (y/n)?}`, + chalk`We would like to collect data on near-shell usage to improve developer experience.` + + chalk ` We will never send private information. We only collect which commands are run via an anonymous identifier.` + + chalk`{bold.yellow Would you like to opt in (y/n)?}`, async (consentToEventTracking) => { if (consentToEventTracking == 'y' || consentToEventTracking == 'Y') { resolve(true); From 80ff9d2205db86b5d9414a3a5ab6964dd74ee88a Mon Sep 17 00:00:00 2001 From: Jane Degtiareva Date: Thu, 23 Apr 2020 12:28:43 -0700 Subject: [PATCH 19/23] Merge conflict cleanup --- commands/create-account.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/commands/create-account.js b/commands/create-account.js index 52157eb8..488ddde6 100644 --- a/commands/create-account.js +++ b/commands/create-account.js @@ -32,13 +32,9 @@ module.exports = { }; async function createAccount(options) { -<<<<<<< HEAD await eventtracking.track(eventtracking.EVENT_ID_CREATE_ACCOUNT_START, {}); options.initialBalance = utils.format.parseNearAmount(options.initialBalance); - // NOTE: initialBalance is passed as part of config here -======= // NOTE: initialBalance is passed as part of config here, parsed in middleware/initial-balance ->>>>>>> master let near = await connect(options); let keyPair; let publicKey; From ad77f3cef2a8f2e31703d6cb75a3fcfea8322baa Mon Sep 17 00:00:00 2001 From: Jane Degtiareva Date: Thu, 23 Apr 2020 12:35:38 -0700 Subject: [PATCH 20/23] Fix typo in settings key in generated test settings file --- test/index.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/index.sh b/test/index.sh index 160ef3a5..0586909f 100755 --- a/test/index.sh +++ b/test/index.sh @@ -2,7 +2,7 @@ export NODE_ENV=${NODE_ENV:-test} OVERALL_RESULT=0 mkdir ~/.near-config -echo '{"trackingEnaled":false}' > ~/.near-config/settings.json +echo '{"trackingEnabled":false}' > ~/.near-config/settings.json for test in ./test/test_*; do echo "" echo "Running $test" From ab9a4b77481b1a0dcf953437f098e931998b5570 Mon Sep 17 00:00:00 2001 From: Jane Degtiareva Date: Thu, 23 Apr 2020 14:29:40 -0700 Subject: [PATCH 21/23] Remove tracking from create account temporarily --- commands/create-account.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/commands/create-account.js b/commands/create-account.js index 488ddde6..7ab35258 100644 --- a/commands/create-account.js +++ b/commands/create-account.js @@ -32,7 +32,6 @@ module.exports = { }; async function createAccount(options) { - await eventtracking.track(eventtracking.EVENT_ID_CREATE_ACCOUNT_START, {}); options.initialBalance = utils.format.parseNearAmount(options.initialBalance); // NOTE: initialBalance is passed as part of config here, parsed in middleware/initial-balance let near = await connect(options); @@ -49,5 +48,4 @@ async function createAccount(options) { await near.connection.signer.keyStore.setKey(options.networkId, options.accountId, keyPair); } console.log(`Account ${options.accountId} for network "${options.networkId}" was created.`); - await eventtracking.track(eventtracking.EVENT_ID_CREATE_ACCOUNT_SUCCESS, {}); } From cc93a4ebdd5443f5293d6f6815c29b3c8ac27ae6 Mon Sep 17 00:00:00 2001 From: Jane Degtiareva Date: Thu, 23 Apr 2020 14:37:34 -0700 Subject: [PATCH 22/23] Fix merge error and readd event tracking to create account --- commands/create-account.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/commands/create-account.js b/commands/create-account.js index 7ab35258..18ea5546 100644 --- a/commands/create-account.js +++ b/commands/create-account.js @@ -32,7 +32,7 @@ module.exports = { }; async function createAccount(options) { - options.initialBalance = utils.format.parseNearAmount(options.initialBalance); + await eventtracking.track(eventtracking.EVENT_ID_CREATE_ACCOUNT_START, {}); // NOTE: initialBalance is passed as part of config here, parsed in middleware/initial-balance let near = await connect(options); let keyPair; @@ -48,4 +48,5 @@ async function createAccount(options) { await near.connection.signer.keyStore.setKey(options.networkId, options.accountId, keyPair); } console.log(`Account ${options.accountId} for network "${options.networkId}" was created.`); + await eventtracking.track(eventtracking.EVENT_ID_CREATE_ACCOUNT_SUCCESS, {}); } From 80caf92ab44e4223a978cbf9393122cfd4b8760e Mon Sep 17 00:00:00 2001 From: Jane Degtiareva Date: Thu, 23 Apr 2020 14:53:41 -0700 Subject: [PATCH 23/23] Remove unused import (lint) --- commands/create-account.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/create-account.js b/commands/create-account.js index 18ea5546..839e9526 100644 --- a/commands/create-account.js +++ b/commands/create-account.js @@ -1,7 +1,7 @@ const exitOnError = require('../utils/exit-on-error'); const connect = require('../utils/connect'); -const { KeyPair, utils } = require('near-api-js'); +const { KeyPair } = require('near-api-js'); const eventtracking = require('../utils/eventtracking'); module.exports = {