Skip to content

Commit

Permalink
refactor: remove "dapp" & "portal" account filter
Browse files Browse the repository at this point in the history
  • Loading branch information
tien committed Aug 29, 2023
1 parent 9751077 commit c474b82
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 9 deletions.
6 changes: 3 additions & 3 deletions apps/extension/src/core/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ const enable = async (origin: string): Promise<Injected> => {
return new TalismanInjected(messageService.sendMessage) as Injected
}

export const isTalismanHostname = (hostname: string) =>
export const isTalismanHostname = (hostname: string | undefined) =>
hostname === TALISMAN_WEB_APP_DOMAIN ||
(DEBUG && hostname.endsWith(".talisman.pages.dev")) ||
(DEBUG && ["localhost", "127.0.0.1"].includes(hostname))
(DEBUG && hostname?.endsWith(".talisman.pages.dev")) ||
(DEBUG && ["localhost", "127.0.0.1"].includes(hostname ?? ""))

function inject() {
// inject substrate wallet provider
Expand Down
2 changes: 1 addition & 1 deletion apps/extension/src/ui/apps/popup/pages/Connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const Connect: FC<{ className?: string }> = ({ className }) => {
const { id } = useParams<"id">() as KnownRequestIdOnly<"auth">
const authRequest = useRequest(id)
const { popupOpenEvent } = useAnalytics()
const allAccounts = useAccounts(isTalismanHostname(authRequest?.url) ? "portal" : "dapp")
const allAccounts = useAccounts(isTalismanHostname(authRequest?.url) ? "all" : "owned")
const { items: connected, toggle, set } = useSet<string>()
const ethereum = !!authRequest?.request?.ethereum
const [showEthAccounts, setShowEthAccounts] = useState(false)
Expand Down
4 changes: 1 addition & 3 deletions apps/extension/src/ui/hooks/useAccounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const INITIAL_VALUE: AccountJsonAny[] = []
const subscribe = (subject: BehaviorSubject<AccountJsonAny[]>) =>
api.accountsSubscribe((v) => subject.next(v))

export type UseAccountsFilter = "all" | "watched" | "owned" | "portfolio" | "dapp" | "portal"
export type UseAccountsFilter = "all" | "watched" | "owned" | "portfolio"

// TODO migrate to recoil
export const useAccounts = (filter: UseAccountsFilter = "all") => {
Expand All @@ -24,10 +24,8 @@ export const useAccounts = (filter: UseAccountsFilter = "all") => {
)
case "watched":
return allAccounts.filter(({ origin }) => origin === AccountType.Watched)
case "dapp":
case "owned":
return allAccounts.filter(({ origin }) => origin !== AccountType.Watched)
case "portal":
case "all":
return allAccounts
}
Expand Down
2 changes: 1 addition & 1 deletion apps/extension/src/ui/hooks/useAuthorisedSiteById.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const useAuthorisedSiteById = (id: AuthorizedSiteId, type: ProviderType) => {
const sites = useAuthorisedSites()
const availableAddresses = useAccountAddresses(
type === "ethereum",
isTalismanHostname(sites[id]?.url) ? "portal" : "dapp"
isTalismanHostname(sites[id]?.url) ? "all" : "owned"
)

const connected = useMemo(() => {
Expand Down
2 changes: 1 addition & 1 deletion apps/extension/src/ui/hooks/useConnectedAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import useAuthorisedSiteById from "./useAuthorisedSiteById"

export const useConnectedAccounts = (siteId: string, providerType: ProviderType) => {
const { connected, toggleOne, url } = useAuthorisedSiteById(siteId, providerType)
const allAccounts = useAccounts(isTalismanHostname(url) ? "portal" : "dapp")
const allAccounts = useAccounts(isTalismanHostname(url) ? "all" : "owned")
const [showEthAccounts, setShowEthAccounts] = useState(
allAccounts?.some((a) => connected.includes(a.address) && a.type === "ethereum")
)
Expand Down

0 comments on commit c474b82

Please sign in to comment.