Skip to content

Commit

Permalink
swap expanded state (#5115)
Browse files Browse the repository at this point in the history
  • Loading branch information
benisgold authored Oct 13, 2023
1 parent 488acd7 commit 55d4f65
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/components/expanded-state/swap-details/SwapDetailsContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ import { padding } from '@/styles';
import { ethereumUtils } from '@/utils';
import { useNavigation } from '@/navigation';
import { Network } from '@/helpers';
import { SwapDetailsRewardRow } from './SwapDetailsRewardRow';
import useExperimentalFlag, {
OP_REWARDS,
} from '@rainbow-me/config/experimentalHooks';
import config from '@/model/config';

const Container = styled(Box).attrs({
flex: 1,
Expand Down Expand Up @@ -56,6 +61,10 @@ export default function SwapDetailsContent({
outputCurrency?.type
);

const hasReward =
(useExperimentalFlag(OP_REWARDS) || config.op_rewards_enabled) &&
!!tradeDetails.reward?.[0];

return (
<AccentColorProvider color={colorForAsset}>
<Container
Expand Down Expand Up @@ -95,6 +104,9 @@ export default function SwapDetailsContent({
tradeDetails={tradeDetails}
/>
)}
{hasReward && (
<SwapDetailsRewardRow reward={tradeDetails.reward?.[0]} />
)}
{flashbotsEnabled && inputCurrencyNetwork === Network.mainnet && (
<SwapDetailsRow
labelPress={() =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React from 'react';
import { Bleed, Box, Text } from '@/design-system';
import { SwapDetailsLabel } from './SwapDetailsRow';
import { ButtonPressAnimation } from '@/components/animations';
import { Reward } from '@rainbow-me/swaps';
import { useNavigation } from '@/navigation';
import Routes from '@/navigation/routesNames';
import { ChainBadge } from '@/components/coin-icon';
import { AssetTypes } from '@/entities';
import { getNetworkObj } from '@/networks';
import { Network } from '@/networks/types';
import { useTheme } from '@/theme';
import * as i18n from '@/languages';

export function SwapDetailsRewardRow({ reward }: { reward: Reward }) {
const { navigate } = useNavigation();
const { isDarkMode } = useTheme();

const roundedAmount = Math.round(reward.amount * 1000) / 1000;

const opNetwork = getNetworkObj(Network.optimism);
const accentColor = isDarkMode
? opNetwork.colors.dark
: opNetwork.colors.light;

return (
<Box flexDirection="row" alignItems="center" justifyContent="space-between">
<ButtonPressAnimation onPress={() => navigate(Routes.OP_REWARDS_SHEET)}>
<SwapDetailsLabel>
{i18n.t(i18n.l.expanded_state.swap_details.reward)} 􀅵
</SwapDetailsLabel>
</ButtonPressAnimation>
<Bleed vertical="10px">
<Box
flexDirection="row"
alignItems="center"
paddingLeft="4px"
paddingRight="8px"
paddingVertical="4px"
borderRadius={20}
style={{
borderWidth: 1.5,
borderColor: accentColor + '0F',
gap: 5,
}}
>
<ChainBadge assetType={AssetTypes.optimism} position="relative" />
<Text
align="center"
size="14px / 19px (Deprecated)"
weight="bold"
color={{ custom: accentColor }}
>
{roundedAmount || '<0.001'} {reward.token.symbol}
</Text>
</Box>
</Bleed>
</Box>
);
}
1 change: 1 addition & 0 deletions src/languages/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@
}
},
"swap_details": {
"reward": "Reward",
"exchange_rate": "Exchange rate",
"rainbow_fee": "Included Rainbow fee",
"refuel": "Extra network tokens",
Expand Down

0 comments on commit 55d4f65

Please sign in to comment.