Skip to content

Commit

Permalink
Fix/market cell bug OK-17507 & ok-17539 (#2594)
Browse files Browse the repository at this point in the history
  • Loading branch information
ezailWang authored Feb 20, 2023
1 parent 858c1b7 commit 6ba8165
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/components/src/hooks/useDropdownPosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ModalRefStore } from '../Modal';
import type { IDropdownPosition, IDropdownProps, SelectProps } from '../Select';
import type { View } from 'react-native';

interface UseDropdownProps {
export interface UseDropdownProps {
dropdownPosition?: IDropdownPosition;
triggerEle?: SelectProps['triggerEle'];
visible?: boolean;
Expand Down
26 changes: 25 additions & 1 deletion packages/kit-bg/src/services/ServiceMarket.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { debounce } from 'lodash';

import type { ISimpleSearchHistoryToken } from '@onekeyhq/engine/src/dbs/simple/entity/SimpleDbEntityMarket';
import simpleDb from '@onekeyhq/engine/src/dbs/simple/simpleDb';
import { formatServerToken } from '@onekeyhq/engine/src/managers/token';
Expand Down Expand Up @@ -32,6 +34,7 @@ import { getDefaultLocale } from '@onekeyhq/kit/src/utils/locale';
import {
backgroundClass,
backgroundMethod,
bindThis,
} from '@onekeyhq/shared/src/background/backgroundDecorators';
import { fetchData } from '@onekeyhq/shared/src/background/backgroundUtils';

Expand Down Expand Up @@ -80,7 +83,28 @@ export default class ServiceMarket extends ServiceBase {
this.backgroundApi.dispatch(updateSelectedCategory(category.categoryId));
}

// fix desktop quickly click the Cancel Like button to trigger the change of the like favorites ids, resulting in a pull action.

// eslint-disable-next-line @typescript-eslint/unbound-method
_fetchMarketListDebounced = debounce(this.fetchMarketList, 1200, {
leading: false,
trailing: true,
});

@backgroundMethod()
async fetchMarketListDebounced({
categoryId,
ids,
sparkline,
}: {
categoryId?: string;
ids?: string;
sparkline?: boolean;
}) {
await this._fetchMarketListDebounced({ categoryId, ids, sparkline });
}

@bindThis()
async fetchMarketList({
categoryId,
ids,
Expand Down Expand Up @@ -247,7 +271,7 @@ export default class ServiceMarket extends ServiceBase {
);
// updata tokenItem for redux
if (data.length > 0) {
this.fetchMarketList({
this.fetchMarketListDebounced({
ids: data.join(','),
sparkline: false,
});
Expand Down
3 changes: 2 additions & 1 deletion packages/kit/src/store/reducers/market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,9 @@ export const MarketSlicer = createSlice({
if (!cacheCategory.coingeckoIds) {
cacheCategory.coingeckoIds = fetchCoingeckoIds;
} else if (
// fix local favorite id go to void,so favorite category's ids need update
// ban favorite category coingecko ids change
cacheCategory.categoryId !== MARKET_FAVORITES_CATEGORYID &&
// cacheCategory.categoryId !== MARKET_FAVORITES_CATEGORYID &&
!equalStringArr(cacheCategory.coingeckoIds, fetchCoingeckoIds) &&
state.listSort === null
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export const showMarketCellMoreMenu = (
triggerEle={triggerEle}
closeOverlay={closeOverlay}
modalProps={modalProps}
useDropdownProps={{ autoAdjust: true }}
>
<MarketCellMoreMenu closeOverlay={closeOverlay} token={token} />
</OverlayPanel>
Expand Down
6 changes: 3 additions & 3 deletions packages/kit/src/views/Market/hooks/useMarketList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ export const useMarketList = ({
checkFavoritesFetch
) {
if (!listSort) {
backgroundApiProxy.serviceMarket.fetchMarketList({
backgroundApiProxy.serviceMarket.fetchMarketListDebounced({
categoryId: selectedCategory.categoryId,
ids: coingeckoIds,
sparkline: !isVerticalLlayout && !isMidLayout,
});
}
timer = setInterval(() => {
backgroundApiProxy.serviceMarket.fetchMarketList({
backgroundApiProxy.serviceMarket.fetchMarketListDebounced({
categoryId: selectedCategory.categoryId,
ids: coingeckoIds,
sparkline: !isVerticalLlayout && !isMidLayout,
Expand All @@ -98,7 +98,7 @@ export const useMarketList = ({
const onRefreshingMarketList = useCallback(async () => {
await backgroundApiProxy.serviceMarket.fetchMarketCategorys();
if (selectedCategory) {
await backgroundApiProxy.serviceMarket.fetchMarketList({
await backgroundApiProxy.serviceMarket.fetchMarketListDebounced({
categoryId: selectedCategory.categoryId,
ids: coingeckoIds,
sparkline: !isVerticalLlayout && !isMidLayout,
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/views/Market/hooks/useMarketSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const useMarketSearchSelectedCategory = () => {

useEffect(() => {
if (searchTabCategoryId) {
backgroundApiProxy.serviceMarket.fetchMarketList({
backgroundApiProxy.serviceMarket.fetchMarketListDebounced({
categoryId: searchTabCategoryId,
sparkline: false,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/views/Market/hooks/useMarketToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const useMarketTokenItem = ({
useEffect(() => {
if (coingeckoId?.length) {
if (!isList && !marketTokenItem) {
backgroundApiProxy.serviceMarket.fetchMarketList({
backgroundApiProxy.serviceMarket.fetchMarketListDebounced({
ids: coingeckoId,
sparkline: !isVertical && !isMidLayout,
});
Expand Down
15 changes: 7 additions & 8 deletions packages/kit/src/views/Overlay/OverlayPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ import {
useSafeAreaInsets,
useThemeValue,
} from '@onekeyhq/components';
import type { UseDropdownProps } from '@onekeyhq/components/src/hooks/useDropdownPosition';
import { useDropdownPosition } from '@onekeyhq/components/src/hooks/useDropdownPosition';
import type { ModalProps } from '@onekeyhq/components/src/Modal';
import type {
IDropdownPosition,
SelectProps,
} from '@onekeyhq/components/src/Select';
import type { SelectProps } from '@onekeyhq/components/src/Select';
import { CloseBackDrop } from '@onekeyhq/components/src/Select';

import type { IBoxProps } from 'native-base';
Expand Down Expand Up @@ -70,13 +68,13 @@ const DesktopDropdown: FC<{
closeOverlay: () => void;
triggerEle?: SelectProps['triggerEle'];
dropdownStyle?: IBoxProps;
dropdownPosition?: IDropdownPosition;
useDropdownProps?: UseDropdownProps;
}> = ({
closeOverlay,
children,
triggerEle,
dropdownStyle,
dropdownPosition,
useDropdownProps,
}) => {
const translateY = 2;
const contentRef = useRef();
Expand All @@ -86,8 +84,9 @@ const DesktopDropdown: FC<{
triggerEle,
visible: true,
translateY,
dropdownPosition: dropdownPosition ?? 'right',
dropdownPosition: 'right',
autoAdjust: false,
...useDropdownProps,
});
return (
<Box position="absolute" w="full" h="full">
Expand Down Expand Up @@ -131,7 +130,7 @@ export const OverlayPanel: FC<{
triggerEle?: SelectProps['triggerEle'];
modalProps?: ModalProps;
modalLizeProps?: ModalizeProps;
dropdownPosition?: IDropdownPosition;
useDropdownProps?: UseDropdownProps;
dropdownStyle?: IBoxProps;
}> = (props) => {
const isVerticalLayout = useIsVerticalLayout();
Expand Down

0 comments on commit 6ba8165

Please sign in to comment.