Skip to content

Commit

Permalink
Add path for near usdt (#632)
Browse files Browse the repository at this point in the history
* feat: add near--->usdt estimate logic

* feat: add triggle logic

* feat: add exception log

* fix: pool fee issue

* feat: add testnet data

* fix: update tx clear logic

* fix: mint-base wallet issue

* fix: error

* fix: mintbase wallet issue

* feat: remote test log

* feat: remove test log

* Feat new meme xref token

* Fix meme bugs

* feat: add swap double check logic

* fix: ui issue

---------

Co-authored-by: naturexie <[email protected]>
Co-authored-by: lq0-github <[email protected]>
  • Loading branch information
3 people authored Nov 1, 2024
1 parent cc9f3a8 commit 4e2a24a
Show file tree
Hide file tree
Showing 17 changed files with 1,046 additions and 366 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
"react-spinners": "^0.11.0",
"react-toastify": "^9.1.1",
"react-tooltip": "^5.23.0",
"react-use": "17.4.0",
"react-use-websocket": "^4.3.1",
"recharts": "^2.1.6",
"reconnecting-websocket": "^4.4.0",
Expand Down
2 changes: 1 addition & 1 deletion src/components/forms/SelectToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1499,4 +1499,4 @@ export const SelectTokenForList = ({
</div>
</div>
);
};
};
19 changes: 13 additions & 6 deletions src/components/forms/SwapFormWrap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { get_pool_name, openUrl } from '../../services/commonV3';
import { PoolInfo } from 'src/services/swapV3';
import { OutLinkIcon } from '../../components/icon/Common';
import { REF_FI_POOL_ACTIVE_TAB } from '../../pages/pools/utils';
import { INEAR_USDT_SWAP_TODOS } from '../../stores/swapStore';

interface SwapFormWrapProps {
title?: string;
Expand Down Expand Up @@ -54,6 +55,7 @@ interface SwapFormWrapProps {
wrapOperation?: boolean;
isInsufficient?: boolean;
mostPoolDetail?: PoolInfo;
near_usdt_swapTodos?: INEAR_USDT_SWAP_TODOS;
}

export default function SwapFormWrap({
Expand All @@ -76,6 +78,7 @@ export default function SwapFormWrap({
quoteDoneLimit,
isInsufficient,
mostPoolDetail,
near_usdt_swapTodos,
}: React.PropsWithChildren<SwapFormWrapProps>) {
const [error, setError] = useState<Error>();

Expand Down Expand Up @@ -132,13 +135,17 @@ export default function SwapFormWrap({

if (isSignedIn || selectMarket === 'orderly') {
try {
selectMarket !== 'orderly' &&
setShowSwapLoading &&
setShowSwapLoading(true);

selectMarket !== 'orderly' &&
setShowSwapLoading &&
if (near_usdt_swapTodos) {
setLoadingPause(true);
} else {
selectMarket !== 'orderly' &&
setShowSwapLoading &&
setShowSwapLoading(true);

selectMarket !== 'orderly' &&
setLoadingPause &&
setLoadingPause(true);
}
onSubmit(event);
} catch (err) {
setError(err);
Expand Down
11 changes: 9 additions & 2 deletions src/components/layout/SwapDoubleCheck.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ export function DoubleCheckModal(
from: string;
onSwap: (e?: any) => void;
priceImpactValue: string;
isMixBest?: boolean;
}
) {
const { tokenIn, tokenOut, from, onSwap, priceImpactValue } = props;
const { tokenIn, tokenOut, from, onSwap, priceImpactValue, isMixBest } =
props;

const [buttonLoading, setButtonLoading] = useState<boolean>(false);

Expand Down Expand Up @@ -145,8 +147,13 @@ export function DoubleCheckModal(
</OutlineButton>
<SolidButton
onClick={(e) => {
setButtonLoading(true);
if (!isMixBest) {
setButtonLoading(true);
}
onSwap();
if (isMixBest) {
props.onRequestClose(e);
}
}}
className="text-sm w-auto text-center"
padding="px-4 py-1.5"
Expand Down
20 changes: 15 additions & 5 deletions src/components/layout/transactionTipPopUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,23 @@ export const getURLInfo = () => {
const errorCode = new URLSearchParams(search).get('errorCode');

const signInErrorType = new URLSearchParams(search).get('signInErrorType');

const txHashes = (
const selectedWalletId =
window.selector?.store?.getState()?.selectedWalletId ?? '';
let txHashes = [];
const txHashesStr =
new URLSearchParams(search).get(TRANSACTION_WALLET_TYPE.NEAR_WALLET) ||
new URLSearchParams(search).get(TRANSACTION_WALLET_TYPE.SENDER_WALLET) ||
new URLSearchParams(search).get(TRANSACTION_WALLET_TYPE.WalletSelector)
)?.split(',');

new URLSearchParams(search).get(TRANSACTION_WALLET_TYPE.WalletSelector);
if (
selectedWalletId == 'bitte-wallet' ||
selectedWalletId == 'mintbase-wallet'
) {
txHashes = decodeURIComponent(decodeURIComponent(txHashesStr || '')).split(
','
);
} else {
txHashes = (txHashesStr || '').split(',');
}
return {
txHash:
txHashes && txHashes.length > 0 ? txHashes[txHashes.length - 1] : '',
Expand Down
22 changes: 21 additions & 1 deletion src/components/meme/StakingChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,30 @@ const StakingChart = ({ chartType }) => {
if (activeIndex < 0 || activeIndex >= data.length) return null;

const activeEntry = data[activeIndex];
const centerX = 275 / 2;
const imageSize = 44;
const imageX = centerX - imageSize / 2;
const imageY = 66;

return (
<>
<image x="43%" y="24%" width={44} height={44} href={activeEntry.icon} />
<defs>
<clipPath id="roundedImage">
<circle
cx={centerX}
cy={imageY + imageSize / 2}
r={imageSize / 2}
/>
</clipPath>
</defs>
<image
x={imageX}
y={imageY}
width={imageSize}
height={imageSize}
href={activeEntry.icon}
clipPath="url(#roundedImage)"
/>
<text
x="50%"
y="46%"
Expand Down
23 changes: 18 additions & 5 deletions src/components/meme/memeConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ export function getMemeContractConfig(
'memefarm-xref-kat.ref-labs.near',
'memefarm-xref-chill.ref-labs.near',
'memefarm-xref-bd.ref-labs.near',
'memefarm-xref-gnear.ref-labs.near',
'memefarm-xref-illia.ref-labs.near',
'memefarm-xref-gnuff.ref-labs.near',
],
MEME_TOKEN_XREF_MAP: {
'blackdragon.tkn.near': 'memefarm-xref-blackdragon.ref-labs.near',
Expand All @@ -312,6 +315,9 @@ export function getMemeContractConfig(
'kat.token0.near': 'memefarm-xref-kat.ref-labs.near',
'chill-129.meme-cooking.near': 'memefarm-xref-chill.ref-labs.near',
'benthedog.near': 'memefarm-xref-bd.ref-labs.near',
'gnear-229.meme-cooking.near': 'memefarm-xref-gnear.ref-labs.near',
'4illia-222.meme-cooking.near': 'memefarm-xref-illia.ref-labs.near',
'gnuff-283.meme-cooking.near': 'memefarm-xref-gnuff.ref-labs.near',
},
};
}
Expand Down Expand Up @@ -447,10 +453,10 @@ export function getMemeDataConfig(): any {
'kat.token0.near',
],
meme_nonListed_tokens: [
'438e48ed4ce6beecf503d43b9dbd3c30d516e7fd.factory.bridge.near',
'gp.token0.near',
'chill-129.meme-cooking.near',
'benthedog.near',
'ftv2.nekotoken.near',
'gnear-229.meme-cooking.near',
'4illia-222.meme-cooking.near',
'gnuff-283.meme-cooking.near',
],
pie_color: {
'blackdragon.tkn.near': '#413B41',
Expand All @@ -476,6 +482,9 @@ export function getMemeDataConfig(): any {
'kat.token0.near': '#FF795D',
'chill-129.meme-cooking.near': '#5ac8ec',
'benthedog.near': '#6124d9',
'gnear-229.meme-cooking.near': '#77B255',
'4illia-222.meme-cooking.near': '#ECE8C5',
'gnuff-283.meme-cooking.near': '#CD9865',
},
meme_cap_tokens: [
'blackdragon.tkn.near',
Expand All @@ -489,7 +498,7 @@ export function getMemeDataConfig(): any {
'usmeme.tg',
'nkok.tkn.near',
'bean.tkn.near',
'ftv2.nekotoken.near',
// 'ftv2.nekotoken.near',
'marmaj.tkn.near',
'babyblackdragon.tkn.near',
'hat.tkn.near',
Expand All @@ -498,6 +507,10 @@ export function getMemeDataConfig(): any {
'neiro.token0.near',
'corgi.token0.near',
'nearnvidia.near',
'438e48ed4ce6beecf503d43b9dbd3c30d516e7fd.factory.bridge.near',
'gp.token0.near',
'chill-129.meme-cooking.near',
'benthedog.near',
],
};
}
Expand Down
65 changes: 57 additions & 8 deletions src/components/swap/SwapCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ import {
FaExchangeAlt,
MdOutlineRefresh,
} from '../reactIcons';
import SwapMixModal from './SwapMixModal';
import { usePersistSwapStore } from '../../stores/swapStore';

const SWAP_IN_KEY = 'REF_FI_SWAP_IN';
const SWAP_OUT_KEY = 'REF_FI_SWAP_OUT';
Expand Down Expand Up @@ -696,9 +698,12 @@ export default function SwapCard(props: {
swapTab,
globalWhiteListTokens,
} = props;

const {
near_usdt_swapTodos,
near_usdt_swapTodos_transaction,
set_near_usdt_swapTodos_transaction,
} = usePersistSwapStore();
const [doubleCheckOpen, setDoubleCheckOpen] = useState<boolean>(false);

const [supportLedger, setSupportLedger] = useState(
localStorage.getItem(SUPPORT_LEDGER_KEY) ? true : false
);
Expand Down Expand Up @@ -729,6 +734,7 @@ export default function SwapCard(props: {
const [balanceOutDone, setBalanceOutDone] = useState<boolean>(false);
const [tokenDeflationRateData, setTokenDeflationRateData] =
useState<Record<string, any>>();
const [showMixSwapModal, setShowMixSwapModal] = useState<boolean>(false);

const intl = useIntl();
const location = useLocation();
Expand Down Expand Up @@ -922,6 +928,22 @@ export default function SwapCard(props: {
setTokenDeflationRateData(undefined);
}
}, [tokenIn?.id]);
useEffect(() => {
if (
accountId &&
near_usdt_swapTodos_transaction?.accountId == accountId &&
near_usdt_swapTodos_transaction?.process == '1'
) {
setShowMixSwapModal(true);
}
if (
accountId &&
near_usdt_swapTodos_transaction &&
near_usdt_swapTodos_transaction.accountId !== accountId
) {
set_near_usdt_swapTodos_transaction(null);
}
}, [near_usdt_swapTodos_transaction?.process, accountId]);
async function getTokenDeflationRate() {
setTokenDeflationRateData(undefined);
const tokenMeta = await tokenFtMetadata(tokenIn.id);
Expand Down Expand Up @@ -1102,14 +1124,24 @@ export default function SwapCard(props: {

const handleSubmit = (event: React.FormEvent) => {
event.preventDefault();

const ifDoubleCheck =
new BigNumber(tokenInAmount || 0).isLessThanOrEqualTo(
new BigNumber(tokenInMax || 0)
) && Number(selectTrade?.priceImpact || 0) > 2;

if (ifDoubleCheck) setDoubleCheckOpen(true);
else selectTrade && selectTrade.makeSwap();
if (selectTrade.estimatesMix) {
if (near_usdt_swapTodos_transaction?.process == '2') {
set_near_usdt_swapTodos_transaction(null);
}
if (ifDoubleCheck) {
// TODO4
setDoubleCheckOpen(true);
} else {
setShowMixSwapModal(true);
}
} else {
if (ifDoubleCheck) setDoubleCheckOpen(true);
else selectTrade && selectTrade.makeSwap();
}
};
const handleSubmit_wrap = (e: any) => {
e.preventDefault();
Expand Down Expand Up @@ -1176,7 +1208,10 @@ export default function SwapCard(props: {
tokenInAmount,
tokenInAmountInput,
]);

function closeMixSwapModal() {
setShowMixSwapModal(false);
set_near_usdt_swapTodos_transaction(null);
}
return (
<>
<SwapFormWrap
Expand Down Expand Up @@ -1223,6 +1258,7 @@ export default function SwapCard(props: {
setShowSwapLoading,
}}
isInsufficient={isInsufficientBalance && selectMarket !== 'orderly'}
near_usdt_swapTodos={near_usdt_swapTodos}
>
<TokenAmountV3
forSwap
Expand Down Expand Up @@ -1435,7 +1471,16 @@ export default function SwapCard(props: {
tokenIn={tokenIn}
tokenOut={tokenOut}
from={tokenInAmount}
onSwap={() => selectTrade && selectTrade.makeSwap()}
isMixBest={!!selectTrade?.estimatesMix}
onSwap={() => {
if (selectTrade) {
if (selectTrade.estimatesMix) {
setShowMixSwapModal(true);
} else {
selectTrade && selectTrade.makeSwap();
}
}
}}
priceImpactValue={selectTrade?.priceImpact || '0'}
/>

Expand All @@ -1445,6 +1490,10 @@ export default function SwapCard(props: {
}}
isOpen={showSkywardTip}
/>
<SwapMixModal
onRequestClose={closeMixSwapModal}
isOpen={showMixSwapModal}
/>
</>
);
}
Loading

0 comments on commit 4e2a24a

Please sign in to comment.