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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useHoverDirty } from 'react-use'
import { WalletIcon, NFTCardStyledAssetPlayer } from '@masknet/shared'
import { Box, Button, Link, Tooltip, Typography } from '@mui/material'
import { makeStyles, MaskColorVar } from '@masknet/theme'
import { NetworkPluginID, NonFungibleAsset } from '@masknet/web3-shared-base'
import { NetworkPluginID } from '@masknet/web3-shared-base'
import { CollectiblePlaceholder } from '../CollectiblePlaceHolder'
import { useDashboardI18N } from '../../../../locales'
import { ChangeNetworkTip } from '../FungibleTokenTableRow/ChangeNetworkTip'
Expand Down Expand Up @@ -95,10 +95,7 @@ const useStyles = makeStyles()((theme) => ({
}))

export interface CollectibleCardProps {
token: NonFungibleAsset<
Web3Helper.Definition[NetworkPluginID]['ChainId'],
Web3Helper.Definition[NetworkPluginID]['SchemaType']
>
token: Web3Helper.NonFungibleAssetScope<'all'>
onSend(): void
renderOrder: number
}
Expand All @@ -108,7 +105,7 @@ export const CollectibleCard = memo<CollectibleCardProps>(({ token, onSend, rend
const chainId = useChainId()
const { classes } = useStyles()
const ref = useRef(null)
const { Others } = useWeb3State<'all'>()
const { Others } = useWeb3State()
const [isHoveringTooltip, setHoveringTooltip] = useState(false)
const isHovering = useHoverDirty(ref)
const networkDescriptor = useNetworkDescriptor(undefined, token.contract?.chainId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ interface ChangeNetworkTipProps {
export const ChangeNetworkTip = memo<ChangeNetworkTipProps>(({ chainId }) => {
const t = useDashboardI18N()

const providerDescriptor = useProviderDescriptor<'all'>()
const networkDescriptors = useNetworkDescriptors<'all'>()
const Web3UI = useWeb3UI<'all'>()
const providerDescriptor = useProviderDescriptor()
const networkDescriptors = useNetworkDescriptors()
const Web3UI = useWeb3UI()
const { NetworkIconClickBait } = Web3UI.SelectNetworkMenu ?? {}
const targetNetwork = networkDescriptors.find((x) => x.chainId === chainId)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export const HistoryTable = memo<HistoryTableProps>(({ selectedChainId }) => {
onPageChange={setPage}
hasNextPage={false}
isLoading={loading}
isEmpty={!value?.data?.length}
dataSource={(value?.data ?? EMPTY_LIST) as Array<Transaction<ChainId, SchemaType>>}
isEmpty={!value?.length}
dataSource={(value ?? EMPTY_LIST) as Array<Transaction<ChainId, SchemaType>>}
selectedChainId={selectedChainId}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export interface HistoryTableRowUIProps extends HistoryTableRowProps {
export const HistoryTableRowUI = memo<HistoryTableRowUIProps>(
({ transaction, selectedChainId, formattedType, domain }) => {
const { classes } = useStyles()
const { Others } = useWeb3State<'all'>()
const { Others } = useWeb3State()
return (
<TableRow className={classes.hover}>
<TableCell className={classes.cell} align="center" variant="body">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ export const WalletStateBar = memo(() => {

const account = useAccount()
const wallet = useWallet()
const networkDescriptor = useNetworkDescriptor<'all'>()
const providerDescriptor = useProviderDescriptor<'all'>()
const networkDescriptor = useNetworkDescriptor()
const providerDescriptor = useProviderDescriptor()
const pendingTransactions = useRecentTransactions(NetworkPluginID.PLUGIN_EVM, TransactionStatusType.NOT_DEPEND)

const { openDialog: openWalletStatusDialog } = useRemoteControlledDialog(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ export const useNetworkSelector = (pluginID?: NetworkPluginID) => {
const { classes } = useStyles()

const currentChainId = useChainId()
const providerDescriptor = useProviderDescriptor<'all'>()
const networkDescriptors = useNetworkDescriptors<'all'>()
const Web3UI = useWeb3UI<'all'>()
const providerDescriptor = useProviderDescriptor()
const networkDescriptors = useNetworkDescriptors()
const Web3UI = useWeb3UI()
const { NetworkIconClickBait } = Web3UI.SelectNetworkMenu ?? {}
const { Connection } = useWeb3State<'all'>(pluginID)
const { Connection } = useWeb3State(pluginID)

const onConnect = useCallback(
async (chainId: Web3Helper.ChainIdAll) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/dashboard/src/pages/Wallets/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function Wallets() {

const networks = getRegisteredWeb3Networks()
const pluginId = useCurrentWeb3NetworkPluginID()
const networkDescriptor = useNetworkDescriptor<'all'>()
const networkDescriptor = useNetworkDescriptor()
const [selectedNetwork, setSelectedNetwork] = useState<Web3Helper.NetworkDescriptorAll | null>(
networkDescriptor ?? null,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const Transaction: FC<TransactionProps> = ({ chainId, transaction: tx, onClear =
}

const web3 = useWeb3()
const { Others } = useWeb3State<'all'>()
const { Others } = useWeb3State()

const { value: targetAddress } = useAsync(async () => {
return ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function WalletStatusBox(props: WalletStatusBox) {
const providerType = useProviderType()
const providerDescriptor = useProviderDescriptor()
const networkDescriptor = useNetworkDescriptor()
const { Others } = useWeb3State<'all'>()
const { Others } = useWeb3State()
const { value: domain } = useReverseAddress(undefined, account)

// #region copy addr to clipboard
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useImageChecker } from '@masknet/plugin-infra/web3'
import { useImageChecker } from '@masknet/shared'
import { makeStyles } from '@masknet/theme'
import type { NonFungibleToken } from '@masknet/web3-shared-base'
import { ChainId, createERC721Token, SchemaType } from '@masknet/web3-shared-evm'
Expand Down
4 changes: 2 additions & 2 deletions packages/mask/src/plugins/Avatar/SNSAdaptor/NFTAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { Box, Button, Skeleton, Typography } from '@mui/material'
import { useI18N } from '../../../utils'
import { AddNFT } from './AddNFT'
import { NFTImage } from './NFTImage'
import { useAccount, useChainId, useImageChecker } from '@masknet/plugin-infra/web3'
import { ReversedAddress } from '@masknet/shared'
import { useAccount, useChainId } from '@masknet/plugin-infra/web3'
import { ReversedAddress, useImageChecker } from '@masknet/shared'
import { NetworkPluginID, NonFungibleToken } from '@masknet/web3-shared-base'
import { ChainBoundary } from '../../../web3/UI/ChainBoundary'
import { useCollectibles } from '../hooks/useCollectibles'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function ConnectionProgress(props: ConnectionProgressProps) {
const { t } = useI18N()
const classes = useStylesExtends(useStyles(), props)

const { Others } = useWeb3State<'all'>(pluginID)
const { Others } = useWeb3State(pluginID)
const providerDescriptor = useProviderDescriptor(pluginID, providerType)

if (!Others) return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function ConnectWalletDialog(props: ConnectWalletDialogProps) {
)
// #endregion

const { Connection, Others } = useWeb3State<'all'>(pluginID)
const { Connection, Others } = useWeb3State(pluginID)

const connection = useAsyncRetry<true>(async () => {
if (!open) return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ export function SelectNftContractDialog(props: SelectNftContractDialogProps) {
}, [id, setDialog])
// #endregion

const { value: assets = [], loading } = useNonFungibleCollections(NetworkPluginID.PLUGIN_EVM, chainId)
const { value: assets = [], loading } = useNonFungibleCollections(NetworkPluginID.PLUGIN_EVM, {
chainId,
})

const contractList = assets
.filter((x) => x.schema_name === WyvernSchemaName.ERC721)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,14 @@ export function SelectProviderDialog(props: SelectProviderDialogProps) {
const networks = getRegisteredWeb3Networks()
const providers = getRegisteredWeb3Providers()
const pluginID = useValueRef(pluginIDSettings)
const network = useNetworkDescriptor<'all'>()
const network = useNetworkDescriptor()
const [undeterminedPluginID, setUndeterminedPluginID] = useState(pluginID)
const [undeterminedNetworkID, setUndeterminedNetworkID] = useState(network?.ID)

const Web3State = useWeb3State<'all'>(undeterminedPluginID)
const Web3State = useWeb3State(undeterminedPluginID)
const { Others, Provider } = Web3State

const { NetworkIconClickBait, ProviderIconClickBait } =
useWeb3UI<'all'>(undeterminedPluginID).SelectProviderDialog ?? {}
const { NetworkIconClickBait, ProviderIconClickBait } = useWeb3UI(undeterminedPluginID).SelectProviderDialog ?? {}

const onNetworkIconClicked = useCallback((network: Web3Helper.NetworkDescriptorAll) => {
setUndeterminedPluginID(network.networkSupporterPluginID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function TransactionSnackbar({ pluginID }: TransactionSnackbarProps) {

const chainId = useChainId(pluginID)
const [progress, setProgress] = useState<TransactionProgressEvent>()
const { Others, TransactionFormatter, TransactionWatcher } = useWeb3State<'all'>(progress?.pluginID)
const { Others, TransactionFormatter, TransactionWatcher } = useWeb3State(progress?.pluginID)

useEffect(() => {
const removeListener = TransactionWatcher?.emitter.on('progress', (id, status, transaction) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/mask/src/web3/UI/ChainBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ export function ChainBoundary<T extends NetworkPluginID>(props: ChainBoundaryPro
const classes = useStylesExtends(useStyles(), props)

const actualPluginID = useCurrentWeb3NetworkPluginID()
const { Others: actualOthers } = useWeb3State<'all'>(actualPluginID)
const { Others: actualOthers } = useWeb3State(actualPluginID)
const actualChainId = useChainId(actualPluginID)
const actualProviderType = useProviderType(actualPluginID)
const actualChainName = actualOthers?.chainResolver.chainName(actualChainId)

const { Others: expectedOthers } = useWeb3State<'all'>(expectedPluginID)
const expectedConnection = useWeb3Connection<'all'>(expectedPluginID)
const { Others: expectedOthers } = useWeb3State(expectedPluginID)
const expectedConnection = useWeb3Connection(expectedPluginID)
const expectedAllowTestnet = useAllowTestnet(expectedPluginID)
const expectedAccount = useAccount(expectedPluginID)
const expectedChainName = expectedOthers?.chainResolver.chainName(expectedChainId)
Expand Down
146 changes: 142 additions & 4 deletions packages/plugin-infra/src/web3-helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import type {
ConnectionState,
ProviderDescriptor,
ProviderState,
FungibleToken,
NonFungibleToken,
FungibleAsset,
NonFungibleAsset,
RecentTransaction,
} from '@masknet/web3-shared-base'
import type * as EVM from '@masknet/web3-shared-evm'
import type * as Flow from '@masknet/web3-shared-flow'
Expand Down Expand Up @@ -119,10 +124,9 @@ export declare namespace Web3Helper {
Definition[T]['Web3'],
Definition[T]['Web3Provider']
>
export type Web3HubOptions<
T extends NetworkPluginID = never,
Indicator extends string | number = number,
> = T extends never ? never : HubOptions<Definition[T]['ChainId'], Indicator>
export type Web3HubOptions<T extends NetworkPluginID = never, Indicator = number> = T extends never
? never
: HubOptions<Definition[T]['ChainId'], Indicator>

export type Web3Hub<T extends NetworkPluginID = never> = T extends never
? never
Expand Down Expand Up @@ -176,6 +180,12 @@ export declare namespace Web3Helper {
Definition[NetworkPluginID]['ProviderType']
>

export type Web3ConnectionOptionsAll = ConnectionOptions<
Definition[NetworkPluginID]['ChainId'],
Definition[NetworkPluginID]['ProviderType'],
Definition[NetworkPluginID]['Transaction']
>

export type Web3ConnectionAll = Connection<
Definition[NetworkPluginID]['ChainId'],
Definition[NetworkPluginID]['SchemaType'],
Expand All @@ -190,6 +200,8 @@ export declare namespace Web3Helper {
Definition[NetworkPluginID]['Web3Provider']
>

export type Web3HubOptionsAll = HubOptions<Definition[NetworkPluginID]['ChainId'], number>

export type Web3HubAll = Hub<
Definition[NetworkPluginID]['ChainId'],
Definition[NetworkPluginID]['SchemaType'],
Expand Down Expand Up @@ -219,4 +231,130 @@ export declare namespace Web3Helper {
Definition[NetworkPluginID]['ProviderType'],
Definition[NetworkPluginID]['NetworkType']
>

export type Scope<S extends 'all' | void = void, T = unknown, F = unknown> = S extends 'all' ? T : F

export type ChainIdScope<
S extends 'all' | void = void,
T extends NetworkPluginID = NetworkPluginID,
> = S extends 'all' ? Web3Helper.ChainIdAll : Web3Helper.Definition[T]['ChainId']
export type NetworkTypeScope<
S extends 'all' | void = void,
T extends NetworkPluginID = NetworkPluginID,
> = S extends 'all' ? Web3Helper.NetworkTypeAll : Web3Helper.Definition[T]['NetworkType']
export type ProviderTypeScope<
S extends 'all' | void = void,
T extends NetworkPluginID = NetworkPluginID,
> = S extends 'all' ? Web3Helper.ProviderTypeAll : Web3Helper.Definition[T]['ProviderType']
export type SchemaTypeScope<
S extends 'all' | void = void,
T extends NetworkPluginID = NetworkPluginID,
> = S extends 'all' ? Web3Helper.SchemaTypeAll : Web3Helper.Definition[T]['SchemaType']
export type TransactionScope<
S extends 'all' | void = void,
T extends NetworkPluginID = NetworkPluginID,
> = S extends 'all' ? TransactionAll : Web3Helper.Definition[T]['Transaction']
export type RecentTransactionScope<
S extends 'all' | void = void,
T extends NetworkPluginID = NetworkPluginID,
> = RecentTransaction<ChainIdScope<S, T>, TransactionScope<S, T>>
export type FungibleTokenScope<
S extends 'all' | void = void,
T extends NetworkPluginID = NetworkPluginID,
> = FungibleToken<ChainIdScope<S, T>, SchemaTypeScope<S, T>>
export type NonFungibleTokenScope<
S extends 'all' | void = void,
T extends NetworkPluginID = NetworkPluginID,
> = NonFungibleToken<ChainIdScope<S, T>, SchemaTypeScope<S, T>>
export type FungibleAssetScope<
S extends 'all' | void = void,
T extends NetworkPluginID = NetworkPluginID,
> = FungibleAsset<ChainIdScope<S, T>, SchemaTypeScope<S, T>>
export type NonFungibleAssetScope<
S extends 'all' | void = void,
T extends NetworkPluginID = NetworkPluginID,
> = NonFungibleAsset<ChainIdScope<S, T>, SchemaTypeScope<S, T>>
export type NetworkDescriptorScope<
S extends 'all' | void = void,
T extends NetworkPluginID = NetworkPluginID,
> = S extends 'all'
? NetworkDescriptorAll
: NetworkDescriptor<Definition[T]['ChainId'], Definition[T]['NetworkType']>
export type ProviderDescriptorScope<
S extends 'all' | void = void,
T extends NetworkPluginID = NetworkPluginID,
> = S extends 'all'
? ProviderDescriptorAll
: ProviderDescriptor<Definition[T]['ChainId'], Definition[T]['ProviderType']>
export type Web3Scope<S extends 'all' | void = void, T extends NetworkPluginID = NetworkPluginID> = S extends 'all'
? Web3All
: Definition[T]['Web3']
export type Web3ProviderScope<
S extends 'all' | void = void,
T extends NetworkPluginID = NetworkPluginID,
> = S extends 'all' ? Web3ProviderAll : Definition[T]['Web3Provider']
export type Web3StateScope<
S extends 'all' | void = void,
T extends NetworkPluginID = NetworkPluginID,
> = S extends 'all'
? Web3StateAll
: Web3Plugin.ObjectCapabilities.Capabilities<
Definition[T]['ChainId'],
Definition[T]['SchemaType'],
Definition[T]['ProviderType'],
Definition[T]['NetworkType'],
Definition[T]['Signature'],
Definition[T]['GasOption'],
Definition[T]['Block'],
Definition[T]['Transaction'],
Definition[T]['TransactionReceipt'],
Definition[T]['TransactionDetailed'],
Definition[T]['TransactionSignature'],
Definition[T]['TransactionParameter'],
Definition[T]['Web3'],
Definition[T]['Web3Provider']
>
export type Web3ConnectionOptionsScope<
S extends 'all' | void = void,
T extends NetworkPluginID = NetworkPluginID,
> = S extends 'all'
? Web3ConnectionOptionsAll
: ConnectionOptions<Definition[T]['ChainId'], Definition[T]['ProviderType'], Definition[T]['Transaction']>
export type Web3ConnectionScope<
S extends 'all' | void = void,
T extends NetworkPluginID = NetworkPluginID,
> = S extends 'all'
? Web3ConnectionAll
: Connection<
Definition[T]['ChainId'],
Definition[T]['SchemaType'],
Definition[T]['ProviderType'],
Definition[T]['Signature'],
Definition[T]['Block'],
Definition[T]['Transaction'],
Definition[T]['TransactionReceipt'],
Definition[T]['TransactionDetailed'],
Definition[T]['TransactionSignature'],
Definition[T]['Web3'],
Definition[T]['Web3Provider']
>
export type Web3UIScope<
S extends 'all' | void = void,
T extends NetworkPluginID = NetworkPluginID,
> = S extends 'all'
? Web3UIAll
: Web3Plugin.UI.UI<Definition[T]['ChainId'], Definition[T]['ProviderType'], Definition[T]['NetworkType']>
export type Web3HubOptionsScope<
S extends 'all' | void = void,
T extends NetworkPluginID = NetworkPluginID,
Indicator = number,
> = S extends 'all' ? Web3HubOptionsAll : HubOptions<Definition[T]['ChainId'], Indicator>
export type Web3HubScope<
S extends 'all' | void = void,
T extends NetworkPluginID = NetworkPluginID,
> = S extends 'all'
? Web3HubAll
: Hub<Definition[T]['ChainId'], Definition[T]['SchemaType'], Definition[T]['GasOption']>
}

// S extends 'all' | void = void, T extends NetworkPluginID = NetworkPluginID
Loading