Skip to content

Commit

Permalink
feat: event add networkType
Browse files Browse the repository at this point in the history
  • Loading branch information
cs1707 committed Apr 23, 2024
1 parent a348d18 commit d5c17ef
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 21 deletions.
6 changes: 6 additions & 0 deletions src/background/controller/provider/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,9 @@ class ProviderController extends BaseController {
createBy: options?.data?.$ctx?.ga ? 'rabby' : 'dapp',
source: options?.data?.$ctx?.ga?.source || '',
trigger: options?.data?.$ctx?.ga?.trigger || '',
networkType: chainItem?.isTestnet
? 'Custom Network'
: 'Integrated Network',
reported: false,
};

Expand Down Expand Up @@ -574,6 +577,9 @@ class ProviderController extends BaseController {
createBy: options?.data?.$ctx?.ga ? 'rabby' : 'dapp',
source: options?.data?.$ctx?.ga?.source || '',
trigger: options?.data?.$ctx?.ga?.trigger || '',
networkType: chainItem?.isTestnet
? 'Custom Network'
: 'Integrated Network',
});
if (!isSpeedUp && !isCancel) {
transactionHistoryService.addSubmitFailedTransaction({
Expand Down
2 changes: 2 additions & 0 deletions src/background/controller/provider/rpcFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ function reportStatsData() {
createBy: statsData?.createBy,
source: statsData?.source,
trigger: statsData?.trigger,
networkType: statsData?.networkType,
};
if (statsData.signMethod) {
sData.signMethod = statsData.signMethod;
Expand All @@ -320,6 +321,7 @@ function reportStatsData() {
createBy: statsData?.createBy,
source: statsData?.source,
trigger: statsData?.trigger,
networkType: statsData?.networkType || '',
});
}

Expand Down
16 changes: 13 additions & 3 deletions src/background/service/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export type StatsData = {
trigger: any;
reported: boolean;
signMethod?: string;
networkType?: string;
};

// something need user approval in window
Expand Down Expand Up @@ -258,15 +259,24 @@ class NotificationService extends Events {
: null;
const explain = signingTx?.explain;

if (explain && currentAccount) {
const chain = findChain({
id: signingTx?.rawTx.chainId,
});

if ((explain || chain?.isTestnet) && currentAccount) {
stats.report('preExecTransaction', {
type: currentAccount.brandName,
category: KEYRING_CATEGORY_MAP[currentAccount.type],
chainId: explain.native_token.chain,
success: explain.calcSuccess && explain.pre_exec.success,
chainId: chain?.serverId || '',
success: explain
? explain.calcSuccess && explain.pre_exec.success
: true,
createBy: data?.params.$ctx?.ga ? 'rabby' : 'dapp',
source: data?.params.$ctx?.ga?.source || '',
trigger: data?.params.$ctx?.ga.trigger || '',
networkType: chain?.isTestnet
? 'Custom Network'
: 'Integrated Network',
});
}
};
Expand Down
7 changes: 4 additions & 3 deletions src/background/service/transactionHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,12 +728,13 @@ class TxHistory {
stats.report('completeTransaction', {
chainId: chain.serverId,
success,
preExecSuccess: Boolean(
target.explain?.pre_exec.success && target.explain?.calcSuccess
),
preExecSuccess: target?.explain
? target.explain?.pre_exec.success && target.explain?.calcSuccess
: true,
createBy: target?.$ctx?.ga ? 'rabby' : 'dapp',
source: target?.$ctx?.ga?.source || '',
trigger: target?.$ctx?.ga?.trigger || '',
networkType: chain?.isTestnet ? 'Custom Network' : 'Integrated Network',
});
}
this.clearBefore({ address, chainId, nonce });
Expand Down
10 changes: 7 additions & 3 deletions src/ui/views/Approval/components/CoinbaseWaiting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,24 +136,28 @@ const CoinbaseWaiting = ({ params }: { params: ApprovalParams }) => {

if (!isText && !isSignTriggered) {
const explain = explainRef.current;
const chainInfo = findChainByEnum(chain);

if (explain) {
if (explain || chainInfo?.isTestnet) {
wallet.reportStats('signTransaction', {
type: account.brandName,
chainId: findChainByEnum(chain)?.serverId || '',
chainId: chainInfo?.serverId || '',
category: KEYRING_CATEGORY_MAP[account.type],
preExecSuccess: explain
? explain?.calcSuccess && explain?.pre_exec.success
: true,
createBy: params?.$ctx?.ga ? 'rabby' : 'dapp',
source: params?.$ctx?.ga?.source || '',
trigger: params?.$ctx?.ga?.trigger || '',
networkType: chainInfo?.isTestnet
? 'Custom Network'
: 'Integrated Network',
});
}
matomoRequestEvent({
category: 'Transaction',
action: 'Submit',
label: account.brandName,
label: chainInfo?.isTestnet ? 'Custom Network' : 'Integrated Network',
});
isSignTriggered = true;
}
Expand Down
5 changes: 4 additions & 1 deletion src/ui/views/Approval/components/CommonWaiting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ export const CommonWaiting = ({ params }: { params: ApprovalParams }) => {
createBy: params?.$ctx?.ga ? 'rabby' : 'dapp',
source: params?.$ctx?.ga?.source || '',
trigger: params?.$ctx?.ga?.trigger || '',
networkType: chain?.isTestnet
? 'Custom Network'
: 'Integrated Network',
});
}
} else {
Expand Down Expand Up @@ -165,7 +168,7 @@ export const CommonWaiting = ({ params }: { params: ApprovalParams }) => {
matomoRequestEvent({
category: 'Transaction',
action: 'Submit',
label: brandName,
label: chain?.isTestnet ? 'Custom Network' : 'Integrated Network',
});
setSignFinishedData({
data: sig,
Expand Down
5 changes: 4 additions & 1 deletion src/ui/views/Approval/components/ImKeyHardwareWaiting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ export const ImKeyHardwareWaiting = ({
createBy: params?.$ctx?.ga ? 'rabby' : 'dapp',
source: params?.$ctx?.ga?.source || '',
trigger: params?.$ctx?.ga?.trigger || '',
networkType: chain?.isTestnet
? 'Custom Network'
: 'Integrated Network',
});
}
} else {
Expand Down Expand Up @@ -181,7 +184,7 @@ export const ImKeyHardwareWaiting = ({
matomoRequestEvent({
category: 'Transaction',
action: 'Submit',
label: KEYRING_CLASS.HARDWARE.IMKEY,
label: chain?.isTestnet ? 'Custom Network' : 'Integrated Network',
});

setSignFinishedData({
Expand Down
5 changes: 4 additions & 1 deletion src/ui/views/Approval/components/LedgerHardwareWaiting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ const LedgerHardwareWaiting = ({ params }: { params: ApprovalParams }) => {
createBy: params?.$ctx?.ga ? 'rabby' : 'dapp',
source: params?.$ctx?.ga?.source || '',
trigger: params?.$ctx?.ga?.trigger || '',
networkType: chain?.isTestnet
? 'Custom Network'
: 'Integrated Network',
});
}
} else {
Expand Down Expand Up @@ -179,7 +182,7 @@ const LedgerHardwareWaiting = ({ params }: { params: ApprovalParams }) => {
matomoRequestEvent({
category: 'Transaction',
action: 'Submit',
label: KEYRING_CLASS.HARDWARE.LEDGER,
label: chain?.isTestnet ? 'Custom Network' : 'Integrated Network',
});

setSignFinishedData({
Expand Down
5 changes: 4 additions & 1 deletion src/ui/views/Approval/components/PrivatekeyWaiting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ export const PrivatekeyWaiting = ({ params }: { params: ApprovalParams }) => {
createBy: params?.$ctx?.ga ? 'rabby' : 'dapp',
source: params?.$ctx?.ga?.source || '',
trigger: params?.$ctx?.ga?.trigger || '',
networkType: chain?.isTestnet
? 'Custom Network'
: 'Integrated Network',
});
}
} else {
Expand Down Expand Up @@ -166,7 +169,7 @@ export const PrivatekeyWaiting = ({ params }: { params: ApprovalParams }) => {
matomoRequestEvent({
category: 'Transaction',
action: 'Submit',
label: type,
label: chain?.isTestnet ? 'Custom Network' : 'Integrated Network',
});
setSignFinishedData({
data: sig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ const QRHardWareWaiting = ({ params }) => {

stats.report('signTransaction', {
type: account.brandName,
chainId: findChainByEnum(chain)?.serverId || '',
chainId: chainInfo?.serverId || '',
category: KEYRING_CATEGORY_MAP[account.type],
preExecSuccess: explain
? explain?.calcSuccess && explain?.pre_exec.success
Expand All @@ -216,6 +216,9 @@ const QRHardWareWaiting = ({ params }) => {
source: params?.$ctx?.ga?.source || '',
trigger: params?.$ctx?.ga?.trigger || '',
signMethod,
networkType: chainInfo?.isTestnet
? 'Custom Network'
: 'Integrated Network',
});
}
} else {
Expand Down
6 changes: 4 additions & 2 deletions src/ui/views/Approval/components/SignTestnetTx/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,13 @@ export const SignTestnetTx = ({ params, origin }: SignTxProps) => {
createBy: params?.$ctx?.ga ? 'rabby' : 'dapp',
source: params?.$ctx?.ga?.source || '',
trigger: params?.$ctx?.ga?.trigger || '',
networkType: chain?.isTestnet ? 'Custom Network' : 'Integrated Network',
});

matomoRequestEvent({
category: 'Transaction',
action: 'init',
label: currentAccount.brandName,
label: chain?.isTestnet ? 'Custom Network' : 'Integrated Network',
});
if (currentAccount.type === KEYRING_TYPE.GnosisKeyring) {
setIsGnosisAccount(true);
Expand Down Expand Up @@ -464,12 +465,13 @@ export const SignTestnetTx = ({ params, origin }: SignTxProps) => {
createBy: params?.$ctx?.ga ? 'rabby' : 'dapp',
source: params?.$ctx?.ga?.source || '',
trigger: params?.$ctx?.ga?.trigger || '',
networkType: chain?.isTestnet ? 'Custom Network' : 'Integrated Network',
});

matomoRequestEvent({
category: 'Transaction',
action: 'Submit',
label: currentAccount.brandName,
label: chain?.isTestnet ? 'Custom Network' : 'Integrated Network',
});
resolveApproval({
...transaction,
Expand Down
8 changes: 6 additions & 2 deletions src/ui/views/Approval/components/SignTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,7 @@ const SignTx = ({ params, origin }: SignTxProps) => {
createBy: params?.$ctx?.ga ? 'rabby' : 'dapp',
source: params?.$ctx?.ga?.source || '',
trigger: params?.$ctx?.ga?.trigger || '',
networkType: chain?.isTestnet ? 'Custom Network' : 'Integrated Network',
});
if (!isViewGnosisSafe) {
const params: any = {
Expand Down Expand Up @@ -1194,6 +1195,7 @@ const SignTx = ({ params, origin }: SignTxProps) => {
createBy: params?.$ctx?.ga ? 'rabby' : 'dapp',
source: params?.$ctx?.ga?.source || '',
trigger: params?.$ctx?.ga?.trigger || '',
networkType: chain?.isTestnet ? 'Custom Network' : 'Integrated Network',
});

let newTx;
Expand Down Expand Up @@ -1363,12 +1365,13 @@ const SignTx = ({ params, origin }: SignTxProps) => {
createBy: params?.$ctx?.ga ? 'rabby' : 'dapp',
source: params?.$ctx?.ga?.source || '',
trigger: params?.$ctx?.ga?.trigger || '',
networkType: chain?.isTestnet ? 'Custom Network' : 'Integrated Network',
});

matomoRequestEvent({
category: 'Transaction',
action: 'Submit',
label: currentAccount.brandName,
label: chain?.isTestnet ? 'Custom Network' : 'Integrated Network',
});
resolveApproval({
...transaction,
Expand Down Expand Up @@ -1655,12 +1658,13 @@ const SignTx = ({ params, origin }: SignTxProps) => {
createBy: params?.$ctx?.ga ? 'rabby' : 'dapp',
source: params?.$ctx?.ga?.source || '',
trigger: params?.$ctx?.ga?.trigger || '',
networkType: chain?.isTestnet ? 'Custom Network' : 'Integrated Network',
});

matomoRequestEvent({
category: 'Transaction',
action: 'init',
label: currentAccount.brandName,
label: chain?.isTestnet ? 'Custom Network' : 'Integrated Network',
});

if (currentAccount.type === KEYRING_TYPE.GnosisKeyring) {
Expand Down
12 changes: 9 additions & 3 deletions src/ui/views/Approval/components/WatchAddressWaiting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,10 @@ const WatchAddressWaiting = ({ params }: { params: ApprovalParams }) => {
) {
if (!isText && !isSignTriggered) {
const explain = explainRef.current;
const chainInfo = findChainByEnum(chain);

// const tx = approval.data?.params;
if (explain) {
if (explain || chainInfo?.isTestnet) {
// const { nonce, from, chainId } = tx;
// const explain = await wallet.getExplainCache({
// nonce: Number(nonce),
Expand All @@ -220,20 +221,25 @@ const WatchAddressWaiting = ({ params }: { params: ApprovalParams }) => {

wallet.reportStats('signTransaction', {
type: account.brandName,
chainId: findChainByEnum(chain)?.serverId || '',
chainId: chainInfo?.serverId || '',
category: KEYRING_CATEGORY_MAP[account.type],
preExecSuccess: explain
? explain?.calcSuccess && explain?.pre_exec.success
: true,
createBy: params?.$ctx?.ga ? 'rabby' : 'dapp',
source: params?.$ctx?.ga?.source || '',
trigger: params?.$ctx?.ga?.trigger || '',
networkType: chainInfo?.isTestnet
? 'Custom Network'
: 'Integrated Network',
});
}
matomoRequestEvent({
category: 'Transaction',
action: 'Submit',
label: account.brandName,
label: chainInfo?.isTestnet
? 'Custom Network'
: 'Integrated Network',
});
isSignTriggered = true;
}
Expand Down

0 comments on commit d5c17ef

Please sign in to comment.