fix priority sorting for send wallets,caching and sorting

This commit is contained in:
Riccardo Balbo 2024-10-16 09:22:43 +02:00 committed by k00b
parent bb91b629f7
commit a6665bca6a
1 changed files with 21 additions and 13 deletions

View File

@ -196,7 +196,7 @@ function useConfig (walletDef) {
const serverConfig = await client.query({ const serverConfig = await client.query({
query: WALLET_BY_TYPE, query: WALLET_BY_TYPE,
variables: { type: walletDef.walletType }, variables: { type: walletDef.walletType },
fetchPolicy: 'no-cache' fetchPolicy: 'network-only'
}) })
if (serverConfig?.data?.walletByType) { if (serverConfig?.data?.walletByType) {
@ -284,7 +284,7 @@ function useConfig (walletDef) {
// check if it misses send or receive configs // check if it misses send or receive configs
const isReadyToSend = canSend && isConfigured({ fields: walletDef.fields, config: newConfig, clientOnly: true }) const isReadyToSend = canSend && isConfigured({ fields: walletDef.fields, config: newConfig, clientOnly: true })
const isReadyToReceive = canReceive && isConfigured({ fields: walletDef.fields, config: newConfig, serverOnly: true }) const isReadyToReceive = canReceive && isConfigured({ fields: walletDef.fields, config: newConfig, serverOnly: true })
const { autoWithdrawThreshold, autoWithdrawMaxFeePercent, priority, enabled } = newServerConfig const { autoWithdrawThreshold, autoWithdrawMaxFeePercent, priority, enabled } = newConfig
// console.log('New client config', newClientConfig) // console.log('New client config', newClientConfig)
// console.log('New server config', newServerConfig) // console.log('New server config', newServerConfig)
@ -453,22 +453,30 @@ export function useWallets () {
export function WalletProvider ({ children }) { export function WalletProvider ({ children }) {
const { me } = useMe() const { me } = useMe()
const wallets = walletDefs.map(def => useWalletInner(def.name)).filter(w => w)
const migrationRan = useRef(false) const migrationRan = useRef(false)
const migratableKeys = !migrationRan.current && !SSR ? Object.keys(window.localStorage).filter(k => k.startsWith('wallet:')) : undefined const migratableKeys = !migrationRan.current && !SSR ? Object.keys(window.localStorage).filter(k => k.startsWith('wallet:')) : undefined
const { data: bestSendWalletListData } = useQuery(BEST_SEND_WALLETS, { const walletList = walletDefs.map(def => useWalletInner(def.name)).filter(w => w)
pollInterval: POLL_INTERVAL, const { data: bestSendWalletList } = useQuery(BEST_SEND_WALLETS, SSR
nextFetchPolicy: 'network-only', ? {}
fetchPolicy: 'network-only' : {
}) pollInterval: POLL_INTERVAL,
nextFetchPolicy: 'cache-and-network'
})
const [bestSendWalletList, setBestSendWalletList] = useState(bestSendWalletListData?.wallets ?? []) const processSendWallets = (bestWalletData) => {
const clientSideSorting = false // sorting is now done on the server
let wallets = (bestWalletData?.wallets ?? []).filter(w => w.canSend)
if (clientSideSorting) wallets = wallets.sort(walletPrioritySort)
return wallets
}
const wallets = walletList.sort(walletPrioritySort)
const [bestSendWallets, innerSetBestSendWallets] = useState(() => processSendWallets(bestSendWalletList))
useEffect(() => { useEffect(() => {
setBestSendWalletList(bestSendWalletListData?.wallets) innerSetBestSendWallets(processSendWallets(bestSendWalletList))
}, [bestSendWalletListData]) }, [bestSendWalletList])
// migration // migration
useEffect(() => { useEffect(() => {
@ -499,7 +507,7 @@ export function WalletProvider ({ children }) {
}, []) }, [])
return ( return (
<WalletContext.Provider value={{ wallets, sendWallets: bestSendWalletList }}> <WalletContext.Provider value={{ wallets, sendWallets: bestSendWallets }}>
{children} {children}
</WalletContext.Provider> </WalletContext.Provider>
) )