diff --git a/apps/api/scripts/script.ts b/apps/api/scripts/script.ts index db419c30c..637844bd6 100644 --- a/apps/api/scripts/script.ts +++ b/apps/api/scripts/script.ts @@ -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'; @@ -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); diff --git a/apps/api/scripts/src/preview.ts b/apps/api/scripts/src/preview.ts index 5b15277d8..da40ca5e2 100644 --- a/apps/api/scripts/src/preview.ts +++ b/apps/api/scripts/src/preview.ts @@ -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'); diff --git a/apps/app/src/components/button/BaseButtonApprove.vue b/apps/app/src/components/button/BaseButtonApprove.vue index 156ffe414..6b6eb63bb 100644 --- a/apps/app/src/components/button/BaseButtonApprove.vue +++ b/apps/app/src/components/button/BaseButtonApprove.vue @@ -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({ @@ -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]; @@ -69,14 +71,16 @@ 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); @@ -84,6 +88,11 @@ export default defineComponent({ 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 }]); + }, }, }); diff --git a/apps/app/src/components/button/BaseButtonLiquidityCreate.vue b/apps/app/src/components/button/BaseButtonLiquidityCreate.vue index a86d35168..fdc3b0f46 100644 --- a/apps/app/src/components/button/BaseButtonLiquidityCreate.vue +++ b/apps/app/src/components/button/BaseButtonLiquidityCreate.vue @@ -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', @@ -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]; @@ -80,6 +82,7 @@ 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); @@ -87,6 +90,11 @@ export default defineComponent({ 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 }]); + }, }, }); diff --git a/apps/app/src/components/button/BaseButtonLiquidityLock.vue b/apps/app/src/components/button/BaseButtonLiquidityLock.vue index b3d61fbec..cec9fdd78 100644 --- a/apps/app/src/components/button/BaseButtonLiquidityLock.vue +++ b/apps/app/src/components/button/BaseButtonLiquidityLock.vue @@ -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', @@ -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]; @@ -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 }]); + }, }, }); diff --git a/apps/app/src/components/button/BaseButtonLiquidityStake.vue b/apps/app/src/components/button/BaseButtonLiquidityStake.vue index 14429d8c3..7af2af4b0 100644 --- a/apps/app/src/components/button/BaseButtonLiquidityStake.vue +++ b/apps/app/src/components/button/BaseButtonLiquidityStake.vue @@ -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', @@ -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]; @@ -55,9 +57,11 @@ 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); @@ -65,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, 'staked liquidity', { poolId, address: wallet?.address, ...data }]); + }, }, }); diff --git a/apps/app/src/components/modal/BaseModalWithdraw.vue b/apps/app/src/components/modal/BaseModalWithdraw.vue index ace34757f..f2ebaf070 100644 --- a/apps/app/src/components/modal/BaseModalWithdraw.vue +++ b/apps/app/src/components/modal/BaseModalWithdraw.vue @@ -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', @@ -66,7 +68,7 @@ export default defineComponent({ }; }, computed: { - ...mapStores(useWalletStore, useVeStore, useLiquidityStore), + ...mapStores(useWalletStore, useVeStore, useLiquidityStore, useAccountStore), isAlertInfoShown() { return !!this.error; }, @@ -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); @@ -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 }]); + }, }, }); diff --git a/libs/common/src/lib/mixpanel.ts b/libs/common/src/lib/mixpanel.ts index 82a652a86..4a74abf72 100644 --- a/libs/common/src/lib/mixpanel.ts +++ b/libs/common/src/lib/mixpanel.ts @@ -63,4 +63,4 @@ export const track = (event: string, params: any[]) => { } }; -export default { init, client, track }; +export default { init, client, track, mixpanel };