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

Add shortcut buttons and address list to Token Details Modal #1237

Merged
merged 17 commits into from
Feb 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
2 changes: 1 addition & 1 deletion apps/desktop-wallet/electron/electron-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ declare global {
getSystemRegion: () => Promise<string>
setProxySettings: (proxySettings: ProxySettings) => Promise<void>
openOnRampServiceWindow: ({ url, targetLocation }: { url: string; targetLocation: string }) => void
onOnRampTargetLocationReached: (callback: () => void) => () => Electron.IpcRenderer
onOnRampTargetLocationReached: (callback: () => void) => () => void
restart: () => void
}
window: {
Expand Down
6 changes: 3 additions & 3 deletions apps/desktop-wallet/locales/en-US/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"Address NFTs": "Address NFTs",
"Address options": "Address options",
"Address tokens": "Address tokens",
"Address transactions": "Address transactions",
"Addresses": "Addresses",
"Addresses & contacts": "Addresses & contacts",
"Advanced feature": "Advanced feature",
Expand Down Expand Up @@ -495,7 +494,7 @@
"You can now complete your purchase in the dedicated window!": "You can now complete your purchase in the dedicated window!",
"Token": "Token",
"Price": "Price",
"Value": "Value",
"Worth": "Worth",
"Invalid mnemonic. Please double check your words.": "Invalid mnemonic. Please double check your words.",
"Incorrect word. Please try again.": "Incorrect word. Please try again.",
"Select the correct word for word number <1>{{ number }} of 24</1>.": "Select the correct word for word number <1>{{ number }} of 24</1>.",
Expand Down Expand Up @@ -533,5 +532,6 @@
"nb_of_hidden_assets_one": "{{ count }} hidden asset",
"nb_of_hidden_assets_other": "{{ count }} hidden assets",
"Close hidden assets list": "Close hidden assets list",
"Unhide asset": "Unhide asset"
"Unhide asset": "Unhide asset",
"No transactions before {{ date }}": "No transactions before {{ date }}"
}
1 change: 1 addition & 0 deletions apps/desktop-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
"react-confetti": "^6.0.1",
"react-detect-click-outside": "^1.1.2",
"react-dom": "^18.2.0",
"react-freeze": "^1.0.4",
Copy link
Member Author

@nop33 nop33 Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was introduced to improve performance by "freezing" the hidden tab content after I improved the tab navigation everywhere by keeping the previous tab mounted.

"react-hook-form": "^7.42.1",
"react-i18next": "^13.2.1",
"react-idle-timer": "^5.7.2",
Expand Down
26 changes: 17 additions & 9 deletions apps/desktop-wallet/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import { migrateGeneralSettings, migrateNetworkSettings, migrateWalletData } fro

const App = memo(() => {
const theme = useAppSelector((s) => s.global.theme)
const { isWalletUnlocked } = useWalletLock()

useAutoLock()

Expand All @@ -61,14 +60,7 @@ const App = memo(() => {
<WalletConnectContextProvider>
<AppContainer>
<CenteredSection>
{!isWalletUnlocked && (
<AnimatedBackground
anchorPosition="bottom"
opacity={theme === 'dark' ? 0.6 : 0.8}
verticalOffset={-100}
hiddenOverflow
/>
)}
<LoginAnimatedBackground />
<Router />
</CenteredSection>
</AppContainer>
Expand Down Expand Up @@ -253,3 +245,19 @@ const AppContainerStyled = styled.div<{ showDevIndication: boolean }>`
border: 5px solid ${theme.global.valid};
`};
`

const LoginAnimatedBackground = () => {
const theme = useAppSelector((s) => s.global.theme)
const { isWalletUnlocked } = useWalletLock()

if (isWalletUnlocked) return null

return (
<AnimatedBackground
anchorPosition="bottom"
opacity={theme === 'dark' ? 0.6 : 0.8}
verticalOffset={-100}
hiddenOverflow
/>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ const useFetchAddressSingleTokenBalances = ({
})

return {
data: (isALPH ? alphBalances : addressTokenBalances) || {
availableBalance: '0',
lockedBalance: '0',
totalBalance: '0'
},
data: isALPH ? alphBalances : addressTokenBalances,
isLoading: isALPH ? isLoadingAlphBalances : isLoadingTokenBalances
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const combineBalancesToArray = (results: UseQueryResult<AddressTokensBalancesQue
}
}

const { useData, DataContextProvider } = createDataContext<AddressTokensBalancesQueryFnData, TokenApiBalances[]>({
const { useData, DataContextProvider } = createDataContext<AddressTokensBalancesQueryFnData, Array<TokenApiBalances>>({
useDataHook: useFetchWalletBalancesTokens,
combineFn: combineBalancesToArray,
defaultValue: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ const combineBalancesByAddress = (
...combineIsLoading(results)
})

const {
useData: useFetchWalletBalancesTokensByAddress,
DataContextProvider: UseFetchWalletBalancesTokensByAddressContextProvider
} = createDataContext<AddressTokensBalancesQueryFnData, AddressesTokensBalances['data']>({
const { useData, DataContextProvider } = createDataContext<
AddressTokensBalancesQueryFnData,
AddressesTokensBalances['data']
>({
useDataHook: useFetchWalletBalancesTokens,
combineFn: combineBalancesByAddress,
defaultValue: {}
})

const useFetchWalletBalancesTokensByAddress = useData
const UseFetchWalletBalancesTokensByAddressContextProvider = DataContextProvider
nop33 marked this conversation as resolved.
Show resolved Hide resolved

export default useFetchWalletBalancesTokensByAddress
export { UseFetchWalletBalancesTokensByAddressContextProvider }
Original file line number Diff line number Diff line change
@@ -1,69 +1,28 @@
import { ALPH } from '@alephium/token-list'
import { useQueries, UseQueryResult } from '@tanstack/react-query'
import { useMemo } from 'react'

import { SkipProp } from '@/api/apiDataHooks/apiDataHooksTypes'
import { combineIsLoading } from '@/api/apiDataHooks/apiDataHooksUtils'
import useFetchWalletBalancesAlph from '@/api/apiDataHooks/wallet/useFetchWalletBalancesAlph'
import { addressTokensBalancesQuery, AddressTokensBalancesQueryFnData } from '@/api/queries/addressQueries'
import { useAppSelector } from '@/hooks/redux'
import { useUnsortedAddressesHashes } from '@/hooks/useUnsortedAddresses'
import { selectCurrentlyOnlineNetworkId } from '@/storage/network/networkSelectors'
import { ApiBalances, TokenId } from '@/types/tokens'
import useFetchWalletBalancesTokensArray from '@/api/apiDataHooks/wallet/useFetchWalletBalancesTokensArray'
import { TokenId } from '@/types/tokens'

interface UseFetchWalletSingleTokenBalancesProps extends SkipProp {
tokenId: TokenId
}

const useFetchWalletSingleTokenBalances = ({ tokenId, skip }: UseFetchWalletSingleTokenBalancesProps) => {
const networkId = useAppSelector(selectCurrentlyOnlineNetworkId)
const allAddressHashes = useUnsortedAddressesHashes()

const useFetchWalletSingleTokenBalances = ({ tokenId }: UseFetchWalletSingleTokenBalancesProps) => {
const isALPH = tokenId === ALPH.id

const { data: alphBalances, isLoading: isLoadingAlphBalances } = useFetchWalletBalancesAlph()

const { data: tokenBalances, isLoading: isLoadingTokenBalances } = useQueries({
queries:
!isALPH && !skip
? allAddressHashes.map((addressHash) => addressTokensBalancesQuery({ addressHash, networkId }))
: [],
combine: useMemo(
() => (results: UseQueryResult<AddressTokensBalancesQueryFnData>[]) => combineTokenBalances(tokenId, results),
[tokenId]
)
})
const { data: tokensBalances, isLoading: isLoadingTokensBalances } = useFetchWalletBalancesTokensArray()

return {
data: isALPH ? alphBalances : tokenBalances,
isLoading: isALPH ? isLoadingAlphBalances : isLoadingTokenBalances
data: useMemo(
() => (isALPH ? alphBalances : tokensBalances.find(({ id }) => id === tokenId)),
[alphBalances, isALPH, tokenId, tokensBalances]
),
isLoading: isALPH ? isLoadingAlphBalances : isLoadingTokensBalances
}
}

export default useFetchWalletSingleTokenBalances

const combineTokenBalances = (tokenId: string, results: UseQueryResult<AddressTokensBalancesQueryFnData>[]) => ({
data: results.reduce(
(totalBalances, { data }) => {
const balances = data?.balances.find(({ id }) => id === tokenId)

totalBalances.totalBalance = (
BigInt(totalBalances.totalBalance) + BigInt(balances ? balances.totalBalance : 0)
).toString()
totalBalances.lockedBalance = (
BigInt(totalBalances.lockedBalance) + BigInt(balances ? balances.lockedBalance : 0)
).toString()
totalBalances.availableBalance = (
BigInt(totalBalances.availableBalance) + BigInt(balances ? balances.availableBalance : 0)
).toString()

return totalBalances
},
{
totalBalance: '0',
lockedBalance: '0',
availableBalance: '0'
} as ApiBalances
),
...combineIsLoading(results)
})

This file was deleted.

27 changes: 20 additions & 7 deletions apps/desktop-wallet/src/api/context/apiContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,30 @@ import { UseFetchWalletBalancesAlphArrayContextProvider } from '@/api/apiDataHoo
import { UseFetchWalletBalancesAlphByAddressContextProvider } from '@/api/apiDataHooks/wallet/useFetchWalletBalancesAlphByAddress'
import { UseFetchWalletBalancesTokensArrayContextProvider } from '@/api/apiDataHooks/wallet/useFetchWalletBalancesTokensArray'
import { UseFetchWalletBalancesTokensByAddressContextProvider } from '@/api/apiDataHooks/wallet/useFetchWalletBalancesTokensByAddress'
import { UseFetchWalletTransactionsLimitedContextProvider } from '@/api/apiDataHooks/wallet/useFetchWalletTransactionsLimited'
import { composeProviders } from '@/api/context/apiContextUtils'

const Providers = composeProviders([
type ProviderProps = { children: ReactNode }
type ProviderComponent = FC<ProviderProps>

const providers: Array<ProviderComponent> = [
UseFetchWalletBalancesTokensArrayContextProvider,
UseFetchWalletBalancesTokensByAddressContextProvider,
UseFetchWalletBalancesAlphArrayContextProvider,
UseFetchWalletBalancesAlphByAddressContextProvider,
UseFetchWalletTransactionsLimitedContextProvider
])
UseFetchWalletBalancesAlphByAddressContextProvider
]

const ComposedProviders = providers.reduce<ProviderComponent>(
(AccumulatedProviders, CurrentProvider) => {
const CombinedProvider: ProviderComponent = ({ children }) => (
<AccumulatedProviders>
<CurrentProvider>{children}</CurrentProvider>
</AccumulatedProviders>
)

return CombinedProvider
},
({ children }) => children
)

const ApiContextProvider = ({ children }: { children: ReactNode }) => <Providers>{children}</Providers>
const ApiContextProvider = ({ children }: ProviderProps) => <ComposedProviders>{children}</ComposedProviders>

export default ApiContextProvider
18 changes: 0 additions & 18 deletions apps/desktop-wallet/src/api/context/apiContextUtils.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion apps/desktop-wallet/src/components/Box.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { motion } from 'framer-motion'
import styled from 'styled-components'

const Box = styled(motion.div)<{ secondary?: boolean }>`
const Box = styled(motion.div)`
border-radius: var(--radius-huge);
width: 100%;
`
Expand Down
Loading
Loading