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

Danh/bug type swap #1206

Merged
merged 5 commits into from
Aug 5, 2022
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
2 changes: 1 addition & 1 deletion src/components/swapv2/PairSuggestion/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export default forwardRef<HTMLInputElement, Props>(function SearchComponent(
ref={ref}
hasBorder={hasBorder}
onBlur={onBlurInput}
onClick={showListViewWithTracking}
onFocus={disabled ? undefined : showListViewWithTracking}
placeholder={t`You can try "10 ETH to KNC"`}
value={value}
onChange={onChange}
Expand Down
21 changes: 13 additions & 8 deletions src/components/swapv2/PairSuggestion/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { t } from '@lingui/macro'
import { debounce } from 'lodash'
import { stringify } from 'qs'
import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react'
import { BrowserView, MobileView, isMobile } from 'react-device-detect'
import { BrowserView, MobileView, isIOS, isMobile } from 'react-device-detect'
import { useHistory } from 'react-router-dom'
import styled from 'styled-components'

Expand Down Expand Up @@ -91,16 +91,21 @@ export default forwardRef<PairSuggestionHandle, Props>(function PairSuggestionIn
const input = refInput.current
if (!input) return
input.focus()
input?.setSelectionRange(searchQuery.length, searchQuery.length) // fix focus input cursor at front (ios)
if (isIOS) input?.setSelectionRange(searchQuery.length, searchQuery.length) // fix focus input cursor at front (ios)
}

const refKeywordSearching = useRef('')
const searchSuggestionPair = (keyword = '') => {
refKeywordSearching.current = keyword
reqGetSuggestionPair(chainId, account, keyword)
.then(({ recommendedPairs = [], favoritePairs = [], amount }) => {
setSuggestions(findLogoAndSortPair(activeTokens, recommendedPairs, chainId))
setListFavorite(findLogoAndSortPair(activeTokens, favoritePairs, chainId))
setSuggestedAmount(amount || '')
if (!keyword) setTotalFavoritePair(favoritePairs.length)
// make sure same query when typing too fast
if (refKeywordSearching.current === keyword) {
setSuggestions(findLogoAndSortPair(activeTokens, recommendedPairs, chainId))
setListFavorite(findLogoAndSortPair(activeTokens, favoritePairs, chainId))
setSuggestedAmount(amount || '')
if (!keyword) setTotalFavoritePair(favoritePairs.length)
}
})
.catch(e => {
console.log(e)
Expand All @@ -110,7 +115,7 @@ export default forwardRef<PairSuggestionHandle, Props>(function PairSuggestionIn
keyword && mixpanelHandler(MIXPANEL_TYPE.TAS_TYPING_KEYWORD, keyword)
}

const searchDebounce = useCallback(debounce(searchSuggestionPair, 300), [chainId, account])
const searchDebounce = useCallback(debounce(searchSuggestionPair, 100), [chainId, account])
const notify = useNotify()
const addToFavorite = (item: SuggestionPairData) => {
focusInput()
Expand Down Expand Up @@ -219,7 +224,7 @@ export default forwardRef<PairSuggestionHandle, Props>(function PairSuggestionIn
const fromToken = findToken(item.tokenIn)
const toToken = findToken(item.tokenOut)
onSelectSuggestedPair(fromToken, toToken, suggestedAmount)
setIsShowListPair(false)
hideListView()
}

useImperativeHandle(ref, () => ({
Expand Down
2 changes: 1 addition & 1 deletion src/state/application/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export enum NotificationType {
export const useNotify = () => {
const addPopup = useAddPopup()
return useCallback(
(data: PopupContentSimple, removeAfterMs = 3000) => {
(data: PopupContentSimple, removeAfterMs = 4000) => {
addPopup(data, PopupType.SIMPLE, data.title, removeAfterMs)
},
[addPopup],
Expand Down