-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: handle account icon's tooltip translations (#1607)
- Loading branch information
Showing
8 changed files
with
166 additions
and
128 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
27 changes: 27 additions & 0 deletions
27
packages/extension-polkagate/src/hooks/useHasIdentityTooltipText.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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2019-2024 @polkadot/extension-polkagate authors & contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { useMemo } from 'react'; | ||
|
||
import { useChain, useTranslation } from '.'; | ||
|
||
export default function useHasIdentityTooltipText (address: string | undefined, hasID: boolean | undefined): string { | ||
const { t } = useTranslation(); | ||
|
||
const chain = useChain(address); | ||
|
||
return useMemo(() => { | ||
if (!chain) { | ||
return t('Account is in Any Chain mode'); | ||
} | ||
|
||
switch (hasID) { | ||
case true: | ||
return t('Has identity'); | ||
case false: | ||
return t('No identity'); | ||
default: | ||
return t('Checking'); | ||
} | ||
}, [chain, hasID, t]); | ||
} |
35 changes: 35 additions & 0 deletions
35
packages/extension-polkagate/src/hooks/useHasProxyTooltipText.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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2019-2024 @polkadot/extension-polkagate authors & contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { useMemo } from 'react'; | ||
|
||
import { useInfo, useProxies, useTranslation } from '.'; | ||
|
||
export default function useHasProxyTooltipText (address: string | undefined): { hasProxy: boolean | undefined; proxyTooltipTxt: string; } { | ||
const { t } = useTranslation(); | ||
|
||
const { api, chain, formatted } = useInfo(address); | ||
|
||
const proxies = useProxies(api, formatted); | ||
const hasProxy = proxies ? !!proxies.length : undefined; | ||
|
||
const proxyTooltipTxt = useMemo(() => { | ||
if (!chain) { | ||
return t('Account is in Any Chain mode'); | ||
} | ||
|
||
switch (hasProxy) { | ||
case true: | ||
return t('Has proxy'); | ||
case false: | ||
return t('No proxy'); | ||
default: | ||
return t('Checking'); | ||
} | ||
}, [chain, hasProxy, t]); | ||
|
||
return { | ||
hasProxy, | ||
proxyTooltipTxt | ||
}; | ||
} |
53 changes: 53 additions & 0 deletions
53
packages/extension-polkagate/src/hooks/useIsRecoverableTooltipText.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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2019-2024 @polkadot/extension-polkagate authors & contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import type { Option } from '@polkadot/types'; | ||
//@ts-ignore | ||
import type { PalletRecoveryRecoveryConfig } from '@polkadot/types/lookup'; | ||
|
||
import { useEffect, useMemo, useState } from 'react'; | ||
|
||
import { useInfo, useTranslation } from '.'; | ||
|
||
export default function useIsRecoverableTooltipText (address: string | undefined): { isRecoverable: boolean | undefined; recoverableToolTipTxt: string; } { | ||
const { t } = useTranslation(); | ||
|
||
const { api, chain, formatted } = useInfo(address); | ||
|
||
const [isRecoverable, setRecoverable] = useState<boolean | undefined>(); | ||
|
||
useEffect((): void => { | ||
if (!api || !formatted) { | ||
return; | ||
} | ||
|
||
api.query?.['recovery']?.['recoverable'](formatted) | ||
.then((result) => { | ||
const recoveryOpt = result as Option<PalletRecoveryRecoveryConfig> | ||
|
||
setRecoverable(!!recoveryOpt.isSome); | ||
}) | ||
.catch(console.error); | ||
}, [api, formatted]); | ||
|
||
const recoverableToolTipTxt = useMemo(() => { | ||
if (!chain) { | ||
return t('Account is in Any Chain mode'); | ||
; | ||
} | ||
|
||
switch (isRecoverable) { | ||
case true: | ||
return t('Recoverable'); | ||
case false: | ||
return t('Not recoverable'); | ||
default: | ||
return t('Checking'); | ||
} | ||
}, [chain, isRecoverable, t]); | ||
|
||
return { | ||
isRecoverable, | ||
recoverableToolTipTxt | ||
}; | ||
} |
Oops, something went wrong.