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

feat: networks and tokens opt-in enhancements #1162

Conversation

0xKheops
Copy link
Contributor

@0xKheops 0xKheops commented Nov 28, 2023

  • Suspense for all networks & balances, remove shimmers
  • Fix subscription by params
  • Fix add networks/tokens from dapps
  • Fix remove custom networks/tokens
  • Specify which chaindata branch to pull data from
  • Buttons to enable/disable all networks & tokens
  • Provision balance rows on subscription startup with an "initializing" status, to let FE knows which ones are pending
  • shimmers for initializing balances

TODO :

  • update subscribeByParams to leverage initializing rows

@@ -153,6 +164,9 @@ interface BalanceModuleCommon<
callback: SubscriptionCallback<Balances>
): Promise<UnsubscribeFn>

/** Used to provision balances in db while they are fetching for the first time */
getPlaceholderBalance(tokenId: TTokenType["id"], address: Address): BalanceJson

/** Fetch balances for this module with optional filtering */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's beautiful


for (const balanceModule of balanceModules) {
const addressesByToken = addressesByTokenByModule[balanceModule.type] ?? {}
for (const [tokenId, addresses] of Object.entries(addressesByToken))
for (const address of addresses) {
if (!existingBalances.find((b) => b.address === address && b.tokenId === tokenId))
if (!existingBalancesKeys.has(`${tokenId}:${address}`))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥🔥🔥

Copy link
Contributor Author

@0xKheops 0xKheops Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x4 faster with a set than with a string array :)

@@ -37,7 +36,7 @@ const rawBalancesState = atom<BalanceJson[]>({

return () => sub.unsubscribe()
},
// instruct backend to keep db syncrhonized while this atom is in use
// instruct backend to keep db synchronized while this atom is in use
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:jean:

@@ -58,7 +58,7 @@ const useSupportedTokenIds = (chains?: Chain[], tokens?: Token[], address?: stri
useEffect(() => {
// pull up to date list from github
// note that there is a 5min cache on github files
fetch(`${githubChaindataBaseUrl}/tokens-buyable.json`)
fetch(`${githubChaindataBaseUrl}/data/tokens-buyable.json`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should totally move this to https://github.com/TalismanSociety/talisman-config

Perhaps even before we release the update that includes these changes?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it belongs in chaindata, but wdyt @0xKheops?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, will try

Comment on lines -150 to -183
const { account, accounts } = useSelectedAccount()
const { networkFilter } = usePortfolio()

const hasEthereumAccount = useMemo(() => accounts.some((a) => a.type === "ethereum"), [accounts])

// if specific account we have 2 rows minimum, if all accounts we have 4
const skeletons = useMemo(() => {
// in this case we don't know the number of min rows, balances should be already loaded anyway
if (networkFilter) return symbolBalances.length ? 0 : 1

// If no accounts then it means "all accounts", expect all default tokens (substrate + eth)
// if account has a genesis hash then we expect only 1 chain
// otherwise we expect default tokens for account type
const expectedRows = (() => {
if (!account)
return (
DEFAULT_PORTFOLIO_TOKENS_SUBSTRATE.length +
(hasEthereumAccount ? DEFAULT_PORTFOLIO_TOKENS_ETHEREUM.length : 0)
)
if (account.genesisHash) return 1

// DEFAULT_TOKENS are only shown for accounts with no balance
const accountHasSomeBalance =
balances.find({ address: account?.address }).sum.planck.total > 0n
if (accountHasSomeBalance) return 0

if (account.type === "ethereum") return DEFAULT_PORTFOLIO_TOKENS_ETHEREUM.length
return DEFAULT_PORTFOLIO_TOKENS_SUBSTRATE.length
})()

return symbolBalances.length < expectedRows ? expectedRows - symbolBalances.length : 0
}, [account, hasEthereumAccount, networkFilter, balances, symbolBalances.length])

return { symbolBalances, availableSymbolBalances, lockedSymbolBalances, skeletons }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feels good

Copy link
Member

@alecdwm alecdwm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🔥

@0xKheops 0xKheops marked this pull request as ready for review December 7, 2023 06:42
@0xKheops 0xKheops merged commit 8b26fab into refactor/distributed-metadata Dec 7, 2023
4 checks passed
@0xKheops 0xKheops deleted the feat/networks-and-tokens-opt-in-enhancements branch December 7, 2023 06:42
alecdwm added a commit that referenced this pull request Jan 5, 2024
* wip: fetch chaindata from github

* wip: metadata updater

* chore: consolidated balance modules

* wip: metadata updater

* wip: port substrate-assets module

* wip: port substrate-tokens module

* wip: port substrate-equilibrium module

* wip: port substrate-psp22 module

* wip: rm substrate-orml module and @talismn/mutate-metadata

* fix: jest mocks for chaindata-provider-extension

* wip: update miniMetadatas when hydrating tokens

* fix: remove deprecated test

* fix: changesets referencing deleted packages

* wip: update miniMetadatas when hydrating tokens

* wip: missing miniMetadata in balance modules

* wip: build evm tokens list in chaindata db

* fix: availableTokenLogoFilenames export

* feat: Known EVM networks & tokens (#1126)

* wip: chaindata logos & ignore non default chains

* feat: disable networks

* chore: cleanup

* feat: enable/disable tokens

* feat: search & enable known evm networks

* fix: perf when updating networks & tokens

* chore: cleanup

* fix: balances subscription init performance

* fix: larger toggle click zone

* fix: reset evm network

* fix: virtualized rows

* fix: filter behavior

* fix: token filter

* feat: clear button on search input

* feat: token form adjustments

* feat: enable toggle on chains forms

* fix: wording

* fix: remove deleted packages from changesets

* fix: inconsistent peerDeps in packages

* feat: added button to reset chain enabled status to talisman default

* fix: inconsistent peerDeps in packages (again)

* fix: show error message when @talismn/scale is used but not initialized

* fix: remove deleted packages from changesets

* fix: incorrect `EvmNativeModuleConfig.symbol` type

* fix: use type `string` for `contractAddress` in `EvmErc20ModuleConfig`

* fix: `ChainConnectorEvm` constructor params

* fix: init chaindata

* fix: performance improvements & decoding via subshape

* fix: missing reset buttons on display balances toggles

* fix: pull miniMetadatas and tokens from chaindata

* fix: print sentry events to the console in development

* fix: crash when chaindata chain has no balancesConfig key

* fix: substrate chain reset

* fix: crash on prod builds

* chore: update @talismn/subshape-fork

* fix: separate init data into its own vendor-background script to keep all scripts below 4MB

* fix: further split up init data to keep all scripts below 4MB

* fix: background script not starting when `dependsOn` is an array

* feat: networks and tokens opt-in enhancements (#1162)

* fix: enable checks & unnecessary balance reset

* fix: tokensWithTestnetsState

* fix: balances in account pickers

* feat: debug from specific chaindata branch

* fix: layout shifts on load

* fix: don't refetch tokens when polling

* feat: enable/disable all substrate networks

* feat: enable/disable all networks

* feat: initial delay for polled balances

* feat: message if no balance to display

* fix: buyable tokens json url

* fix: ignore account all in query string

* fix: delete custom network

* fix: reset balances sub if tokens change

* fix: show balances for import when onboarding

* fix: typos in comments

* feat: initialize empty balances

* fix: balance status

* fix: chainId from tokenId

* fix: cleanup

* fix: don't display balances until initialized

* chore: cleanup

* fix: optimize add missing balances code

* fix: tests

* feat: shimmer when initializing balance

* fix: absolute imports in balances handler

* fix: absolute imports in tokenRates handler

* fix: show updateTokenRates warning in function docstring

---------

Co-authored-by: alecdwm <alec@owls.io>

* refactor: getChainIdFromTokenId

* fix: remove useless top level suspense

* fix: merge regression

* refactor: atoms & suspense performance

* fix: layout shift on token & chain logos

* fix: tests

* chore: cleanup

* fix: suspense on tokenRates to prevent flickering

* feat: init balances for balancesByParams

* feat: maintain subscription when opening dashboard

* fix: cleanup

* refactor: pull buy tokens config from config repo

* fix: wording

* fix: no assets message

* fix: remove changeset for deleted pkg

* fix: changeset

* chore: cleanup

* feat: merge main atoms into one (#1187)

* feat: merge main atoms into one

* feat: merge atoms

* fix: tests

* fix: vendor-talisman cacheGroup not including init data

* fix: don't import chaindata init data until it's actually used

* fix: **really** don't import chaindata init data until it's actually used

* chore: update init data

* feat: assets discovery (#1191)

* fix: responsive account name alignment in portfolio account picker (#1183)

* fix: responsive account name alignment in portfolio account picker

* fix: don't break text-ellipsis

* fix: allow blockeplorer to be null in wallet_addEthereumChain (#1175)

* wip: asset discovery

* refactor: optimize scan

* feat: token rates for asset discovery

* feat: scan contextual menu

* fix: prevent bug in analytics (#1186)

* fix: remove nonce when estimating gas to validate txs (#1189)

* feat: revoke approval signing ui (#1190)

* fix: layout shift on dashboard asset rows (#1192)

* fix: wording

* Upgrade Ledger deps (#1193)

* chore: upgrade ethereum ledger dependencies

* fix: improve Ledger connection error messages

* chore: specify version of ledger/hw-transport library

* chore: version bump 1.20.1 (#1194)

* chore: rename enabled to active

* fix: tests

* chore: cleanup

* fix: enable => activate

* fix: log timer warnings

* feat: options param on main hooks

* feat: scan native tokens

* feat: scan & activate native tokens

* fix: testnets management

* fix: prevent auto switch to disabled network

* feat: enrich when adding network from dapp

* feat: migrate to new evm default networks

* feat: privacy notice

* fix: typo

* feat: launch scan after adding account

* feat: add border to notification container

* feat: alerts if new tokens detected

* chore: self review

* chore: remove comment

* fix: persist tokens count

* fix: incorrect instantiation of `ChainConnectorEvm` (#1199)

* fix: incorrect instantiation of `ChainConnectorEvm`

* fix: combine ChaindataEvmNetworkProvider and ChaindataTokenProvider in ChainConnectorEvm

---------

Co-authored-by: alecdwm <alec@owls.io>

* fix: connected includes removed addreses (#1205)

* fix: invoke stopListening when an error is caught (#1203)

* feat: rework tokens page

* fix: poll crowdloan contributions (fixes #1152)

* feat: token info context menu

* fix: erc20 check

---------

Co-authored-by: Alec WM <alec@owls.io>
Co-authored-by: Chid Gilovitz <chid@talisman.xyz>
Co-authored-by: Tiến Nguyễn Khắc <tien.nguyenkhac@icloud.com>
Co-authored-by: Chris Ling <81092286+chrisling-dev@users.noreply.github.com>

---------

Co-authored-by: Kheops <26880866+0xKheops@users.noreply.github.com>
Co-authored-by: Chid Gilovitz <chid@talisman.xyz>
Co-authored-by: Tiến Nguyễn Khắc <tien.nguyenkhac@icloud.com>
Co-authored-by: Chris Ling <81092286+chrisling-dev@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants