Skip to content

Commit

Permalink
Merge branch 'main' into feat/earn-landing
Browse files Browse the repository at this point in the history
  • Loading branch information
viet-nv authored Dec 23, 2024
2 parents 486d2a7 + db1a67c commit 7764dc4
Show file tree
Hide file tree
Showing 16 changed files with 113 additions and 135 deletions.
65 changes: 21 additions & 44 deletions public/christmas-logo-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ const HeaderLinks = styled(Row)`

const IconImage = styled.img<{ isChristmas?: boolean }>`
width: 140px;
margin-top: ${({ isChristmas }) => (isChristmas ? '-18px' : '1px')};
margin-top: ${({ isChristmas }) => (isChristmas ? '-9px' : '1px')};
${({ theme, isChristmas }) => theme.mediaWidth.upToSmall`
width: 114px;
margin-top: ${isChristmas ? '-10px' : '1px'};
margin-top: ${isChristmas ? '-2px' : '1px'};
`};
${({ theme }) => theme.mediaWidth.upToExtraSmall`
Expand Down Expand Up @@ -195,7 +195,7 @@ export default function Header() {
<Title to={`${APP_PATHS.SWAP}/${networkInfo.route}`}>
{holidayMode ? (
<LogoIcon>
<IconImage isChristmas src={'/christmas-logo-dark.svg'} alt="logo" />
<IconImage isChristmas src={'/christmas-logo-dark.svg?'} alt="logo" />
</LogoIcon>
) : (
<LogoIcon>
Expand Down
2 changes: 1 addition & 1 deletion src/components/SwapForm/SwapModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
TransactionSubmittedContent,
} from 'components/TransactionConfirmationModal'
import { useActiveWeb3React } from 'hooks'
import { permitError } from 'state/user/actions'
import { permitError } from 'state/swap/actions'
import { captureSwapError } from 'utils/sentry'

import ConfirmSwapModalContent from './ConfirmSwapModalContent'
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/Trades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import { useAllCurrencyCombinations } from 'hooks/useAllCurrencyCombinations'
import useDebounce from 'hooks/useDebounce'
import { AppState } from 'state'
import { useAllDexes, useExcludeDexes } from 'state/customizeDexes/hooks'
import { usePermitData } from 'state/swap/hooks'
import { useAllTransactions } from 'state/transactions/hooks'
import { usePermitData, useUserSlippageTolerance } from 'state/user/hooks'
import { useUserSlippageTolerance } from 'state/user/hooks'
import { isAddress } from 'utils'
import { Aggregator } from 'utils/aggregator'

Expand Down
4 changes: 2 additions & 2 deletions src/hooks/usePermit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { useActiveWeb3React, useWeb3React } from 'hooks'
import { useNotify } from 'state/application/hooks'
import { WrappedTokenInfo } from 'state/lists/wrappedTokenInfo'
import { useSingleCallResult } from 'state/multicall/hooks'
import { permitUpdate } from 'state/user/actions'
import { usePermitData } from 'state/user/hooks'
import { permitUpdate } from 'state/swap/actions'
import { usePermitData } from 'state/swap/hooks'
import { friendlyError } from 'utils/errorMessage'

import { useReadingContract } from './useContract'
Expand Down
11 changes: 5 additions & 6 deletions src/pages/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as Sentry from '@sentry/react'
import { Suspense, lazy, useEffect } from 'react'
import { isMobile } from 'react-device-detect'
import { Navigate, Route, Routes, useLocation, useParams } from 'react-router-dom'
import { useNetwork, usePrevious } from 'react-use'
import styled from 'styled-components'
Expand All @@ -15,7 +14,6 @@ import Header from 'components/Header'
import Loader from 'components/LocalLoader'
import ModalsGlobal from 'components/ModalsGlobal'
import ProtectedRoute from 'components/ProtectedRoute'
import Snowfall from 'components/Snowflake/Snowfall'
import SupportButton from 'components/SupportButton'
import { APP_PATHS, CHAINS_SUPPORT_CROSS_CHAIN } from 'constants/index'
import { CLASSIC_NOT_SUPPORTED, ELASTIC_NOT_SUPPORTED, NETWORKS_INFO, SUPPORTED_NETWORKS } from 'constants/networks'
Expand All @@ -26,7 +24,6 @@ import useSessionExpiredGlobal from 'hooks/useSessionExpire'
import { useSyncNetworkParamWithStore } from 'hooks/web3/useSyncNetworkParamWithStore'
import { PROFILE_MANAGE_ROUTES } from 'pages/NotificationCenter/const'
import { RedirectPathToSwapV3Network } from 'pages/SwapV3/redirects'
import { useHolidayMode } from 'state/user/hooks'
import { isSupportLimitOrder } from 'utils'

import VerifyAuth from './Verify/VerifyAuth'
Expand Down Expand Up @@ -214,7 +211,7 @@ export default function App() {
useGlobalMixpanelEvents()
const isPartnerSwap = pathname.includes(APP_PATHS.PARTNER_SWAP)
const showFooter = !pathname.includes(APP_PATHS.ABOUT) && !isPartnerSwap
const [holidayMode] = useHolidayMode()
//const [holidayMode] = useHolidayMode()

const snowflake = new Image()
snowflake.src = snow
Expand All @@ -230,15 +227,17 @@ export default function App() {
<Header />
</HeaderWrapper>
<Suspense fallback={<Loader />}>
{holidayMode && (
{/*
holidayMode && (
<Snowfall
speed={[0.5, 1]}
wind={[-0.5, 0.25]}
snowflakeCount={isMobile ? 13 : 31}
images={[snowflake]}
radius={[5, 15]}
/>
)}
)
*/}

<BodyWrapper>
<Popups />
Expand Down
3 changes: 2 additions & 1 deletion src/pages/PartnerSwap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import { TAB, isSettingTab } from 'pages/SwapV3'
import Header from 'pages/SwapV3/Header'
import Updater from 'state/customizeDexes/updater'
import { Field } from 'state/swap/actions'
import { useDegenModeManager, usePermitData, useUserSlippageTolerance, useUserTransactionTTL } from 'state/user/hooks'
import { usePermitData } from 'state/swap/hooks'
import { useDegenModeManager, useUserSlippageTolerance, useUserTransactionTTL } from 'state/user/hooks'
import { useCurrencyBalances } from 'state/wallet/hooks'
import { TransactionFlowState } from 'types/TransactionFlowState'
import { DetailedRouteSummary } from 'types/route'
Expand Down
4 changes: 2 additions & 2 deletions src/pages/SwapV3/PopulatedSwapForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { useLocation, useSearchParams } from 'react-router-dom'
import SwapForm, { SwapFormProps } from 'components/SwapForm'
import { APP_PATHS } from 'constants/index'
import { Field } from 'state/swap/actions'
import { useInputCurrency, useOutputCurrency, useSwapActionHandlers } from 'state/swap/hooks'
import { useDegenModeManager, usePermitData, useUserSlippageTolerance, useUserTransactionTTL } from 'state/user/hooks'
import { useInputCurrency, useOutputCurrency, usePermitData, useSwapActionHandlers } from 'state/swap/hooks'
import { useDegenModeManager, useUserSlippageTolerance, useUserTransactionTTL } from 'state/user/hooks'
import { useCurrencyBalances } from 'state/wallet/hooks'
import { DetailedRouteSummary } from 'types/route'

Expand Down
10 changes: 10 additions & 0 deletions src/state/swap/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,13 @@ export const replaceSwapState = createAction<{
export const setRecipient = createAction<{ recipient: string | null }>('swap/setRecipient')
export const setTrendingSoonShowed = createAction('swap/setTrendingSoonShowed')
export const setTrade = createAction<{ trade: Aggregator | undefined }>('swap/setTrade')
export const permitUpdate = createAction<{
chainId: number
address: string
rawSignature: string
deadline: number
value: string
account: string
}>('swap/permitUpdate')
export const revokePermit = createAction<{ chainId: number; address: string; account: string }>('swap/revokePermit')
export const permitError = createAction<{ chainId: number; address: string; account: string }>('swap/permitError')
10 changes: 10 additions & 0 deletions src/state/swap/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { CORRELATED_COINS_ADDRESS, DEFAULT_OUTPUT_TOKEN_BY_CHAIN, NativeCurrenci
import { useActiveWeb3React } from 'hooks'
import { useAllTokens, useCurrencyV2, useStableCoins } from 'hooks/Tokens'
import { NETWORKS_INFO } from 'hooks/useChainsConfig'
import { useAppSelector } from 'state/hooks'
import { AppDispatch, AppState } from 'state/index'
import { Field, resetSelectCurrency, setRecipient, setTrade, typeInput } from 'state/swap/actions'
import { SwapState } from 'state/swap/reducer'
Expand Down Expand Up @@ -325,3 +326,12 @@ export const useSwitchPairToLimitOrder = () => {
[networkInfo, inputCurrencyId, outputCurrencyId, navigate],
)
}

export const usePermitData: (
address?: string,
) => { rawSignature?: string; deadline?: number; value?: string; errorCount?: number } | null = address => {
const { chainId, account } = useActiveWeb3React()
const permitData = useAppSelector(state => state.swap.permitData)

return address && account && permitData ? permitData[account]?.[chainId]?.[address] : null
}
50 changes: 50 additions & 0 deletions src/state/swap/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import { Aggregator } from 'utils/aggregator'

import {
Field,
permitError,
permitUpdate,
replaceSwapState,
resetSelectCurrency,
revokePermit,
setRecipient,
setTrade,
setTrendingSoonShowed,
Expand Down Expand Up @@ -35,6 +38,19 @@ export interface SwapState {
readonly txHash: string | undefined

readonly isSelectTokenManually: boolean

permitData?: {
[account: string]: {
[chainId: number]: {
[address: string]: {
rawSignature?: string
deadline?: number
value?: string
errorCount?: number
} | null
}
}
}
}

// const { search, pathname } = window.location
Expand All @@ -44,6 +60,7 @@ export interface SwapState {

const initialState: SwapState = {
independentField: Field.INPUT,
permitData: {},
typedValue: '1',
// [Field.INPUT]: {
// currencyId: inputCurrency?.toString() || '',
Expand Down Expand Up @@ -137,5 +154,38 @@ export default createReducer<SwapState>(initialState, builder =>
})
.addCase(setTrade, (state, { payload: { trade } }) => {
state.trade = trade
})
.addCase(permitUpdate, (state, { payload: { chainId, address, rawSignature, deadline, value, account } }) => {
if (!state.permitData) state.permitData = {}
if (!state.permitData[account]) state.permitData[account] = {}
if (!state.permitData[account][chainId]) state.permitData[account][chainId] = {}

state.permitData[account][chainId][address] = {
rawSignature,
deadline,
value,
errorCount: state.permitData[account][chainId][address]?.errorCount || 0,
}
})
.addCase(revokePermit, (state, { payload: { chainId, address, account } }) => {
if (
!state.permitData ||
!state.permitData[account] ||
!state.permitData[account][chainId] ||
!state.permitData[account][chainId][address]
)
return

state.permitData[account][chainId][address] = null
})
.addCase(permitError, (state, { payload: { chainId, address, account } }) => {
if (!state.permitData?.[account]?.[chainId]?.[address]) return
const { errorCount } = state.permitData[account][chainId][address] || {}
state.permitData[account][chainId][address] = {
rawSignature: undefined,
deadline: undefined,
value: undefined,
errorCount: (errorCount || 0) + 1,
}
}),
)
2 changes: 1 addition & 1 deletion src/state/transactions/updater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useActiveWeb3React, useWeb3React } from 'hooks'
import useMixpanel, { MIXPANEL_TYPE, NEED_CHECK_SUBGRAPH_TRANSACTION_TYPES } from 'hooks/useMixpanel'
import { useBlockNumber, useKyberSwapConfig, useTransactionNotify } from 'state/application/hooks'
import { AppDispatch, AppState } from 'state/index'
import { revokePermit } from 'state/user/actions'
import { revokePermit } from 'state/swap/actions'
import { findTx } from 'utils'

import { checkedTransaction, finalizeTransaction, modifyTransaction, removeTx, replaceTx } from './actions'
Expand Down
10 changes: 0 additions & 10 deletions src/state/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,6 @@ export const updateTokenAnalysisSettings = createAction<string>('user/updateToke
export const updateAcceptedTermVersion = createAction<number | null>('user/updateAcceptedTermVersion')
export const changeViewMode = createAction<VIEW_MODE>('user/changeViewMode')
export const toggleHolidayMode = createAction<void>('user/toggleHolidayMode')
export const permitUpdate = createAction<{
chainId: number
address: string
rawSignature: string
deadline: number
value: string
account: string
}>('user/permitUpdate')
export const revokePermit = createAction<{ chainId: number; address: string; account: string }>('user/revokePermit')
export const permitError = createAction<{ chainId: number; address: string; account: string }>('user/permitError')
export const pinSlippageControl = createAction<boolean>('user/pinSlippageControl')
export const toggleMyEarningChart = createAction<void>('user/toggleMyEarningChart')

Expand Down
16 changes: 3 additions & 13 deletions src/state/user/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import {
updateUserSlippageTolerance,
} from 'state/user/actions'
import { CROSS_CHAIN_SETTING_DEFAULT, CrossChainSetting, VIEW_MODE } from 'state/user/reducer'
import { isAddress } from 'utils'
import { isAddress, isChristmasTime } from 'utils'

const MAX_FAVORITE_LIMIT = 12

Expand Down Expand Up @@ -439,14 +439,13 @@ export const usePaymentToken: () => [Token | null, (paymentToken: Token | null)

export const useHolidayMode: () => [boolean, () => void] = () => {
const dispatch = useAppDispatch()
// const holidayMode = useAppSelector(state => (state.user.holidayMode === undefined ? true : state.user.holidayMode))
const holidayMode = useAppSelector(state => (state.user.holidayMode === undefined ? true : state.user.holidayMode))

const toggle = useCallback(() => {
dispatch(toggleHolidayMode())
}, [dispatch])

// return [isChristmasTime() ? holidayMode : false, toggle]
return [false, toggle]
return [isChristmasTime() ? holidayMode : false, toggle]
}

export const useCrossChainSetting = () => {
Expand Down Expand Up @@ -508,15 +507,6 @@ export const useSlippageSettingByPage = () => {
}
}

export const usePermitData: (
address?: string,
) => { rawSignature?: string; deadline?: number; value?: string; errorCount?: number } | null = address => {
const { chainId, account } = useActiveWeb3React()
const permitData = useAppSelector(state => state.user.permitData)

return address && account && permitData ? permitData[account]?.[chainId]?.[address] : null
}

export const useShowMyEarningChart: () => [boolean, () => void] = () => {
const dispatch = useAppDispatch()

Expand Down
49 changes: 0 additions & 49 deletions src/state/user/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ import {
addSerializedPair,
addSerializedToken,
changeViewMode,
permitError,
permitUpdate,
pinSlippageControl,
removeSerializedPair,
removeSerializedToken,
revokePermit,
setCrossChainSetting,
setPaymentToken,
toggleFavoriteToken,
Expand Down Expand Up @@ -108,19 +105,6 @@ export interface UserState {
viewMode: VIEW_MODE
paymentToken: Token | null
holidayMode: boolean
permitData: {
[account: string]: {
[chainId: number]: {
[address: string]: {
rawSignature?: string
deadline?: number
value?: string
errorCount?: number
} | null
}
}
}

isSlippageControlPinned: boolean

crossChain: CrossChainSetting
Expand Down Expand Up @@ -157,7 +141,6 @@ const initialState: UserState = {
acceptedTermVersion: null,
viewMode: VIEW_MODE.GRID,
holidayMode: true,
permitData: {},
isSlippageControlPinned: true,
crossChain: CROSS_CHAIN_SETTING_DEFAULT,
myEarningChart: true,
Expand Down Expand Up @@ -295,38 +278,6 @@ export default createReducer(initialState, builder =>
const oldMode = state.holidayMode
state.holidayMode = !oldMode
})
.addCase(permitUpdate, (state, { payload: { chainId, address, rawSignature, deadline, value, account } }) => {
if (!state.permitData) state.permitData = {}
if (!state.permitData[account]) state.permitData[account] = {}
if (!state.permitData[account][chainId]) state.permitData[account][chainId] = {}

state.permitData[account][chainId][address] = {
rawSignature,
deadline,
value,
errorCount: state.permitData[account][chainId][address]?.errorCount || 0,
}
})
.addCase(revokePermit, (state, { payload: { chainId, address, account } }) => {
if (
!state.permitData[account] ||
!state.permitData[account][chainId] ||
!state.permitData[account][chainId][address]
)
return

state.permitData[account][chainId][address] = null
})
.addCase(permitError, (state, { payload: { chainId, address, account } }) => {
if (!state.permitData?.[account]?.[chainId]?.[address]) return
const { errorCount } = state.permitData[account][chainId][address] || {}
state.permitData[account][chainId][address] = {
rawSignature: undefined,
deadline: undefined,
value: undefined,
errorCount: (errorCount || 0) + 1,
}
})
.addCase(pinSlippageControl, (state, { payload }) => {
state.isSlippageControlPinned = payload
})
Expand Down
3 changes: 1 addition & 2 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,8 @@ export const findTx = (txs: GroupedTxsByHash | undefined, hash: string): Transac
}

export const isChristmasTime = () => {
return false
const currentTime = dayjs()
return false && currentTime.month() === 11 && currentTime.date() >= 15
return currentTime.month() === 11 && currentTime.date() >= 12
}

export const isSupportLimitOrder = (chainId: ChainId): boolean => {
Expand Down

0 comments on commit 7764dc4

Please sign in to comment.