-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move some API to infra/.../context and move some others to …
…web3-provider (#10775)
- Loading branch information
1 parent
dd4efff
commit 5dcfe20
Showing
74 changed files
with
261 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Services from '#services' | ||
import { Providers } from '@masknet/web3-providers' | ||
import { ProviderType } from '@masknet/web3-shared-evm' | ||
import { NextSharedUIContext } from '../utils/plugin-context-shared-ui.js' | ||
|
||
Providers[ProviderType.MaskWallet].setIOContext({ | ||
allPersonas: NextSharedUIContext.allPersonas, | ||
resetAllWallets: Services.Wallet.resetAllWallets, | ||
removeWallet: Services.Wallet.removeWallet, | ||
renameWallet: Services.Wallet.renameWallet, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// This file will be virtualized in the future. | ||
// Currently all plugins access the same value, but we can virtualize them in the future. | ||
|
||
import type { PersonaInformation } from '@masknet/shared-base' | ||
import type { Subscription } from 'use-subscription' | ||
|
||
export interface __UIContext__ { | ||
allPersonas: Subscription<readonly PersonaInformation[]> | ||
} | ||
export let allPersonas: __UIContext__['allPersonas'] | ||
export function __setUIContext__(value: __UIContext__) { | ||
allPersonas = value.allPersonas | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// This file will be virtualized in the future. | ||
// Currently all plugins access the same value, but we can virtualize them in the future. | ||
|
||
import type { Subscription } from 'use-subscription' | ||
import type { IdentityResolved } from '../types.js' | ||
import { __setUIContext__, type __UIContext__ } from '../dom/context.js' | ||
|
||
export * from '../dom/context.js' | ||
export interface __SiteAdaptorContext__ extends __UIContext__ { | ||
lastRecognizedProfile: Subscription<IdentityResolved | undefined> | ||
currentVisitingProfile: Subscription<IdentityResolved | undefined> | ||
} | ||
export let lastRecognizedProfile: __SiteAdaptorContext__['lastRecognizedProfile'] | ||
export let currentVisitingProfile: __SiteAdaptorContext__['currentVisitingProfile'] | ||
export function __setSiteAdaptorContext__(value: __SiteAdaptorContext__) { | ||
__setUIContext__(value) | ||
lastRecognizedProfile = value.lastRecognizedProfile | ||
currentVisitingProfile = value.currentVisitingProfile | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
import { useSubscription } from 'use-subscription' | ||
import { EMPTY_ARRAY } from '@masknet/shared-base' | ||
import { useSiteAdaptorContext } from '../dom/useSiteAdaptorContext.js' | ||
import { allPersonas } from '../dom/context.js' | ||
|
||
export function useAllPersonas() { | ||
const { allPersonas } = useSiteAdaptorContext() | ||
return useSubscription(allPersonas ?? EMPTY_ARRAY) | ||
return useSubscription(allPersonas) | ||
} |
5 changes: 3 additions & 2 deletions
5
packages/plugin-infra/src/site-adaptor/useCurrentPersonaInformation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import { useSubscription } from 'use-subscription' | ||
import { UNDEFINED } from '@masknet/shared-base' | ||
import { useSiteAdaptorContext } from '../dom/useSiteAdaptorContext.js' | ||
import { allPersonas } from '../dom/context.js' | ||
|
||
export function useCurrentPersonaInformation() { | ||
const { currentPersona, allPersonas } = useSiteAdaptorContext() | ||
const { currentPersona } = useSiteAdaptorContext() | ||
const current = useSubscription(currentPersona ?? UNDEFINED) | ||
const personas = useSubscription(allPersonas ?? UNDEFINED) | ||
const personas = useSubscription(allPersonas) | ||
return personas?.find((x) => x.identifier.rawPublicKey === current?.rawPublicKey) | ||
} |
6 changes: 2 additions & 4 deletions
6
packages/plugin-infra/src/site-adaptor/useCurrentVisitingIdentity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
import { useSubscription } from 'use-subscription' | ||
import { UNDEFINED } from '@masknet/shared-base' | ||
import { useSiteAdaptorContext } from '../dom/useSiteAdaptorContext.js' | ||
import { currentVisitingProfile } from './context.js' | ||
|
||
export function useCurrentVisitingIdentity() { | ||
const { currentVisitingProfile } = useSiteAdaptorContext() | ||
return useSubscription(currentVisitingProfile ?? UNDEFINED) | ||
return useSubscription(currentVisitingProfile) | ||
} |
3 changes: 1 addition & 2 deletions
3
packages/plugin-infra/src/site-adaptor/useLastRecognizedIdentity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
import { useSubscription } from 'use-subscription' | ||
import { UNDEFINED } from '@masknet/shared-base' | ||
import { useSiteAdaptorContext } from '../dom/useSiteAdaptorContext.js' | ||
import { lastRecognizedProfile } from './context.js' | ||
|
||
export function useLastRecognizedIdentity() { | ||
const { lastRecognizedProfile } = useSiteAdaptorContext() | ||
return useSubscription(lastRecognizedProfile ?? UNDEFINED) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.