Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add AB test for human-readable transactions #2543

Merged
merged 4 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ import './safe-apps-commands'
before(() => {
cy.on('window:before:load', (window) => {
window.localStorage.setItem('SAFE_v2__show_terms', false)
// So that tests that rely on this feature don't randomly fail
window.localStorage.setItem('SAFE_v2__AB_human-readable', true)
})
})
7 changes: 6 additions & 1 deletion src/components/dashboard/PendingTxs/PendingTxListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import useSafeInfo from '@/hooks/useSafeInfo'
import useWallet from '@/hooks/wallets/useWallet'
import SignTxButton from '@/components/transactions/SignTxButton'
import ExecuteTxButton from '@/components/transactions/ExecuteTxButton'
import useABTesting from '@/services/tracking/useAbTesting'
import { AbTest } from '@/services/tracking/abTesting'

type PendingTxType = {
transaction: TransactionSummary
Expand All @@ -26,6 +28,7 @@ const PendingTx = ({ transaction }: PendingTxType): ReactElement => {
const { id } = transaction
const { safe } = useSafeInfo()
const wallet = useWallet()
const shouldDisplayHumanDescription = useABTesting(AbTest.HUMAN_DESCRIPTION)
const canSign = wallet ? isSignableBy(transaction, wallet.address) : false
const canExecute = wallet ? isExecutable(transaction, wallet?.address, safe) : false

Expand All @@ -40,7 +43,9 @@ const PendingTx = ({ transaction }: PendingTxType): ReactElement => {
[router, id],
)

const displayInfo = !transaction.txInfo.richDecodedInfo && transaction.txInfo.type !== TransactionInfoType.TRANSFER
const displayInfo =
(!transaction.txInfo.richDecodedInfo && transaction.txInfo.type !== TransactionInfoType.TRANSFER) ||
!shouldDisplayHumanDescription

return (
<NextLink href={url} passHref>
Expand Down
3 changes: 3 additions & 0 deletions src/components/transactions/TxDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { DelegateCallWarning, UnsignedWarning } from '@/components/transactions/
import Multisend from '@/components/transactions/TxDetails/TxData/DecodedData/Multisend'
import useSafeInfo from '@/hooks/useSafeInfo'
import useIsPending from '@/hooks/useIsPending'
import { trackEvent, TX_LIST_EVENTS } from '@/services/analytics'

export const NOT_AVAILABLE = 'n/a'

Expand Down Expand Up @@ -125,6 +126,8 @@ const TxDetails = ({

const [txDetailsData, error, loading] = useAsync<TransactionDetails>(
async () => {
trackEvent(TX_LIST_EVENTS.FETCH_DETAILS)

return txDetails || getTransactionDetails(chainId, txSummary.id)
},
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
6 changes: 5 additions & 1 deletion src/components/transactions/TxSummary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import useTransactionStatus from '@/hooks/useTransactionStatus'
import TxType from '@/components/transactions/TxType'
import TxConfirmations from '../TxConfirmations'
import useIsPending from '@/hooks/useIsPending'
import useABTesting from '@/services/tracking/useAbTesting'
import { AbTest } from '@/services/tracking/abTesting'

const getStatusColor = (value: TransactionStatus, palette: Palette) => {
switch (value) {
Expand All @@ -41,6 +43,7 @@ const TxSummary = ({ item, isGrouped }: TxSummaryProps): ReactElement => {
const wallet = useWallet()
const txStatusLabel = useTransactionStatus(tx)
const isPending = useIsPending(tx.id)
const shouldDisplayHumanDescription = useABTesting(AbTest.HUMAN_DESCRIPTION)
const isQueue = isTxQueued(tx.txStatus)
const awaitingExecution = isAwaitingExecution(tx.txStatus)
const nonce = isMultisigExecutionInfo(tx.executionInfo) ? tx.executionInfo.nonce : undefined
Expand All @@ -52,7 +55,8 @@ const TxSummary = ({ item, isGrouped }: TxSummaryProps): ReactElement => {
: undefined

const displayConfirmations = isQueue && !!submittedConfirmations && !!requiredConfirmations
const displayInfo = !tx.txInfo.richDecodedInfo && tx.txInfo.type !== TransactionInfoType.TRANSFER
const displayInfo =
(!tx.txInfo.richDecodedInfo && tx.txInfo.type !== TransactionInfoType.TRANSFER) || !shouldDisplayHumanDescription

return (
<Box
Expand Down
8 changes: 4 additions & 4 deletions src/components/transactions/TxSummary/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
}

.columnTemplateShort {
grid-template-columns: minmax(50px, 0.25fr) minmax(150px, 4fr) minmax(200px, 2fr) 1fr minmax(60px, 0.5fr) minmax(
grid-template-columns: minmax(50px, 0.25fr) minmax(150px, 4fr) 0fr minmax(200px, 2fr) 1fr minmax(60px, 0.5fr) minmax(
170px,
1fr
);
grid-template-areas: 'nonce type date confirmations actions status';
grid-template-areas: 'nonce type empty date confirmations actions status';
}

.columnTemplateTxHistory {
Expand All @@ -27,8 +27,8 @@
}

.columnTemplateTxHistoryShort {
grid-template-columns: minmax(50px, 0.25fr) 6fr 0.75fr 0.5fr;
grid-template-areas: 'nonce type date status';
grid-template-columns: minmax(50px, 0.25fr) 6fr 0fr 0.75fr 0.5fr;
grid-template-areas: 'nonce type empty date status';
}

.columnWrap {
Expand Down
7 changes: 5 additions & 2 deletions src/components/transactions/TxType/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import { Box } from '@mui/material'
import css from './styles.module.css'
import SafeAppIconCard from '@/components/safe-apps/SafeAppIconCard'
import { HumanDescription, TransferDescription } from '@/components/transactions/HumanDescription'
import useABTesting from '@/services/tracking/useAbTesting'
import { AbTest } from '@/services/tracking/abTesting'

type TxTypeProps = {
tx: TransactionSummary
}

const TxType = ({ tx }: TxTypeProps) => {
const type = useTransactionType(tx)
const shouldDisplayHumanDescription = useABTesting(AbTest.HUMAN_DESCRIPTION)

const humanDescription = tx.txInfo.richDecodedInfo?.fragments

Expand All @@ -24,9 +27,9 @@ const TxType = ({ tx }: TxTypeProps) => {
height={16}
fallback="/images/transactions/custom.svg"
/>
{humanDescription ? (
{humanDescription && shouldDisplayHumanDescription ? (
<HumanDescription fragments={humanDescription} />
) : tx.txInfo.type === TransactionInfoType.TRANSFER ? (
) : tx.txInfo.type === TransactionInfoType.TRANSFER && shouldDisplayHumanDescription ? (
<TransferDescription isSendTx={tx.txInfo.direction === TransferDirection.OUTGOING} txInfo={tx.txInfo} />
) : (
type.text
Expand Down
3 changes: 3 additions & 0 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import useSafeMessageNotifications from '@/hooks/messages/useSafeMessageNotifica
import useSafeMessagePendingStatuses from '@/hooks/messages/useSafeMessagePendingStatuses'
import useChangedValue from '@/hooks/useChangedValue'
import { TxModalProvider } from '@/components/tx-flow'
import useABTesting from '@/services/tracking/useAbTesting'
import { AbTest } from '@/services/tracking/abTesting'
import { useNotificationTracking } from '@/components/settings/PushNotifications/hooks/useNotificationTracking'

const GATEWAY_URL = IS_PRODUCTION || cgwDebugStorage.get() ? GATEWAY_URL_PRODUCTION : GATEWAY_URL_STAGING
Expand All @@ -59,6 +61,7 @@ const InitApp = (): null => {
useTxTracking()
useSafeMsgTracking()
useBeamer()
useABTesting(AbTest.HUMAN_DESCRIPTION)

return null
}
Expand Down
4 changes: 4 additions & 0 deletions src/services/analytics/events/txList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export const TX_LIST_EVENTS = {
action: 'Batch Execute',
category: TX_LIST_CATEGORY,
},
FETCH_DETAILS: {
action: 'Fetch transaction details',
category: TX_LIST_CATEGORY,
},
}

export const MESSAGE_EVENTS = {
Expand Down
4 changes: 3 additions & 1 deletion src/services/tracking/abTesting.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/**
* Holds current A/B test identifiers.
*/
export const enum AbTest {}
export const enum AbTest {
HUMAN_DESCRIPTION = 'human-readable',
}

let _abTest: AbTest | null = null

Expand Down