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

Commit

Permalink
Adding more events in tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
janedegtiareva committed Apr 21, 2020
1 parent 1e0a592 commit e6684af
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions commands/create-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <accountId>',
Expand Down Expand Up @@ -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);
Expand All @@ -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, {});
}
3 changes: 3 additions & 0 deletions commands/tx-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <hash>',
Expand All @@ -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(':');
Expand All @@ -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, {});
})
};
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand Down
13 changes: 11 additions & 2 deletions utils/eventtracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
};

0 comments on commit e6684af

Please sign in to comment.