Skip to content

Commit

Permalink
fix: bring back confirmation time measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
meeh0w committed Aug 28, 2024
1 parent f80a9b5 commit 4242722
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 42 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"dependencies": {
"@avalabs/avalanchejs": "4.0.5",
"@avalabs/bitcoin-module": "0.0.0-feat-link-detail-type-20240828084300",
"@avalabs/bitcoin-module": "0.0.0-feat-link-detail-type-20240828121226",
"@avalabs/bridge-unified": "2.1.0",
"@avalabs/core-bridge-sdk": "3.1.0-alpha.4",
"@avalabs/core-chains-sdk": "3.1.0-alpha.4",
Expand All @@ -39,8 +39,8 @@
"@avalabs/hw-app-avalanche": "0.14.1",
"@avalabs/core-k2-components": "4.18.0-alpha.47",
"@avalabs/types": "3.1.0-alpha.3",
"@avalabs/evm-module": "0.0.0-feat-link-detail-type-20240828084300",
"@avalabs/vm-module-types": "0.0.0-feat-link-detail-type-20240828084300",
"@avalabs/evm-module": "0.0.0-feat-link-detail-type-20240828121226",
"@avalabs/vm-module-types": "0.0.0-feat-link-detail-type-20240828121226",
"@blockaid/client": "0.10.0",
"@coinbase/cbpay-js": "1.6.0",
"@cubist-labs/cubesigner-sdk": "0.3.28",
Expand Down
63 changes: 38 additions & 25 deletions src/background/vmModules/ApprovalController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,41 @@ import { NetworkService } from '../services/network/NetworkService';
import { NetworkWithCaipId } from '../services/network/models';

import { ApprovalParamsWithContext, VIA_MODULE_SYMBOL } from './models';
import { measureDuration } from '@src/utils/measureDuration';
import { AnalyticsServicePosthog } from '../services/analytics/AnalyticsServicePosthog';

class ApprovalController implements IApprovalController {
#walletService: WalletService;
#requestsMetadata = new Map<
string,
{ txType: string; chainId: number; site: string; rpcUrl: string }
>();

constructor(walletService: WalletService) {
this.#walletService = walletService;
}

onTransactionConfirmed = (txHash: `0x${string}`) => {
console.log(
'DEBUG Transaction Confirmed. Show a toast? Trigger browser notification?',
txHash
);
onTransactionConfirmed = (txHash: `0x${string}`, requestId: string) => {
// Transaction Confirmed. Show a toast? Trigger browser notification?',
const confirmationTime = measureDuration(requestId).end();
const analyticsService = container.resolve(AnalyticsServicePosthog);
const metadata = this.#requestsMetadata.get(requestId);

if (metadata) {
analyticsService.captureEncryptedEvent({
name: 'TransactionTimeToConfirmation',
windowId: crypto.randomUUID(),
properties: {
...metadata,
duration: confirmationTime,
},
});
this.#requestsMetadata.delete(requestId);
}
};

onTransactionReverted = (txHash: `0x${string}`) => {
console.log(
'DEBUG Transaction Confirmed. Show a toast? Trigger browser notification?',
txHash
);
onTransactionReverted = () => {
// Transaction Reverted. Show a toast? Trigger browser notification?',
};

requestApproval = async (
Expand All @@ -51,21 +66,6 @@ class ApprovalController implements IApprovalController {
throw new Error('Unsupported network: ' + params.request.chainId);
}

// 2. Setup listeners on ActionsService, waiting for the action
// to be concluded (approved, rejected or timeout)
//
// Remember that actions can also be updated (i.e. fee could be updated).
// If it is, this gets a bit tricky for Bitcoin. The reason is that I guess
// the Modules should be the source of truth here and only provide us with
// inputs/outputs arrays, but if the user updates the fee on the approval screen,
// we need to may need to re-generate the inputs/outputs (i.e. to select different
// UTXOs). So, should we then ask the Bitcoin Module to create the signing data again?
// Seems cumbersome. So for now we agreed that the frontend could reconstruct the
// inputs/outputs arrays (just like it does for the Send feature at the moment).
// There is a Slack convo with the mobile team about this, feel free to ask to get
// added to it so you can see more details.

// 3. Open the approval screen
const url = this.#getPopupUrl(params.request.method);
const action = await openApprovalWindow(this.#buildAction(params), url);

Expand All @@ -74,6 +74,10 @@ class ApprovalController implements IApprovalController {
const actionId = action.id;

const cleanup = () => {
if (action.actionId) {
actionsService.removeAction(action.actionId);
}

actionsService.removeListener(
ActionsEvent.MODULE_ACTION_UPDATED,
onUpdated
Expand Down Expand Up @@ -154,6 +158,15 @@ class ApprovalController implements IApprovalController {
const { signingData } = action;

if (signingData?.type === RpcMethod.BITCOIN_SEND_TRANSACTION) {
this.#requestsMetadata.set(params.request.requestId, {
txType: 'send',
chainId: network.chainId,
rpcUrl: network.rpcUrl,
site: new URL(params.request.dappInfo.url).hostname,
});

measureDuration(params.request.requestId).start();

const { inputs, outputs } = await buildBtcTx(
signingData.account,
getProviderForNetwork(network) as BitcoinProvider,
Expand Down
28 changes: 14 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@
"@scure/base" "1.1.5"
micro-eth-signer "0.7.2"

"@avalabs/[email protected]20240828084300":
version "0.0.0-feat-link-detail-type-20240828084300"
resolved "https://registry.yarnpkg.com/@avalabs/bitcoin-module/-/bitcoin-module-0.0.0-feat-link-detail-type-20240828084300.tgz#5db0ef43616b66d39a90fcc5ae7e4fde08c93419"
integrity sha512-d6ovdqTXnSvY2iiefwiZ8YLnztQ2EfULDzJRdZaq6sAcsy8P2UkCXUHJeiBJewDcKUzf0hpuzfSrNnyd8c0CAA==
"@avalabs/[email protected]20240828121226":
version "0.0.0-feat-link-detail-type-20240828121226"
resolved "https://registry.yarnpkg.com/@avalabs/bitcoin-module/-/bitcoin-module-0.0.0-feat-link-detail-type-20240828121226.tgz#87e365b7a8e9cbaf1c3bd9bd6fbdd4c6c226ca11"
integrity sha512-TiGgB8Pazd/Shr/buUBqnO3+Awmrv4NNeHdIyP8vpQ6K7+hkYDR/ZhZENb0k1qFuUmJmiyf8c7BGx859Y2vjHA==
dependencies:
"@avalabs/core-coingecko-sdk" "3.1.0-alpha.1"
"@avalabs/core-utils-sdk" "3.1.0-alpha.1"
"@avalabs/core-wallets-sdk" "3.1.0-alpha.1"
"@avalabs/vm-module-types" "0.0.0-feat-link-detail-type-20240828084300"
"@avalabs/vm-module-types" "0.0.0-feat-link-detail-type-20240828121226"
"@metamask/rpc-errors" "6.3.0"
"@zodios/core" "10.9.6"
big.js "6.2.1"
Expand Down Expand Up @@ -227,18 +227,18 @@
ledger-bitcoin "0.2.3"
xss "1.0.14"

"@avalabs/[email protected]20240828084300":
version "0.0.0-feat-link-detail-type-20240828084300"
resolved "https://registry.yarnpkg.com/@avalabs/evm-module/-/evm-module-0.0.0-feat-link-detail-type-20240828084300.tgz#491918e6695f8b093295aabb6eeb5e69169e2204"
integrity sha512-L0ohLqPRGPUCZB6DAhgVaBgOY+z8xyDQFjr0JpRNvJLAzla+pWiVzfOsveUQvQCOTf9yFtgk+/nV4tbT4JXQrA==
"@avalabs/[email protected]20240828121226":
version "0.0.0-feat-link-detail-type-20240828121226"
resolved "https://registry.yarnpkg.com/@avalabs/evm-module/-/evm-module-0.0.0-feat-link-detail-type-20240828121226.tgz#cf63a70fd116f60946680b052527c20c9c219bd7"
integrity sha512-DKQlPs0E2BSrz8cs8IOYPqAwiPd6ysQUVCLY2D4Fod2kiJWe59Tx4Ljebr8fQPa1XNMY0bHlIAhrjD/EBQmYdw==
dependencies:
"@avalabs/core-coingecko-sdk" "3.1.0-alpha.1"
"@avalabs/core-etherscan-sdk" "3.1.0-alpha.1"
"@avalabs/core-utils-sdk" "3.1.0-alpha.1"
"@avalabs/core-wallets-sdk" "3.1.0-alpha.1"
"@avalabs/glacier-sdk" "3.1.0-alpha.1"
"@avalabs/types" "3.1.0-alpha.1"
"@avalabs/vm-module-types" "0.0.0-feat-link-detail-type-20240828084300"
"@avalabs/vm-module-types" "0.0.0-feat-link-detail-type-20240828121226"
"@blockaid/client" "0.11.0"
"@metamask/rpc-errors" "6.3.0"
"@zodios/core" "10.9.6"
Expand Down Expand Up @@ -277,10 +277,10 @@
resolved "https://registry.yarnpkg.com/@avalabs/types/-/types-3.1.0-alpha.3.tgz#3b7fb8cb8e2f124e0b11406788a903142753b5a0"
integrity sha512-WN6NyPsF9XpmQp2SN4UbwjBT+XYH8di8gvL9rppQxz4d43xRLI1T2WVt/LXJgYdOauhuaSelb6zB4yNqGyKutQ==

"@avalabs/[email protected]20240828084300":
version "0.0.0-feat-link-detail-type-20240828084300"
resolved "https://registry.yarnpkg.com/@avalabs/vm-module-types/-/vm-module-types-0.0.0-feat-link-detail-type-20240828084300.tgz#65d502f51ab5d5349e115ad2309088413bb3082f"
integrity sha512-3Ja+OvWPjd7tFAAFOoKyZOyBJbT28ErMgn9efYZD5M6JQMUTMHZZ3u3tBV3bh78G1SxCHFha277I/7HSiNj/Og==
"@avalabs/[email protected]20240828121226":
version "0.0.0-feat-link-detail-type-20240828121226"
resolved "https://registry.yarnpkg.com/@avalabs/vm-module-types/-/vm-module-types-0.0.0-feat-link-detail-type-20240828121226.tgz#ad7c102eb5aa568a4820bf5f198b66ca42a84fdd"
integrity sha512-9E6NChwI8Nf2m1Jt3ItfRBSHEaHLNUPWkdkJupApa1SI4t8pO4yl7Oror6UgyWBMi18qCv73shVGtom6ctJk+Q==
dependencies:
"@avalabs/core-wallets-sdk" "3.1.0-alpha.1"
"@metamask/rpc-errors" "6.3.0"
Expand Down

0 comments on commit 4242722

Please sign in to comment.