Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/swap-slide' into tmp/20241218
Browse files Browse the repository at this point in the history
  • Loading branch information
dmy147 committed Dec 18, 2024
2 parents f73c656 + b739877 commit b1f6eeb
Show file tree
Hide file tree
Showing 31 changed files with 1,135 additions and 1,534 deletions.
7 changes: 6 additions & 1 deletion _raw/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -872,10 +872,12 @@
"price-expired-refresh-quote": "Price expired. Refresh quote.",
"approve-x-symbol": "Approve {{symbol}}",
"approve-and-swap": "Approve and Swap via {{name}}",
"approve-swap": "Approve and Swap",
"swap-via-x": "Swap via {{name}}",
"get-quotes": "Get quotes",
"chain": "Chain",
"swap-from": "Swap from",
"from": "From",
"to": "To",
"search-by-name-address": "Search by Name / Address",
"amount-in": "Amount in {{symbol}}",
Expand Down Expand Up @@ -1005,6 +1007,7 @@
"est-difference": "Est. Difference:",
"loss-tips": "You're losing {{usd}}. Try a different amount.",
"price-impact": "Price Impact",
"max-tips": "This value is calculated by subtracting the gas cost for bridge.",
"showMore": {
"title": "Show More",
"source": "Bridge Source"
Expand Down Expand Up @@ -2554,7 +2557,9 @@
},
"noTokens": "No Tokens",
"noMatch": "No Match",
"noMatchSuggestion": "Try to search contract address on {{ chainName }}"
"noMatchSuggestion": "Try to search contract address on {{ chainName }}",
"hot": "Hot",
"recent": "Recent"
},
"ModalPreviewNFTItem": {
"FieldLabel": {
Expand Down
2 changes: 2 additions & 0 deletions src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1757,6 +1757,8 @@ export class WalletController extends BaseController {
setAutoSlippage = swapService.setAutoSlippage;
setIsCustomSlippage = swapService.setIsCustomSlippage;
setSlippage = swapService.setSlippage;
getRecentSwapToTokens = swapService.getRecentSwapToTokens;
setRecentSwapToToken = swapService.setRecentSwapToToken;

setRedirect2Points = RabbyPointsService.setRedirect2Points;
setRabbyPointsSignature = RabbyPointsService.setSignature;
Expand Down
17 changes: 17 additions & 0 deletions src/background/service/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type SwapServiceStore = {
autoSlippage: boolean;
isCustomSlippage?: boolean;
slippage: string;
recentToTokens?: TokenItem[];

/**
* @deprecated
Expand Down Expand Up @@ -59,6 +60,7 @@ class SwapService {
preferMEVGuarded: false,
autoSlippage: true,
slippage: '0.1',
recentToTokens: [],
};

init = async () => {
Expand All @@ -75,6 +77,7 @@ class SwapService {
sortIncludeGasFee: true,
autoSlippage: true,
slippage: '0.1',
recentToTokens: [],
},
});
if (storage) {
Expand Down Expand Up @@ -258,6 +261,20 @@ class SwapService {
setSlippage = (slippage: string) => {
this.store.slippage = slippage;
};

getRecentSwapToTokens = () => {
return this.store.recentToTokens || [];
};

setRecentSwapToToken = (token: TokenItem) => {
const recentToTokens = this.store.recentToTokens || [];
this.store.recentToTokens = [
token,
...recentToTokens.filter(
(item) => item.id !== token.id || item.chain !== token.chain
),
].slice(0, 5);
};
}

export default new SwapService();
3 changes: 3 additions & 0 deletions src/ui/assets/swap/arrow-down-cc.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/ui/assets/swap/best-quote-sharp-bg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/ui/assets/swap/wallet-cc.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 20 additions & 3 deletions src/ui/component/ChainSelector/InForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { SelectChainListProps } from '@/ui/component/ChainSelector/components/Se
import ChainSelectorModal from '@/ui/component/ChainSelector/Modal';
import styled from 'styled-components';
import ChainIcon from '@/ui/component/ChainIcon';
import { ReactComponent as RcImgArrowDown } from '@/ui/assets/swap/arrow-down.svg';
import { ReactComponent as RcImgArrowDownCC } from '@/ui/assets/swap/arrow-down-cc.svg';
import { useWallet } from '@/ui/utils';
import { findChain } from '@/utils/chain';
import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -43,6 +43,16 @@ const ChainWrapper = styled.div`
}
}
}
&.inlineHover {
background: transparent;
&:hover {
background: transparent;
.name,
.down {
color: var(--r-blue-default, #7084ff);
}
}
}
&:hover {
background: rgba(134, 151, 255, 0.2);
}
Expand All @@ -51,6 +61,7 @@ const ChainWrapper = styled.div`
margin-left: auto;
width: 20px;
height: 20px;
color: var(--r-neutral-body, #3e495e);
}
.name {
color: var(--r-neutral-title-1, #192945);
Expand All @@ -65,12 +76,14 @@ export const ChainRender = ({
className,
arrowDownComponent,
mini,
inlineHover,
...other
}: {
chain?: CHAINS_ENUM;
readonly: boolean;
arrowDownComponent?: React.ReactNode;
mini?: boolean;
inlineHover?: boolean;
} & InsHTMLAttributes<HTMLDivElement>) => {
const wallet = useWallet();
const { t } = useTranslation();
Expand All @@ -94,7 +107,8 @@ export const ChainRender = ({
className={clsx(
{
'cursor-default hover:bg-r-neutral-bg-2': readonly,
mini: mini,
mini,
inlineHover,
},
className
)}
Expand All @@ -117,7 +131,7 @@ export const ChainRender = ({
(arrowDownComponent ? (
arrowDownComponent
) : (
<RcImgArrowDown className="down" viewBox="0 0 20 20" />
<RcImgArrowDownCC className="down" viewBox="0 0 20 20" />
))}
</ChainWrapper>
);
Expand All @@ -139,6 +153,7 @@ interface ChainSelectorProps {
excludeChains?: CHAINS_ENUM[];
drawerHeight?: number;
showClosableIcon?: boolean;
inlineHover?: boolean;
}
export default function ChainSelectorInForm({
value,
Expand All @@ -155,6 +170,7 @@ export default function ChainSelectorInForm({
excludeChains,
drawerHeight,
showClosableIcon,
inlineHover,
}: ChainSelectorProps) {
const [showSelectorModal, setShowSelectorModal] = useState(showModal);

Expand Down Expand Up @@ -183,6 +199,7 @@ export default function ChainSelectorInForm({
className={chainRenderClassName}
arrowDownComponent={arrowDownComponent}
mini={mini}
inlineHover={inlineHover}
/>
{!readonly && (
<ChainSelectorModal
Expand Down
9 changes: 8 additions & 1 deletion src/ui/component/TokenSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,14 @@ const TokenSelect = ({
).filter((e) => !excludeTokens.includes(e.id));
}, [allDisplayTokens, searchedTokenByQuery, excludeTokens, queryConds]);

const displayTokenList = useSortToken(availableToken);
const displaySortedTokenList = useSortToken(availableToken);

const displayTokenList = useMemo(() => {
if (type === 'swapTo') {
return availableToken;
}
return displaySortedTokenList;
}, [availableToken, displaySortedTokenList, type]);

const isListLoading = queryConds.keyword
? isSearchLoading
Expand Down
Loading

0 comments on commit b1f6eeb

Please sign in to comment.