Skip to content
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
34 changes: 18 additions & 16 deletions packages/mask/shared/kv-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,26 @@ export const PersistentStorages = {
Settings: createPersistentKVStorage('settings', {
debugging: false,
}),
ApplicationEntryUnListedList: createPersistentKVStorage<{ [key: string]: boolean }>(
ApplicationEntryUnListedList: createPersistentKVStorage<{ current: { [key: string]: boolean } }>(
ApplicationEntryUnlistedListKey,
{
[PluginId.RedPacket]: false,
[PluginId.FileService]: false,
[PluginId.ITO]: false,
[`${PluginId.ITO}_claim`]: false,
[PluginId.CrossChainBridge]: false,
[PluginId.MaskBox]: false,
[PluginId.Savings]: false,
[PluginId.Avatar]: false,
[PluginId.Trader]: false,
[PluginId.Tips]: false,
[PluginId.Transak]: false,
[PluginId.Pets]: false,
[PluginId.FindTruman]: false,
[PluginId.GoPlusSecurity]: false,
[PluginId.Referral]: false,
current: {
[PluginId.RedPacket]: false,
[PluginId.FileService]: false,
[PluginId.ITO]: false,
[`${PluginId.ITO}_claim`]: false,
[PluginId.CrossChainBridge]: false,
[PluginId.MaskBox]: false,
[PluginId.Savings]: false,
[PluginId.Avatar]: false,
[PluginId.Trader]: false,
[PluginId.Tips]: false,
[PluginId.Transak]: false,
[PluginId.Pets]: false,
[PluginId.FindTruman]: false,
[PluginId.GoPlusSecurity]: false,
[PluginId.Referral]: false,
},
},
),
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ export interface Application {

// #region kv storage
export function setUnlistedApp(app: Application, unlisted: boolean) {
PersistentStorages.ApplicationEntryUnListedList.storage[app.entry.ApplicationEntryID].setValue(unlisted)
const state = PersistentStorages.ApplicationEntryUnListedList.storage.current
if (!state.initialized) return
PersistentStorages.ApplicationEntryUnListedList.storage.current.setValue({
...state.value,
[app.entry.ApplicationEntryID]: unlisted,
})
}

export function getUnlistedApp(app: Application): boolean {
const state = PersistentStorages.ApplicationEntryUnListedList.storage[app.entry.ApplicationEntryID]
return state.initialized ? state.value : true
const state = PersistentStorages.ApplicationEntryUnListedList.storage.current
return state.initialized ? state.value[app.entry.ApplicationEntryID] : true
}
// #endregion

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useBlockNumber, useChainId, useWeb3Connection, Web3Helper } from '@masknet/plugin-infra/web3'
import { useChainId, useWeb3Connection, Web3Helper } from '@masknet/plugin-infra/web3'
import { NetworkPluginID } from '@masknet/web3-shared-base'
import { ChainId, getITOConstants } from '@masknet/web3-shared-evm'
import { useRef, useEffect } from 'react'
Expand All @@ -12,7 +12,6 @@ export function useAllPoolsAsSeller(address: string) {
const allPoolsRef = useRef<PoolFromNetwork[]>([])
const chainId = useChainId(NetworkPluginID.PLUGIN_EVM)
const connection = useWeb3Connection(NetworkPluginID.PLUGIN_EVM, { chainId })
const { value: blockNumber = 0 } = useBlockNumber(NetworkPluginID.PLUGIN_EVM)

useEffect(() => {
allPoolsRef.current = []
Expand All @@ -24,11 +23,12 @@ export function useAllPoolsAsSeller(address: string) {
pools: EMPTY_LIST,
loadMore: false,
}
const blockNumber = await connection.getBlockNumber()
const _pools = await getAllPoolsAsSeller(address, blockNumber, chainId, connection)
const pools = _pools.filter((a) => !allPoolsRef.current.map((b) => b.pool.pid).includes(a.pool.pid))
allPoolsRef.current = allPoolsRef.current.concat(pools)
return { pools: allPoolsRef.current, loadMore: pools.length > 0 }
}, [address, blockNumber, chainId, connection])
}, [address, chainId, connection])
}

async function getAllPoolsAsSeller(
Expand All @@ -37,7 +37,7 @@ async function getAllPoolsAsSeller(
chainId: ChainId,
connection: Web3Helper.Web3Connection<NetworkPluginID.PLUGIN_EVM>,
) {
if (!connection) return []
if (!connection) return EMPTY_LIST

const { ITO2_CONTRACT_CREATION_BLOCK_HEIGHT } = getITOConstants(chainId)

Expand Down
6 changes: 3 additions & 3 deletions packages/mask/src/plugins/ITO/SNSAdaptor/hooks/useClaimAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useAsyncRetry } from 'react-use'
import type { SwappedTokenType } from '../../types'
import * as chain from '../utils/chain'
import type { ChainId } from '@masknet/web3-shared-evm'
import { useBlockNumber, useWeb3Connection } from '@masknet/plugin-infra/web3'
import { useWeb3Connection } from '@masknet/plugin-infra/web3'
import { NetworkPluginID } from '@masknet/web3-shared-base'

export function useClaimAll(swapperAddress: string, chainId: ChainId) {
Expand All @@ -13,14 +13,14 @@ export function useClaimAll(swapperAddress: string, chainId: ChainId) {
allPoolsRef.current = []
}, [chainId])

const { value: blockNumber = 0 } = useBlockNumber(NetworkPluginID.PLUGIN_EVM, { chainId })
const connection = useWeb3Connection(NetworkPluginID.PLUGIN_EVM, { chainId })
const asyncResult = useAsyncRetry(async () => {
if (allPoolsRef.current.length > 0 || !connection) return allPoolsRef.current
const blockNumber = await connection.getBlockNumber()
const results = await chain.getClaimAllPools(chainId, blockNumber, swapperAddress, connection)
allPoolsRef.current = results
return allPoolsRef.current
}, [swapperAddress, blockNumber, chainId])
}, [swapperAddress, chainId])

return {
...asyncResult,
Expand Down
2 changes: 1 addition & 1 deletion packages/mask/src/plugins/ITO/SNSAdaptor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const sns: Plugin.SNSAdaptor.Definition = {
: clickHandler
}
/>
<ClaimAllDialog open={open} onClose={() => setOpen(false)} />
{open ? <ClaimAllDialog open={open} onClose={() => setOpen(false)} /> : null}
</>
)
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { useAsyncRetry } from 'react-use'
import { NetworkPluginID } from '@masknet/web3-shared-base'
import { ChainId, getRedPacketConstants } from '@masknet/web3-shared-evm'
import { useBlockNumber, useWeb3Connection, Web3Helper } from '@masknet/plugin-infra/web3'
import { EMPTY_LIST } from '@masknet/shared-base'
import { useWeb3Connection, Web3Helper } from '@masknet/plugin-infra/web3'
import * as chain from '../utils/chain'
import { RedPacketRPC } from '../../messages'

export function useRedPacketHistory(address: string, chainId: ChainId) {
const { value: blockNumber = 0 } = useBlockNumber(NetworkPluginID.PLUGIN_EVM)
const connection = useWeb3Connection(NetworkPluginID.PLUGIN_EVM, { chainId })

return useAsyncRetry(async () => {
if (!blockNumber || !connection) return []

if (!connection) return EMPTY_LIST
const blockNumber = await connection.getBlockNumber()
return getRedPacketHistory(address, chainId, blockNumber, connection)
}, [address, chainId, blockNumber, connection])
}, [address, chainId, connection])
}

async function getRedPacketHistory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export function ReferralDialog({ open, onClose }: ReferralDialogProps) {
return (
<InjectedDialog
open={open}
isOnBack={currentPage.page !== PagesType.LANDING}
onClose={onHandleClose}
titleBarIconStyle="close"
title={
Expand Down
2 changes: 1 addition & 1 deletion packages/mask/src/plugins/Referral/SNSAdaptor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const sns: Plugin.SNSAdaptor.Definition = {
: clickHandler
}
/>
<ReferralDialog open={open} onClose={() => setOpen(false)} />
{open ? <ReferralDialog open={open} onClose={() => setOpen(false)} /> : null}
</>
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export function SavingsDialog({ open, onClose }: SavingsDialogProps) {
<InjectedDialog
open={open}
title={t('plugin_savings')}
isOnBack={Boolean(selectedProtocol)}
onClose={() => {
if (selectedProtocol === null) {
onClose?.()
Expand Down