Skip to content

Commit

Permalink
Adds events
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpolman committed May 30, 2024
1 parent 2d3d030 commit 22faca4
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 12 deletions.
4 changes: 2 additions & 2 deletions apps/api/scripts/script.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import db from '@thxnetwork/api/util/database';
import main from './src/veLiquidity';
// import main from './src/veLiquidity';
// import main from './src/veTransfer';
// import main from './src/veRewards';
// import main from './src/time';
Expand All @@ -10,7 +10,7 @@ import main from './src/veLiquidity';
// import main from './src/ipfs';
// import main from './src/invoices';
// import main from './src/demo';
// import main from './src/preview';
import main from './src/preview';
// import main from './src/metamask';

db.connect(process.env.MONGODB_URI_PROD);
Expand Down
2 changes: 1 addition & 1 deletion apps/api/scripts/src/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import path from 'path';
import CanvasService from '@thxnetwork/api/services/CanvasService';

// Provide before running
const poolIds = ['660f101c4a0130f6f8315762', '660f10e4e298a7a04bbb35ae'];
const poolIds = ['665642621cf2b394bcbd40f6', '6655fe16908e57b4ab3383a4'];

// Load on boot as registration on runtime results in font not being loaded in time
const fontPath = path.resolve(assetsPath, 'fa-solid-900.ttf');
Expand Down
15 changes: 12 additions & 3 deletions apps/app/src/components/button/BaseButtonApprove.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import { BigNumber } from 'ethers/lib/ethers';
import { formatUnits, parseUnits } from 'ethers/lib/utils';
import { useWalletStore } from '@thxnetwork/app/stores/Wallet';
import { useVeStore } from '@thxnetwork/app/stores/VE';
import { useAccountStore } from '@thxnetwork/app/stores/Account';
import { mapStores } from 'pinia';
import { contractNetworks } from '@thxnetwork/app/config/constants';
import { ChainId } from '@thxnetwork/common/enums';
import { track } from '@thxnetwork/common/mixpanel';
import poll from 'promise-poller';
export default defineComponent({
Expand All @@ -31,7 +33,7 @@ export default defineComponent({
};
},
computed: {
...mapStores(useVeStore, useWalletStore),
...mapStores(useVeStore, useWalletStore, useAccountStore),
address() {
if (!this.walletStore.wallet) return contractNetworks[ChainId.Polygon];
return contractNetworks[this.walletStore.wallet.chainId];
Expand Down Expand Up @@ -69,21 +71,28 @@ export default defineComponent({
try {
this.isPolling = true;
await this.walletStore.approve({
const data = {
tokenAddress: this.token.address,
spender: this.spender,
amountInWei: this.amountInWei.toString(),
});
};
await this.walletStore.approve(data);
await this.waitForApproval();
this.trackEvent(data);
this.$emit('success');
} catch (error) {
this.$emit('error', error);
} finally {
this.isPolling = false;
}
},
trackEvent(data: any) {
const { poolId, account } = this.accountStore;
const { wallet } = this.walletStore;
track('UserCreates', [account?.sub, 'allowance', { poolId, address: wallet?.address, ...data }]);
},
},
});
</script>
10 changes: 9 additions & 1 deletion apps/app/src/components/button/BaseButtonLiquidityCreate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import { ChainId } from '@thxnetwork/common/enums';
import { BalancerSDK, Network } from '@balancer-labs/sdk';
import { POLYGON_RPC } from '@thxnetwork/app/config/secrets';
import { useLiquidityStore } from '@thxnetwork/app/stores/Liquidity';
import { useAccountStore } from '@thxnetwork/app/stores/Account';
import { useVeStore } from '@thxnetwork/app/stores/VE';
import { track } from '@thxnetwork/common/mixpanel';
export default defineComponent({
name: 'BaseButtonLiquidityCreate',
Expand All @@ -31,7 +33,7 @@ export default defineComponent({
};
},
computed: {
...mapStores(useVeStore, useWalletStore, useLiquidityStore),
...mapStores(useVeStore, useWalletStore, useLiquidityStore, useAccountStore),
address() {
if (!this.walletStore.wallet) return contractNetworks[ChainId.Polygon];
return contractNetworks[this.walletStore.wallet.chainId];
Expand Down Expand Up @@ -80,13 +82,19 @@ export default defineComponent({
await this.liquidityStore.createLiquidity(wallet, data);
await this.liquidityStore.waitForLiquidity(wallet, data);
this.trackEvent(data);
this.$emit('success');
} catch (error) {
this.$emit('error', error);
} finally {
this.isPolling = false;
}
},
trackEvent(data: any) {
const { poolId, account } = this.accountStore;
const { wallet } = this.walletStore;
track('UserCreates', [account?.sub, 'liquidity', { poolId, address: wallet?.address, ...data }]);
},
},
});
</script>
9 changes: 8 additions & 1 deletion apps/app/src/components/button/BaseButtonLiquidityLock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import { BigNumber } from 'ethers/lib/ethers';
import { useWalletStore } from '@thxnetwork/app/stores/Wallet';
import { mapStores } from 'pinia';
import { useVeStore } from '@thxnetwork/app/stores/VE';
import { useAccountStore } from '@thxnetwork/app/stores/Account';
import { contractNetworks } from '../../config/constants';
import { ChainId } from '@thxnetwork/common/enums';
import { track } from '@thxnetwork/common/mixpanel';
export default defineComponent({
name: 'BaseButtonLiquidityLock',
Expand All @@ -27,7 +29,7 @@ export default defineComponent({
};
},
computed: {
...mapStores(useWalletStore, useVeStore),
...mapStores(useWalletStore, useVeStore, useAccountStore),
address() {
if (!this.walletStore.wallet) return contractNetworks[ChainId.Polygon];
return contractNetworks[this.walletStore.wallet.chainId];
Expand Down Expand Up @@ -67,6 +69,11 @@ export default defineComponent({
this.isPolling = false;
}
},
trackEvent(data: any) {
const { poolId, account } = this.accountStore;
const { wallet } = this.walletStore;
track('UserCreates', [account?.sub, 'locked liquidity', { poolId, address: wallet?.address, ...data }]);
},
},
});
</script>
13 changes: 11 additions & 2 deletions apps/app/src/components/button/BaseButtonLiquidityStake.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { ChainId } from '@thxnetwork/common/enums';
import { useWalletStore } from '@thxnetwork/app/stores/Wallet';
import { useLiquidityStore } from '@thxnetwork/app/stores/Liquidity';
import { useVeStore } from '@thxnetwork/app/stores/VE';
import { useAccountStore } from '@thxnetwork/app/stores/Account';
import { track } from '@thxnetwork/common/mixpanel';
export default defineComponent({
name: 'BaseButtonLiquidityStake',
Expand All @@ -27,7 +29,7 @@ export default defineComponent({
};
},
computed: {
...mapStores(useVeStore, useWalletStore, useLiquidityStore),
...mapStores(useVeStore, useWalletStore, useLiquidityStore, useAccountStore),
address() {
if (!this.walletStore.wallet) return contractNetworks[ChainId.Polygon];
return contractNetworks[this.walletStore.wallet.chainId];
Expand Down Expand Up @@ -55,16 +57,23 @@ export default defineComponent({
this.isPolling = true;
await this.liquidityStore.stake(wallet, { amountInWei: this.amountInWei.toString() });
const data = { amountInWei: this.amountInWei.toString() };
await this.liquidityStore.stake(wallet, data);
await this.liquidityStore.waitForStake(wallet, this.amountInWei);
this.trackEvent(data);
this.$emit('success');
} catch (error) {
this.$emit('error', error);
} finally {
this.isPolling = false;
}
},
trackEvent(data: any) {
const { poolId, account } = this.accountStore;
const { wallet } = this.walletStore;
track('UserCreates', [account?.sub, 'staked liquidity', { poolId, address: wallet?.address, ...data }]);
},
},
});
</script>
10 changes: 9 additions & 1 deletion apps/app/src/components/modal/BaseModalWithdraw.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ import { useVeStore } from '../../stores/VE';
import { useWalletStore } from '../../stores/Wallet';
import { MAX_LOCK_TIME, contractNetworks } from '../../config/constants';
import { useLiquidityStore } from '@thxnetwork/app/stores/Liquidity';
import { useAccountStore } from '@thxnetwork/app/stores/Account';
import { calculatePenalty, toFiatPrice } from '@thxnetwork/app/utils/price';
import { WalletVariant } from '@thxnetwork/app/types/enums/accountVariant';
import { track } from '@thxnetwork/common/mixpanel';
export default defineComponent({
name: 'BaseModalWithdraw',
Expand All @@ -66,7 +68,7 @@ export default defineComponent({
};
},
computed: {
...mapStores(useWalletStore, useVeStore, useLiquidityStore),
...mapStores(useWalletStore, useVeStore, useLiquidityStore, useAccountStore),
isAlertInfoShown() {
return !!this.error;
},
Expand Down Expand Up @@ -108,6 +110,7 @@ export default defineComponent({
this.walletStore.getBalance(contractNetworks[wallet.chainId].BPTGauge);
this.trackEvent({ isEarly: this.isEarly, isEarlyAttempt: this.isEarlyAttempt });
this.$emit('hidden');
} catch (response) {
this.onError(response);
Expand All @@ -118,6 +121,11 @@ export default defineComponent({
onError(response: any) {
this.error = response && response.error ? response.error.message : 'Something went wrong...';
},
trackEvent(data: any) {
const { poolId, account } = this.accountStore;
const { wallet } = this.walletStore;
track('UserCreates', [account?.sub, 'withdrawal', { poolId, address: wallet?.address, ...data }]);
},
},
});
</script>
2 changes: 1 addition & 1 deletion libs/common/src/lib/mixpanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ export const track = (event: string, params: any[]) => {
}
};

export default { init, client, track };
export default { init, client, track, mixpanel };

0 comments on commit 22faca4

Please sign in to comment.