Skip to content

Commit

Permalink
Merge pull request #586 from liteflow-labs/dev
Browse files Browse the repository at this point in the history
Release v3.4.4
  • Loading branch information
ismailToyran authored Mar 14, 2024
2 parents 5e04c87 + 5d0873f commit f465112
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 42 deletions.
4 changes: 1 addition & 3 deletions components/Filter/FilterBy/Price.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ const FilterByPrice: FC<Props> = ({

const filterResult = watch()

const { data: currencyData } = useFetchCurrenciesQuery({
ssr: false,
})
const { data: currencyData } = useFetchCurrenciesQuery()
const currencies = useMemo(
() =>
filterResult.chains.length > 0
Expand Down
23 changes: 18 additions & 5 deletions components/History/ListItem/BurnListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Flex, Icon, Text } from '@chakra-ui/react'
import { BigNumber } from '@ethersproject/bignumber'
import { FaBurn } from '@react-icons/all-files/fa/FaBurn'
import { HiBadgeCheck } from '@react-icons/all-files/hi/HiBadgeCheck'
import Trans from 'next-translate/Trans'
import useTranslation from 'next-translate/useTranslation'
import { FC } from 'react'
import { AccountVerificationStatus } from '../../../graphql'
import { formatDate } from '../../../utils'
Expand All @@ -24,15 +24,28 @@ type IProps = {
}

const BurnListItem: FC<IProps> = ({ quantity, fromAddress, from, date }) => {
const { t } = useTranslation('components')
return (
<ListItem
px={0}
image={<Icon as={FaBurn} h={5} w={5} color="gray.400" />}
label={
<Text as="span" color="brand.black" fontWeight="medium">
{t('history.burn.quantity', { value: quantity })}
</Text>
<Trans
ns="components"
i18nKey="history.burn.quantity"
values={{
count: BigNumber.from(quantity).lte(Number.MAX_SAFE_INTEGER - 1)
? BigNumber.from(quantity).toNumber()
: Number.MAX_SAFE_INTEGER - 1,
}}
components={[
<Text
key="quantity"
as="span"
color="brand.black"
fontWeight="medium"
/>,
]}
/>
}
subtitle={
<Trans
Expand Down
11 changes: 8 additions & 3 deletions hooks/useAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type AccountDetail = {
address?: string
jwtToken: string | null
logout: () => Promise<void>
login: (connector: Connector) => Promise<void>
login: (connector: Connector) => Promise<boolean>
sign: (connector: Connector) => Promise<void>
}

Expand Down Expand Up @@ -64,8 +64,12 @@ export default function useAccount(): AccountDetail {
const signer = walletClientToSigner(wallet)
const currentAddress = (await signer.getAddress()).toLowerCase()
if (jwt && currentAddress === jwt.address) {
return setAuthenticationToken(jwt.token)
setAuthenticationToken(jwt.token)
// fully login, nothing to do
return true
}
// not fully login, need to sign
return false
},
[jwt, setAuthenticationToken],
)
Expand All @@ -76,6 +80,7 @@ export default function useAccount(): AccountDetail {
const signer = walletClientToSigner(wallet)
const { jwtToken } = await authenticate(signer)

setAuthenticationToken(jwtToken)
const newJwt = jwtDecode<JwtPayload>(jwtToken)
setCookie(COOKIE_JWT_TOKEN, jwtToken, {
...COOKIE_OPTIONS,
Expand All @@ -87,7 +92,7 @@ export default function useAccount(): AccountDetail {
: {}),
})
},
[authenticate, setCookie],
[authenticate, setAuthenticationToken, setCookie],
)

// Server side
Expand Down
4 changes: 1 addition & 3 deletions hooks/useFees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ export default function useFees({
quantity: BigNumber
debounceTimeout?: number
}) {
const [fetchFees, { data, previousData }] = useFeesLazyQuery({
ssr: false,
})
const [fetchFees, { data, previousData }] = useFeesLazyQuery()
const [loading, setLoading] = useState(false) // manual state to tell if the fetch is in progress. Cannot use the loading param from useFeesLazyQuery because of the debounce feature
useEffect(() => {
if (currencyId === undefined) return
Expand Down
6 changes: 3 additions & 3 deletions locales/en/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@
"purchased_other": "<0>{{count}}</0> editions purchased for <1/> each"
},
"burn": {
"quantity_one": "{{count}} edition burned",
"purchased_other": "{{count}} editions burned",
"by": "By {{user}}"
"quantity_one": "<0>{{count}}</0> edition burned",
"quantity_other": "<0>{{count}}</0> editions burned",
"by": "By <0/>"
}
},
"modal": {
Expand Down
6 changes: 3 additions & 3 deletions locales/es-mx/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@
"purchased_other": "<0>{{count}}</0> ediciones compradas por <1/> cada una"
},
"burn": {
"quantity_one": "{{count}} edición quemada",
"purchased_other": "{{count}} ediciones quemadas",
"by": "Por {{user}}"
"quantity_one": "<0>{{count}}</0> edición quemada",
"quantity_other": "<0>{{count}}</0> ediciones quemadas",
"by": "Por <0/>"
}
},
"modal": {
Expand Down
6 changes: 3 additions & 3 deletions locales/ja/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@
"purchased_other": "<0>{{count}}</0> 各エディションが購入されました <1/>"
},
"burn": {
"quantity_one": "{{count}} エディションが燃やされました",
"purchased_other": "{{count}} エディションが燃やされました",
"by": "までに{{user}}"
"quantity_one": "<0>{{count}}</0> エディションが燃やされました",
"quantity_other": "<0>{{count}}</0> エディションが燃やされました",
"by": "までに<0/>"
}
},
"modal": {
Expand Down
6 changes: 3 additions & 3 deletions locales/zh-cn/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@
"purchased_other": "已购买 <0>{{count}}</0> 个版本,单价为 <1/>"
},
"burn": {
"quantity_one": "{{count}} 版本已烧毁",
"purchased_other": "{{count}} 个版本已烧毁",
"by": "截至 {{user}}"
"quantity_one": "<0>{{count}}</0> 版本已烧毁",
"quantity_other": "<0>{{count}}</0> 个版本已烧毁",
"by": "截至 <0/>"
}
},
"modal": {
Expand Down
41 changes: 25 additions & 16 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ import React, {
Fragment,
JSX,
PropsWithChildren,
useCallback,
useEffect,
useMemo,
useState,
} from 'react'
import { Cookies, CookiesProvider, useCookies } from 'react-cookie'
import {
Connector,
WagmiConfig,
useDisconnect,
useAccount as useWagmiAccount,
Expand Down Expand Up @@ -128,36 +130,43 @@ function AccountProvider({
const { LITEFLOW_API_KEY, BASE_URL } = useEnvironment()
const { jwtToken, login, logout } = useAccount()
const { disconnect } = useDisconnect()
const { isOpen, onOpen, onClose } = useDisclosure()
const { isOpen, onOpen: openSignModal, onClose } = useDisclosure()
const [cookies] = useCookies<string, COOKIES>([COOKIE_JWT_TOKEN])

const { connector } = useWagmiAccount({
async onConnect({ connector }) {
if (!connector) return
try {
await login(connector)
// jwtToken from useAccount is null on refresh, so we need to check the cookies
if (!cookies[COOKIE_JWT_TOKEN]) onOpen()
} catch (e: any) {
disconnect()
}
},
onDisconnect() {
onConnect: useCallback(
async ({ connector }: { connector?: Connector }) => {
if (!connector) return
try {
const isConnected = await login(connector)
if (!isConnected) openSignModal()
} catch (e: any) {
disconnect()
}
},
[disconnect, login, openSignModal],
),
onDisconnect: useCallback(() => {
void logout()
},
}, [logout]),
})

// handle change of account
useEffect(() => {
if (!connector) return
const handleLogin = () => {
login(connector).then(onOpen).catch(onError)
const handleLogin = async () => {
try {
const isConnected = await login(connector)
if (!isConnected) openSignModal()
} catch (error) {
onError(1)
}
}
connector.on('change', handleLogin)
return () => {
connector.off('change', handleLogin)
}
}, [connector, login, onError, onOpen])
}, [connector, cookies, login, onError, openSignModal])

const client = useMemo(
// The client needs to be reset when the jwtToken changes but only on the client as the server will
Expand Down

0 comments on commit f465112

Please sign in to comment.