Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bundle of ui adjustments #1721

Merged
merged 6 commits into from
Nov 29, 2024
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
@@ -1,4 +1,5 @@
<!-- version: v2.1.0 -->

**<span class="icon">🔏</span> New Polkadot Signing UI:** Talisman now shows customised and detailed information about each Polkadot transaction you're signing.

**<span class="icon">🍸</span> Polkadot Dry Runs:** On compatible chains, Talisman will warn you if a dry-run identifies that the transaction is likely to fail.
22 changes: 16 additions & 6 deletions apps/extension/src/ui/domains/Asset/TokenPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,23 @@ const TokensList: FC<TokensListProps> = ({

// apply user search
const tokens = useMemo(() => {
if (!search) return tokensWithBalances

const ls = search?.toLowerCase()
return tokensWithBalances.filter(
(t) =>
!ls ||
t.token.symbol.toLowerCase().includes(ls) ||
t.chainNameSearch?.toLowerCase().includes(ls),
)
return tokensWithBalances
.filter(
(t) =>
!ls ||
t.token.symbol.toLowerCase().includes(ls) ||
t.chainNameSearch?.toLowerCase().includes(ls),
)
.sort((t1, t2) => {
const s1 = t1.token.symbol.toLowerCase()
const s2 = t2.token.symbol.toLowerCase()
if (s1 === ls && s2 !== ls) return -1
if (s1 !== ls && s2 === ls) return 1
return 0
})
}, [search, tokensWithBalances])

const handleAccountClick = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const AssetDiscoveryDashboardAlert = () => {
</Suspense>
),
{
autoClose: false,
autoClose: 60_000,
toastId: ASSET_DISCOVERY_TOAST_ID,
onClick: () => {
navigate("/settings/networks-tokens/asset-discovery")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ const AddressFormatError = ({ chain }: { chain?: Chain }) => {
return (
<div className="h-min-h-full align-center flex w-full flex-col items-center gap-4 px-12 py-7">
<XOctagonIcon className="text-brand-orange text-lg" />
<span className="text-body-secondary">{t("Address Format Mismatch")}</span>
<p className="text-body-disabled text-center">
<span className="text-body">{t("Address Format Mismatch")}</span>
<p className="text-body-secondary mt-4 text-center">
<Trans
t={t}
defaults="The address you've entered is not compatible with the <Chain><ChainLogo />{{chainName}}</Chain> chain. Please enter a compatible address or select a different chain to send on."
components={{
Chain: <div className="text-body-secondary inline-flex items-baseline gap-1" />,
Chain: <div className="text-body inline-flex items-baseline gap-1" />,
ChainLogo: <ChainLogo className="self-center" id={chain?.id} />,
}}
values={{ chainName: chain?.name ?? t("Unknown") }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const ViewDetailsButton: FC<ViewDetailsButtonProps> = ({
"text-body-inactive hover:text-body-secondary flex items-center gap-2",
className,
hasError && "text-alert-warn",
hide && "hidden",
hide && "invisible",
)}
>
{hasClickRequest && isAnalysing ? (
Expand Down
73 changes: 37 additions & 36 deletions packages/extension-core/src/domains/assetDiscovery/autoEnable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import { EvmNetwork, EvmNetworkId } from "@talismn/chaindata-provider"
import { liveQuery } from "dexie"
import { log } from "extension-shared"
import { uniq } from "lodash"
import { BehaviorSubject, combineLatest, debounceTime, distinctUntilChanged } from "rxjs"
import { BehaviorSubject, combineLatest, distinctUntilChanged } from "rxjs"

import { db } from "../../db"
import { chaindataProvider } from "../../rpcs/chaindata"
import { isEvmToken } from "../../util/isEvmToken"
import { activeEvmNetworksStore } from "../ethereum/store.activeEvmNetworks"
import { activeTokensStore } from "../tokens/store.activeTokens"

const MIN_INTERVAL = 30_000 // 30 seconds, to prevent balances subscriptions from restarting too often
import { assetDiscoveryStore } from "./store"

const isEnabled$ = new BehaviorSubject(false)

Expand All @@ -22,43 +21,45 @@ isEnabled$.pipe(distinctUntilChanged()).subscribe((isEnabled) => {
if (!isEnabled) return

return combineLatest([
assetDiscoveryStore.observable,
liveQuery(() => db.assetDiscovery.toArray()),
activeTokensStore.observable,
activeEvmNetworksStore.observable,
])
.pipe(debounceTime(MIN_INTERVAL))
.subscribe(async ([discoveredBalances, activeTokens, activeEvmNetworks]) => {
try {
const tokenIds = uniq(discoveredBalances.map((entry) => entry.tokenId))
const tokens = (
await Promise.all(tokenIds.map((tokenId) => chaindataProvider.tokenById(tokenId)))
).filter(isEvmToken)
]).subscribe(async ([assetDiscovery, discoveredBalances, activeTokens, activeEvmNetworks]) => {
try {
// exit if a scan is active, to avoid restarting balance subscription too often
if (assetDiscovery.currentScanId) return

const tokenIds = uniq(discoveredBalances.map((entry) => entry.tokenId))
const tokens = (
await Promise.all(tokenIds.map((tokenId) => chaindataProvider.tokenById(tokenId)))
).filter(isEvmToken)

const evmNetworkIds = uniq(
tokens.map((token) => token.evmNetwork?.id).filter((id): id is EvmNetworkId => !!id),
)
const evmNetworks = (
await Promise.all(evmNetworkIds.map((id) => chaindataProvider.evmNetworkById(id)))
).filter((network): network is EvmNetwork => !!network)
const evmNetworkIds = uniq(
tokens.map((token) => token.evmNetwork?.id).filter((id): id is EvmNetworkId => !!id),
)
const evmNetworks = (
await Promise.all(evmNetworkIds.map((id) => chaindataProvider.evmNetworkById(id)))
).filter((network): network is EvmNetwork => !!network)

// activate tokens that have not been explicitely disabled
for (const token of tokens)
if (activeTokens[token.id] === undefined) {
log.debug("[AssetDiscovery] Automatically enabling discovered asset", { token })
activeTokensStore.setActive(token.id, true)
}
// activate tokens that have not been explicitely disabled
for (const token of tokens)
if (activeTokens[token.id] === undefined) {
log.debug("[AssetDiscovery] Automatically enabling discovered asset", { token })
activeTokensStore.setActive(token.id, true)
}

// activate networks that have not been explicitely disabled
for (const evmNetwork of evmNetworks)
if (activeEvmNetworks[evmNetwork.id] === undefined) {
log.debug("[AssetDiscovery] Automatically enabling discovered network", { evmNetwork })
activeEvmNetworksStore.setActive(evmNetwork.id, true)
}
} catch (err) {
log.error("[AssetDiscovery] Failed to automatically enable discovered assets", {
err,
discoveredBalances,
})
}
})
// activate networks that have not been explicitely disabled
for (const evmNetwork of evmNetworks)
if (activeEvmNetworks[evmNetwork.id] === undefined) {
log.debug("[AssetDiscovery] Automatically enabling discovered network", { evmNetwork })
activeEvmNetworksStore.setActive(evmNetwork.id, true)
}
} catch (err) {
log.error("[AssetDiscovery] Failed to automatically enable discovered assets", {
err,
discoveredBalances,
})
}
})
})