Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: mf-3301 respect to scoped domains (#8749)
- Loading branch information
Showing
9 changed files
with
93 additions
and
34 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
5 changes: 3 additions & 2 deletions
5
packages/plugins/RSS3/src/SNSAdaptor/hooks/useAddressLabel.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 type { NetworkPluginID } from '@masknet/shared-base' | ||
import { useReverseAddress, useWeb3State } from '@masknet/web3-hooks-base' | ||
import { ScopedDomainsContainer, useReverseAddress, useWeb3State } from '@masknet/web3-hooks-base' | ||
|
||
export function useAddressLabel(address: string, pluginID?: NetworkPluginID): string { | ||
const { Others } = useWeb3State() | ||
const { getDomain } = ScopedDomainsContainer.useContainer() | ||
|
||
const { value } = useReverseAddress(pluginID, address) | ||
const label = value ?? Others?.formatAddress(address, 4) ?? address | ||
const label = getDomain(address) || value || Others?.formatAddress(address, 4) || address | ||
return label | ||
} |
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,26 @@ | ||
import { createContainer } from 'unstated-next' | ||
import { useCallback, useState } from 'react' | ||
|
||
function useMap() { | ||
const [map, setMap] = useState<Record<string, string>>({}) | ||
|
||
const setPair = useCallback((address: string, domain: string) => { | ||
setMap((map) => { | ||
const key = address.toLowerCase() | ||
if (map[key] === domain) return map | ||
return { ...map, [key]: domain } | ||
}) | ||
}, []) | ||
const getDomain = useCallback( | ||
(address: string) => { | ||
return map[address.toLowerCase()] | ||
}, | ||
[map], | ||
) | ||
|
||
return { setPair, getDomain } | ||
} | ||
|
||
export const ScopedDomainsContainer = createContainer(useMap) | ||
|
||
ScopedDomainsContainer.Provider.displayName = 'ScopedDomainsContainer.Provider' |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.