Skip to content

Commit

Permalink
wip: scale-ts
Browse files Browse the repository at this point in the history
  • Loading branch information
alecdwm committed Apr 17, 2024
1 parent f161a4a commit 8cda5cd
Show file tree
Hide file tree
Showing 22 changed files with 823 additions and 706 deletions.
30 changes: 20 additions & 10 deletions apps/balances-demo/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import "anylogger-loglevel"
import "./index.css"

import { BalancesProvider } from "@talismn/balances-react"
import loglevel from "loglevel"
import { StrictMode, useState } from "react"
import { createRoot } from "react-dom/client"

import { App } from "./App"

loglevel.setLevel("info")

const onfinalityApiKey = undefined

const Root = () => {
Expand All @@ -28,16 +31,23 @@ const Root = () => {
// // westend
// "0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e",
// ]}
// enabledTokens={[
// // DOT (polkadot relay chain)
// "polkadot-substrate-native",
// // USDC (polkadot asset hub)
// "polkadot-asset-hub-substrate-assets-1337-usdc",
// // ETH (ethereum mainnet)
// "1-evm-native",
// // GM (gm chain)
// "gm-substrate-tokens-gm",
// ]}
enabledTokens={[
"polkadot-substrate-native",
"acala-substrate-native",
"astar-substrate-native",
"composable-substrate-native",
"crust-substrate-native",
"hydradx-substrate-native",
"interlay-substrate-native",
"karura-substrate-native",
"kintsugi-substrate-native",
"mangata-substrate-native",
"moonbeam-substrate-native",
"moonriver-substrate-native",
"polimec-substrate-native",
"westend-testnet-substrate-native",
"rococo-testnet-substrate-native",
]}
>
<App withTestnets={withTestnets} setWithTestnets={setWithTestnets} />
</BalancesProvider>
Expand Down
13 changes: 7 additions & 6 deletions packages/balances-react/src/atoms/balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ const balancesSubscriptionAtomEffect = atomEffect((get) => {
addressesByTokenByModule[token.type][token.id] = allAddresses.filter((address) => {
// for each address, fetch balances only from compatible chains
return isEthereumAddress(address)
? !!token.evmNetwork?.id || chainsById[token.chain?.id ?? ""]?.account === "secp256k1"
: !!token.chain?.id
? token.evmNetwork?.id || chainsById[token.chain?.id ?? ""]?.account === "secp256k1"
: token.chain?.id && chainsById[token.chain?.id ?? ""]?.account !== "secp256k1"
})
})

Expand Down Expand Up @@ -212,11 +212,12 @@ const balancesSubscriptionAtomEffect = atomEffect((get) => {
const hasChain = balance.chainId && chainIds.has(balance.chainId)
const hasEvmNetwork = balance.evmNetworkId && evmNetworkIds.has(balance.evmNetworkId)
const chainUsesSecp256k1Accounts = chain?.account === "secp256k1"
if (!isEthereumAddress(balance.address) && !hasChain) {
return true
if (!isEthereumAddress(balance.address)) {
if (!hasChain) return true
if (chainUsesSecp256k1Accounts) return true
}
if (isEthereumAddress(balance.address) && !(hasEvmNetwork || chainUsesSecp256k1Accounts)) {
return true
if (isEthereumAddress(balance.address)) {
if (!hasEvmNetwork && !chainUsesSecp256k1Accounts) return true
}

// keep balance
Expand Down
14 changes: 6 additions & 8 deletions packages/balances-react/src/atoms/chaindata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ export const miniMetadatasAtom = atom(async (get) => (await get(chaindataAtom)).
export const chaindataAtom = atomWithObservable((get) => {
const enableTestnets = get(enableTestnetsAtom)

const filterTestnets = <T extends { id: string; isTestnet: boolean }>(items: T[]) =>
items.filter(({ id }) => ["polkadot", "polimec"].includes(id))
const filterMapTestnets = <T extends { id: string; isTestnet: boolean }>(
items: Record<string, T>
) =>
Object.fromEntries(
Object.entries(items).filter(([, { id }]) => ["polkadot", "polimec"].includes(id))
)
const filterTestnets = <T extends { isTestnet: boolean }>(items: T[]) =>
enableTestnets ? items : items.filter(({ isTestnet }) => !isTestnet)
const filterMapTestnets = <T extends { isTestnet: boolean }>(items: Record<string, T>) =>
enableTestnets
? items
: Object.fromEntries(Object.entries(items).filter(([, { isTestnet }]) => !isTestnet))

const filterEnabledTokens = (tokens: Token[]) =>
tokens.filter((token) => token.isDefault || ("isCustom" in token && token.isCustom))
Expand Down
18 changes: 17 additions & 1 deletion packages/balances/src/MiniMetadataUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,23 @@ export class MiniMetadataUpdater {
await balancesDb.miniMetadatas.bulkDelete(unwantedIds)
}

const needUpdates = ["polkadot", "astar", "hydradx", "polimec"]
const needUpdates = [
"polkadot",
"acala",
"astar",
"composable",
"crust",
"hydradx",
"interlay",
"karura",
"kintsugi",
"mangata",
"moonbeam",
"moonriver",
"polimec",
"westend-testnet",
"rococo-testnet",
]
// const needUpdates = Array.from(statusesByChain.entries())
// .filter(([, status]) => status !== "good")
// .map(([chainId]) => chainId)
Expand Down
Loading

0 comments on commit 8cda5cd

Please sign in to comment.