Skip to content

Commit 8db0455

Browse files
authored
Merge pull request #1717 from balancer/fix/gas-estimate-speed-label
fix: gas estimate speed label
2 parents 3ed1722 + 3ce72de commit 8db0455

File tree

5 files changed

+93
-9
lines changed

5 files changed

+93
-9
lines changed

packages/lib/modules/transactions/transaction-steps/step-tracker/DesktopStepTracker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type Props = {
1515

1616
export function DesktopStepTracker({ chain, transactionSteps, isTxBatch, extraStyles }: Props) {
1717
return (
18-
<Card padding={0} position="absolute" right="-300px" top="10px" width="280px" {...extraStyles}>
18+
<Card padding={0} position="absolute" right="-320px" top="10px" width="300px" {...extraStyles}>
1919
<VStack alignItems="flex-start" gap="0" w="full">
2020
<HStack justify="space-between" px="ms" py="sm" w="full">
2121
<Heading fontWeight="bold" size="h6">

packages/lib/modules/transactions/transaction-steps/step-tracker/Step.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { getPendingNestedSteps, hasSomePendingNestedTxInBatch } from '../safe/sa
1515
import { useTransactionGasCost } from '../useTransactionGasCost'
1616
import { getBlockExplorerTxUrl } from '@repo/lib/shared/utils/blockExplorer'
1717
import { getGqlChain } from '@repo/lib/config/app.config'
18-
import { SMALL_AMOUNT_LABEL } from '@repo/lib/shared/utils/numbers'
18+
import { TxnSpeedSetting } from './TxnSpeedSetting'
1919

2020
export function Step(props: StepProps) {
2121
const transaction = props.step.transaction
@@ -121,7 +121,7 @@ function NestedInfo({
121121
}) {
122122
const gasCostData = useTransactionGasCost(transaction)
123123

124-
const isSmallAmount = gasCostData && gasCostData.costUsd?.replace('$', '') === SMALL_AMOUNT_LABEL
124+
const isActual = gasCostData && gasCostData.isActual
125125

126126
const textProps = {
127127
fontSize: 'sm',
@@ -133,11 +133,13 @@ function NestedInfo({
133133
<Box mb="0" mt="0" p="0.5" pl="0">
134134
<HStack align="start" gap="xxs">
135135
{!details?.gasless && gasCostData && gasCostData.costUsd != null ? (
136-
<Text {...textProps} p="0">
137-
{gasCostData.isActual ? 'Final gas: ' : 'Estimated gas: '}
138-
{(!isSmallAmount || !gasCostData.isActual) && '~'}
139-
{gasCostData.costUsd}
140-
</Text>
136+
<HStack gap="0">
137+
<Text {...textProps} mr="sm" p="0">
138+
{isActual ? 'Final gas: ' : 'Estimated gas: '}
139+
{gasCostData.costUsd}
140+
</Text>
141+
{!isActual && <TxnSpeedSetting />}
142+
</HStack>
141143
) : step.isComplete() ? (
142144
<Text {...textProps}>Previously approved</Text>
143145
) : (
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import {
2+
Box,
3+
Popover,
4+
PopoverTrigger,
5+
HStack,
6+
Image,
7+
PopoverContent,
8+
PopoverArrow,
9+
Text,
10+
} from '@chakra-ui/react'
11+
import { useUserAccount } from '@repo/lib/modules/web3/UserAccountProvider'
12+
import { SpeedIcon } from '@repo/lib/shared/components/icons/SpeedIcon'
13+
import { WalletIcon } from '@repo/lib/shared/components/icons/WalletIcon'
14+
15+
function getSpeedSettingLabel(id: string = 'default') {
16+
switch (id) {
17+
case 'rabby':
18+
case 'io.rabby':
19+
return 'Normal'
20+
case 'metaMaskSDK':
21+
return 'Low'
22+
default:
23+
return 'Slow'
24+
}
25+
}
26+
27+
export function TxnSpeedSetting() {
28+
const { connector } = useUserAccount()
29+
30+
const speedSettingLabel = getSpeedSettingLabel(connector?.id)
31+
const userWalletLabel = connector?.name || 'your wallet'
32+
33+
return (
34+
<Popover placement="top" trigger="hover">
35+
<PopoverTrigger>
36+
<HStack gap="xs">
37+
{connector && connector.icon ? (
38+
<Image height="14px" src={connector.icon} width="14px" />
39+
) : (
40+
<WalletIcon size={14} />
41+
)}
42+
<Box color="font.secondary" position="relative" top="0px">
43+
<SpeedIcon size={14} />
44+
</Box>
45+
<Text color="grayText" cursor="pointer" fontSize="xs">
46+
{speedSettingLabel}
47+
</Text>
48+
</HStack>
49+
</PopoverTrigger>
50+
<PopoverContent p="2" shadow="2xl" width="250px" zIndex="popover">
51+
<PopoverArrow bg="background.level3" />
52+
<Text color="grayText" fontSize="sm">
53+
{`This is a general estimate to give you a sense of the cost based on a '${speedSettingLabel}' speed transaction on your ${userWalletLabel}. This UI can’t access your wallet’s transaction speed, so the estimate may be inaccurate if your wallet is set to a higher speed.`}
54+
</Text>
55+
</PopoverContent>
56+
</Popover>
57+
)
58+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ModalContentProps } from '@chakra-ui/react'
22

33
export function getStylesForModalContentWithStepTracker(isDesktop: boolean): ModalContentProps {
4-
return isDesktop ? { left: '-100px', position: 'relative' } : {}
4+
return isDesktop ? { left: '-160px', position: 'relative' } : {}
55
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export function SpeedIcon({ size = 24 }: { size?: number }) {
2+
return (
3+
<svg
4+
fill="none"
5+
height={size}
6+
viewBox="0 0 14 14"
7+
width={size}
8+
xmlns="http://www.w3.org/2000/svg"
9+
>
10+
<path
11+
d="M2.757 11.743a6 6 0 1 1 8.486 0"
12+
stroke="currentColor"
13+
strokeLinecap="round"
14+
strokeWidth="1.5"
15+
/>
16+
<path
17+
d="M9.667 4.828 7 7.495"
18+
stroke="currentColor"
19+
strokeLinecap="round"
20+
strokeWidth="1.25"
21+
/>
22+
</svg>
23+
)
24+
}

0 commit comments

Comments
 (0)