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: cowSwap some issue ok-34971 ok-34976 ok-34986 #6504

Merged
merged 4 commits into from
Jan 14, 2025
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
19 changes: 15 additions & 4 deletions packages/kit-bg/src/services/ServiceSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,12 @@ export default class ServiceSwap extends ServiceBase {
await this.backgroundApi.simpleDb.swapHistory.deleteSwapHistoryItem(
statuses,
);
const inAppNotification = await inAppNotificationAtom.get();
const deleteHistoryIds = inAppNotification.swapHistoryPendingList
.filter((item) => statuses?.includes(item.status))
.map((item) =>
item.txInfo.useOrderId ? item.txInfo.orderId : item.txInfo.txId,
);
await inAppNotificationAtom.set((pre) => ({
...pre,
swapHistoryPendingList: statuses
Expand All @@ -1005,6 +1011,9 @@ export default class ServiceSwap extends ServiceBase {
)
: [],
}));
await Promise.all(
deleteHistoryIds.map((id) => this.cleanHistoryStateIntervals(id)),
);
}

@backgroundMethod()
Expand All @@ -1014,14 +1023,16 @@ export default class ServiceSwap extends ServiceBase {
orderId?: string;
}) {
await this.backgroundApi.simpleDb.swapHistory.deleteOneSwapHistory(txInfo);
const deleteHistoryId = txInfo.useOrderId
? txInfo.orderId ?? ''
: txInfo.txId ?? '';
await inAppNotificationAtom.set((pre) => ({
...pre,
swapHistoryPendingList: pre.swapHistoryPendingList.filter((item) =>
item.txInfo.useOrderId
? item.txInfo.orderId !== txInfo.orderId
: item.txInfo.txId !== txInfo.txId,
swapHistoryPendingList: pre.swapHistoryPendingList.filter(
(item) => item.txInfo.txId !== deleteHistoryId,
),
}));
await this.cleanHistoryStateIntervals(deleteHistoryId);
}

@backgroundMethod()
Expand Down
9 changes: 9 additions & 0 deletions packages/kit/src/states/jotai/contexts/swap/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,15 @@ class ContentJotaiActionsSwap extends ContextJotaiActionsBase {
txId: undefined,
status: ESwapApproveTransactionStatus.FAILED,
};
} else {
// update quote list
const quoteList = get(swapQuoteListAtom());
const updateQuoteList = quoteList.filter(
(quote) =>
quote.info.provider !== preApproveTx.provider ||
quote.quoteId !== preApproveTx.quoteId,
);
set(swapQuoteListAtom(), [...updateQuoteList]);
}
await backgroundApiProxy.serviceSwap.setApprovingTransaction(
newApproveTx,
Expand Down
2 changes: 2 additions & 0 deletions packages/kit/src/views/Swap/hooks/useSwapBuiltTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export function useSwapBuildTx() {
const isBatchTransfer = useSwapBatchTransfer(
swapFromAddressInfo.networkId,
swapFromAddressInfo.accountInfo?.account?.id,
selectQuote?.providerDisableBatchTransfer,
);

const syncRecentTokenPairs = useCallback(
Expand Down Expand Up @@ -717,6 +718,7 @@ export function useSwapBuildTx() {
provider: selectQuote?.info.provider,
fromToken,
toToken,
quoteId: selectQuote?.quoteId ?? '',
amount,
useAddress: swapFromAddressInfo.address ?? '',
spenderAddress: allowanceInfo.allowanceTarget,
Expand Down
10 changes: 8 additions & 2 deletions packages/kit/src/views/Swap/hooks/useSwapState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ export function useSwapQuoteEventFetching() {
);
}

export function useSwapBatchTransfer(networkId?: string, accountId?: string) {
export function useSwapBatchTransfer(
networkId?: string,
accountId?: string,
providerDisableBatchTransfer?: boolean,
) {
const [settingsPersistAtom] = useSettingsPersistAtom();
const isExternalAccount = accountUtils.isExternalAccount({
accountId: accountId ?? '',
Expand All @@ -133,7 +137,8 @@ export function useSwapBatchTransfer(networkId?: string, accountId?: string) {
return (
settingsPersistAtom.swapBatchApproveAndSwap &&
!isUnSupportBatchTransferNet &&
!isExternalAccount
!isExternalAccount &&
!providerDisableBatchTransfer
);
}

Expand All @@ -159,6 +164,7 @@ export function useSwapActionState() {
const isBatchTransfer = useSwapBatchTransfer(
swapFromAddressInfo.networkId,
swapFromAddressInfo.accountInfo?.account?.id,
quoteCurrentSelect?.providerDisableBatchTransfer,
);
const isRefreshQuote = useMemo(
() => quoteIntervalCount > swapQuoteIntervalMaxCount || shouldRefreshQuote,
Expand Down
1 change: 1 addition & 0 deletions packages/kit/src/views/Swap/hooks/useSwapTxHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export function useSwapTxHistoryActions() {
swapTxInfo.swapBuildResData.result.fee?.otherFeeInfos ?? [],
orderId: swapTxInfo.swapBuildResData.orderId,
supportUrl: swapTxInfo.swapBuildResData.result.supportUrl,
orderSupportUrl: swapTxInfo.swapBuildResData.result.orderSupportUrl,
},
ctx: swapTxInfo.swapBuildResData.ctx,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ const SwapActionsState = ({
const isBatchTransfer = useSwapBatchTransfer(
swapFromAddressInfo.networkId,
swapFromAddressInfo.accountInfo?.account?.id,
currentQuoteRes?.providerDisableBatchTransfer,
);
const swapRecipientAddressInfo = useSwapRecipientAddressInfo(
swapEnableRecipientAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,14 @@ const SwapHistoryDetailModal = () => {
label="Order ID"
renderContent={txHistory.txInfo.orderId}
showCopy
{...(txHistory.swapInfo.orderSupportUrl
? {
openWithUrl: () =>
onViewInBrowser(
txHistory.swapInfo.orderSupportUrl ?? '',
),
}
: {})}
ezailWang marked this conversation as resolved.
Show resolved Hide resolved
/>
) : null}
<InfoItem
Expand Down Expand Up @@ -386,6 +394,7 @@ const SwapHistoryDetailModal = () => {
);
}, [
intl,
onViewInBrowser,
renderNetworkFee,
renderRate,
renderSwapAssetsChange,
Expand Down
4 changes: 4 additions & 0 deletions packages/shared/types/swap/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export interface ISwapApproveTransaction {
fromToken: ISwapToken;
toToken: ISwapToken;
provider: string;
quoteId: string;
useAddress: string;
spenderAddress: string;
amount: string;
Expand Down Expand Up @@ -273,11 +274,13 @@ export interface IFetchQuoteResult {
};
protocolNoRouterInfo?: string;
supportUrl?: string;
orderSupportUrl?: string;
isAntiMEV?: boolean;
tokenMetadata?: ISwapTokenMetadata;
quoteShowTip?: IQuoteTip;
gasLimit?: number;
slippage?: number;
providerDisableBatchTransfer?: boolean;
}

export interface IAllowanceResult {
Expand Down Expand Up @@ -571,6 +574,7 @@ export interface ISwapTxHistory {
otherFeeInfos?: IQuoteResultFeeOtherFeeInfo[];
orderId?: string;
supportUrl?: string;
orderSupportUrl?: string;
};
date: {
created: number;
Expand Down
Loading