Skip to content

Commit

Permalink
set up property
Browse files Browse the repository at this point in the history
  • Loading branch information
icerove committed Oct 9, 2020
1 parent 789877c commit 9fcc9cb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ exports.deploy = async function (options) {

const near = await connect(options);
const account = await near.account(options.accountId);
let prevState = await account.state();
let prevCodeHash = prevState.code_hash;
// Deploy with init function and args
const txs = [transactions.deployContract(fs.readFileSync(options.wasmFile))];

if (options.initFunction) {
if (!options.initArgs) {
console.error('Must add initialization arguments.\nExample: near deploy --accountId near.testnet --initFunction "new" --initArgs \'{"key": "value"}\'');
await eventtracking.track(eventtracking.EVENT_ID_DEPLOY_END, { success: false }, options);
process.exit(1);
}
txs.push(transactions.functionCall(
Expand All @@ -54,6 +57,10 @@ exports.deploy = async function (options) {

const result = await account.signAndSendTransaction(options.accountId, txs);
inspectResponse.prettyPrintResponse(result, options);
let state = await account.state();
let codeHash = state.code_hash;
await eventtracking.track(eventtracking.EVENT_ID_DEPLOY_END, { success: true, code_hash: codeHash, is_same_contract: prevCodeHash === codeHash, contract_id: options.accountId }, options);
eventtracking.trackDeployedContract();
console.log(`Done deploying ${options.initFunction ? 'and initializing' : 'to'} ${options.accountId}`);
};

Expand Down
27 changes: 16 additions & 11 deletions utils/eventtracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,17 @@ const track = async (eventType, eventProperties, options) => {
node_url: options.nodeUrl,
wallet_url: options.walletUrl,
is_gitpod: isGitPod(),
timestamp: new Date()
};
Object.assign(mixPanelProperties, eventProperties);
await mixpanel.track(eventType, mixPanelProperties);
await Promise.all([mixpanel.track(eventType, mixPanelProperties),
mixpanel.people.set_once({
distinct_id: isGitPod()
? getGitPodUserHash()
: shellSettings[TRACKING_SESSION_ID_KEY],
network_id: options.networkId,
node_url: options.nodeUrl,
})]);
} catch (e) {
console.log(
'Warning: problem while sending developer event tracking data. This is not critical. Error: ',
Expand Down Expand Up @@ -114,27 +122,24 @@ const askForConsentIfNeeded = async (options) => {
: undefined;
settings.saveShellSettings(shellSettings);
if (shellSettings[TRACKING_ENABLED_KEY]) {
await Promise.all([
track(module.exports.EVENT_ID_TRACKING_OPT_IN, {}, options),
mixpanel.people.set({
distinct_id: isGitPod()
? getGitPodUserHash()
: shellSettings[TRACKING_SESSION_ID_KEY],
network_id: options.networkId,
node_url: options.nodeUrl,
}),
]);
await track(module.exports.EVENT_ID_TRACKING_OPT_IN, {}, options);
}
}
};

const trackDeployedContract = async () => {
await mixpanel.people.increment({deployed_contracts: 1});
};

module.exports = {
track,
askForConsentIfNeeded,
trackDeployedContract,
// Some of the event ids are auto-generated runtime with the naming convention event_id_shell_{command}_start

EVENT_ID_CREATE_ACCOUNT_END: 'event_id_shell_create-account_end',
EVENT_ID_TRACKING_OPT_IN: 'event_id_tracking_opt_in',
EVENT_ID_LOGIN_END: 'event_id_shell_login_end',
EVENT_ID_DEPLOY_END: 'event_id_shell_deploy_end',
EVENT_ID_ERROR: 'event_id_shell_error',
};

0 comments on commit 9fcc9cb

Please sign in to comment.