Skip to content

Commit

Permalink
Add wallet type stats to redis and GA
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterBenc committed Nov 12, 2020
1 parent 2f38e35 commit 70a6408
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/frontend/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export default ({setState, getState}: {setState: SetStateFn; getState: GetStateF
const walletInfo = await wallet.getWalletInfo()
const conversionRatesPromise = getConversionRates(state)
const usingHwWallet = wallet.isHwWallet()
const hwWalletName = usingHwWallet ? wallet.getHwWalletName() : undefined
const hwWalletName = usingHwWallet ? wallet.getWalletName() : undefined
if (usingHwWallet) loadingAction(state, `Waiting for ${hwWalletName}...`)
const demoRootSecret = (await mnemonicToWalletSecretDef(
ADALITE_CONFIG.ADALITE_DEMO_WALLET_MNEMONIC
Expand Down
3 changes: 2 additions & 1 deletion app/frontend/wallet/blockchain-explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const blockchainExplorer = (ADALITE_CONFIG) => {
return balance
}

async function submitTxRaw(txHash, txBody) {
async function submitTxRaw(txHash, txBody, params) {
const token = ADALITE_CONFIG.ADALITE_BACKEND_TOKEN
const response = await request(
`${ADALITE_CONFIG.ADALITE_SERVER_URL}/api/txs/submit`,
Expand All @@ -143,6 +143,7 @@ const blockchainExplorer = (ADALITE_CONFIG) => {
}),
{
'Content-Type': 'application/json',
...params,
...(token ? {token} : {}),
}
)
Expand Down
6 changes: 3 additions & 3 deletions app/frontend/wallet/cardano-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ const CardanoWallet = (options) => {
return cryptoProvider.isHwWallet()
}

function getHwWalletName() {
function getWalletName() {
return isHwWallet ? (cryptoProvider as any).getHwWalletName() : undefined
}

function submitTx(signedTx): Promise<any> {
const {txBody, txHash} = signedTx
return blockchainExplorer.submitTxRaw(txHash, txBody)
return blockchainExplorer.submitTxRaw(txHash, txBody, {})
}

function getWalletSecretDef() {
Expand Down Expand Up @@ -261,7 +261,7 @@ const CardanoWallet = (options) => {

return {
isHwWallet,
getHwWalletName,
getWalletName,
getWalletSecretDef,
submitTx,
signTxAux,
Expand Down
9 changes: 5 additions & 4 deletions app/frontend/wallet/shelley-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,14 @@ const ShelleyWallet = ({
return cryptoProvider.isHwWallet()
}

function getHwWalletName() {
return isHwWallet ? (cryptoProvider as any).getHwWalletName() : undefined
function getWalletName() {
return cryptoProvider.getWalletName()
}

function submitTx(signedTx): Promise<any> {
const params = {walletType: getWalletName()}
const {txBody, txHash} = signedTx
return blockchainExplorer.submitTxRaw(txHash, txBody)
return blockchainExplorer.submitTxRaw(txHash, txBody, params)
}

function getWalletSecretDef() {
Expand Down Expand Up @@ -472,7 +473,7 @@ const ShelleyWallet = ({

return {
isHwWallet,
getHwWalletName,
getWalletName,
getWalletSecretDef,
submitTx,
signTxAux,
Expand Down
3 changes: 3 additions & 0 deletions app/frontend/wallet/shelley/shelley-js-crypto-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const ShelleyJsCryptoProvider = ({

const isHwWallet = () => false

const getWalletName = () => 'Mnemonic'

const getWalletSecret = () => masterHdNode.toBuffer()

const getDerivationScheme = () => derivationScheme
Expand Down Expand Up @@ -132,6 +134,7 @@ const ShelleyJsCryptoProvider = ({
network,
signTx,
getWalletSecret,
getWalletName,
getDerivationScheme,
deriveXpub,
isHwWallet,
Expand Down
4 changes: 2 additions & 2 deletions app/frontend/wallet/shelley/shelley-ledger-crypto-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const ShelleyLedgerCryptoProvider = async ({network, config, isWebUSB}) => {
checkVersion()

const isHwWallet = () => true
const getHwWalletName = () => 'Ledger'
const getWalletName = () => 'Ledger'

const deriveXpub = CachedDeriveXpubFactory(derivationScheme, async (absDerivationPath) => {
const response = await ledger.getExtendedPublicKey(absDerivationPath)
Expand Down Expand Up @@ -256,7 +256,7 @@ const ShelleyLedgerCryptoProvider = async ({network, config, isWebUSB}) => {
displayAddressForPath,
deriveXpub,
isHwWallet,
getHwWalletName,
getWalletName,
_sign: sign,
_deriveHdNode: deriveHdNode,
checkVersion,
Expand Down
4 changes: 2 additions & 2 deletions app/frontend/wallet/shelley/shelley-trezor-crypto-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const CardanoTrezorCryptoProvider = ({network, config}) => {
})

const isHwWallet = () => true
const getHwWalletName = () => 'Trezor'
const getWalletName = () => 'Trezor'

const deriveXpub = CachedDeriveXpubFactory(derivationScheme, async (absDerivationPath) => {
const response = await TrezorConnect.cardanoGetPublicKey({
Expand Down Expand Up @@ -220,7 +220,7 @@ const CardanoTrezorCryptoProvider = ({network, config}) => {
displayAddressForPath,
deriveXpub,
isHwWallet,
getHwWalletName,
getWalletName,
_sign: sign,
_deriveHdNode: deriveHdNode,
network,
Expand Down
8 changes: 8 additions & 0 deletions server/middlewares/statsGoogleAnalytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const trackTxSubmissions = mung.jsonAsync(async (body, req, res) => {
? 'txSubmissions'
: 'otherTxSubmissions'
const txSubmissionSuccess = body.Right ? 'successful' : 'unsuccessful'
const txWalletType = req.get('walletType')

try {
const baseEventData = {
Expand All @@ -85,6 +86,13 @@ const trackTxSubmissions = mung.jsonAsync(async (body, req, res) => {
originTestSuccess: tokenMatched,
}

await trackEvent({
...baseEventData,
action: `${txSubmissionType}:${txWalletType}`,
label: 'Wallet type',
value: undefined,
})

if (txSubmissionSuccess === 'successful') {
const {txBody} = req.body

Expand Down
3 changes: 3 additions & 0 deletions server/middlewares/statsRedis.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ const trackTxSubmissions = mung.json((body, req, res) => {

incrCountersBy(`${txSubmissionType}:${txSubmissionSuccess}`, 1)

const txWalletType = req.get('walletType')
incrCountersBy(`${txSubmissionType}:${txWalletType}`, 1)

if (txSubmissionSuccess === 'successful') {
const {txBody} = req.body
let txOutAmount = 0
Expand Down
9 changes: 9 additions & 0 deletions server/statsPageRedis.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ const getStats = async () => {
'sentTotal:total': [],
'sentTotal:monthly': [],
'sentTotal:daily': [],
'Ledger:total': [],
'Ledger:mothly': [],
'Ledger:daily': [],
'Trezor:total': [],
'Trezor:mothly': [],
'Trezor:daily': [],
'Mnemonic:total': [],
'Mnemonic:mothly': [],
'Mnemonic:daily': [],
},
otherTxSubmissions: {
'successful:total': [],
Expand Down

0 comments on commit 70a6408

Please sign in to comment.