Skip to content

Commit

Permalink
Merge pull request #434 from TalismanSociety/feat/support-for-more-as…
Browse files Browse the repository at this point in the history
…sets

feat: support for more assets
  • Loading branch information
chidg authored Jan 25, 2023
2 parents 5a22444 + f7a0b13 commit b083d95
Show file tree
Hide file tree
Showing 73 changed files with 2,041 additions and 1,221 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/publish-pr-snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Publish PR Snapshot

on:
pull_request:
types: [opened, synchronize]

jobs:
publish:
name: "Publish PR Snapshot"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14
cache: yarn
- run: yarn --immutable
- run: yarn changeset version --snapshot pr${{ github.event.pull_request.number }}
- run: yarn build:packages:prod
- run: yarn plugin import workspace-tools
- run: yarn workspaces foreach --verbose --no-private npm publish --tolerate-republish --tag pr${{ github.event.pull_request.number }}
env:
YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
6 changes: 1 addition & 5 deletions apps/balances-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
"@polkadot/api": "^9.1.1",
"@polkadot/extension-dapp": "^0.44.3",
"@talismn/balances": "workspace:^",
"@talismn/balances-evm-erc20": "workspace:^",
"@talismn/balances-evm-native": "workspace:^",
"@talismn/balances-example": "workspace:^",
"@talismn/balances-default-modules": "workspace:^",
"@talismn/balances-react": "workspace:^",
"@talismn/balances-substrate-native": "workspace:^",
"@talismn/balances-substrate-orml": "workspace:^",
"@talismn/chaindata-provider-extension": "workspace:^",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^13.0.0",
Expand Down
7 changes: 1 addition & 6 deletions apps/balances-demo/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { web3AccountsSubscribe, web3Enable } from "@polkadot/extension-dapp"
import { EvmErc20Module } from "@talismn/balances-evm-erc20"
import { EvmNativeModule } from "@talismn/balances-evm-native"
import { balanceModules } from "@talismn/balances-default-modules"
import { useBalances, useChaindata, useTokens } from "@talismn/balances-react"
import { SubNativeModule } from "@talismn/balances-substrate-native"
import { SubOrmlModule } from "@talismn/balances-substrate-orml"
import { Token } from "@talismn/chaindata-provider"
import { formatDecimals } from "@talismn/util"
import { useEffect, useMemo, useState } from "react"

const balanceModules = [SubNativeModule, SubOrmlModule, EvmNativeModule, EvmErc20Module]

export function App(): JSX.Element {
const chaindata = useChaindata()
const addresses = useExtensionAddresses()
Expand Down
5 changes: 1 addition & 4 deletions apps/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@
"@substrate/txwrapper-core": "*",
"@svgr/webpack": "^6.5.1",
"@talismn/balances": "workspace:^",
"@talismn/balances-evm-erc20": "workspace:^",
"@talismn/balances-evm-native": "workspace:^",
"@talismn/balances-default-modules": "workspace:^",
"@talismn/balances-react": "workspace:^",
"@talismn/balances-substrate-native": "workspace:^",
"@talismn/balances-substrate-orml": "workspace:^",
"@talismn/chaindata-js": "^0.0.7",
"@talismn/chaindata-provider": "workspace:^",
"@talismn/token-rates": "workspace:^",
Expand Down
12 changes: 6 additions & 6 deletions apps/extension/src/core/domains/balances/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ import { SingleAddress } from "@polkadot/ui-keyring/observable/types"
import { assert } from "@polkadot/util"
import * as Sentry from "@sentry/browser"
import { AddressesByToken, db as balancesDb } from "@talismn/balances"
import { EvmErc20Module } from "@talismn/balances-evm-erc20"
import { EvmNativeModule } from "@talismn/balances-evm-native"
import { SubNativeModule } from "@talismn/balances-substrate-native"
import { SubOrmlModule } from "@talismn/balances-substrate-orml"
import { balanceModules as defaultBalanceModules } from "@talismn/balances-default-modules"
import { Token, TokenList } from "@talismn/chaindata-provider"
import { encodeAnyAddress } from "@talismn/util"
import { liveQuery } from "dexie"
import isEqual from "lodash/isEqual"
import pick from "lodash/pick"
import { ReplaySubject, Subject, combineLatest, firstValueFrom } from "rxjs"

export const balanceModules = defaultBalanceModules

type ChainIdAndHealth = Pick<Chain, "id" | "isHealthy" | "genesisHash" | "account">
type EvmNetworkIdAndHealth = Pick<
EvmNetwork,
Expand All @@ -37,8 +36,6 @@ type TokenIdAndType = Pick<Token, "id" | "type" | "chain" | "evmNetwork">

type SubscriptionsState = "Closed" | "Closing" | "Open"

export const balanceModules = [SubNativeModule, SubOrmlModule, EvmNativeModule, EvmErc20Module]

// TODO: Fix this class up
// 1. It shouldn't need a whole extra copy of addresses+chains+networks separate to the db
// 2. It shouldn't subscribe to all this data when subscriptions aren't even open
Expand Down Expand Up @@ -239,6 +236,9 @@ export class BalanceStore {
// remove balance if token doesn't exist
if (tokens[balance.tokenId] === undefined) return true

// remove balance if module doesn't exist
if (!balanceModules.find((module) => module.type === balance.source)) return true

// keep balance
return false
})
Expand Down
24 changes: 24 additions & 0 deletions apps/extension/src/core/domains/transactions/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,18 @@ export default class AssetTransferHandler extends ExtensionHandler {
})
if (tokenType === "evm-erc20")
throw new Error("Erc20 token transfers are not implemented in this version of Talisman.")
if (tokenType === "substrate-assets")
throw new Error(
`${token.symbol} transfers on ${token.chain.id} are not implemented in this version of Talisman.`
)
if (tokenType === "substrate-tokens")
throw new Error(
`${token.symbol} transfers on ${token.chain.id} are not implemented in this version of Talisman.`
)
if (tokenType === "substrate-equilibrium")
throw new Error(
`${token.symbol} transfers on ${token.chain.id} are not implemented in this version of Talisman.`
)

// force compilation error if any token types don't have a case
const exhaustiveCheck: never = tokenType
Expand Down Expand Up @@ -202,6 +214,18 @@ export default class AssetTransferHandler extends ExtensionHandler {
return await OrmlTokenTransfersRpc.checkFee(chainId, tokenId, amount, pair, toAddress, tip)
if (tokenType === "evm-erc20")
throw new Error("Erc20 token transfers are not implemented in this version of Talisman.")
if (tokenType === "substrate-assets")
throw new Error(
`${token.symbol} transfers on ${token.chain.id} are not implemented in this version of Talisman.`
)
if (tokenType === "substrate-tokens")
throw new Error(
`${token.symbol} transfers on ${token.chain.id} are not implemented in this version of Talisman.`
)
if (tokenType === "substrate-equilibrium")
throw new Error(
`${token.symbol} transfers on ${token.chain.id} are not implemented in this version of Talisman.`
)

// force compilation error if any token types don't have a case
const exhaustiveCheck: never = tokenType
Expand Down
6 changes: 5 additions & 1 deletion apps/extension/src/ui/hooks/useChainsTokens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,14 @@ export const useChainsTokens = (chains: Chain[], evmNetworks?: EvmNetwork[]) =>
return chainUsesOrmlForNativeToken(nonEmptyBalances, chain.id, nativeToken)
}
if (tokenType === "evm-erc20") return true
if (tokenType === "substrate-assets") return true
if (tokenType === "substrate-tokens") return true
if (tokenType === "substrate-equilibrium") return true

// force compilation error if any token types don't have a case
const exhaustiveCheck: never = tokenType
throw new Error(`Unhandled token type ${exhaustiveCheck}`)
console.warn(`Unhandled token type ${exhaustiveCheck}`) // eslint-disable-line no-console
return false
})
.sort(
([aChainId], [bChainId]) =>
Expand Down
174 changes: 0 additions & 174 deletions packages/balances-acala-liquidcrowdloan/CHANGELOG.md

This file was deleted.

1 change: 0 additions & 1 deletion packages/balances-acala-liquidcrowdloan/README.md

This file was deleted.

1 change: 0 additions & 1 deletion packages/balances-acala-liquidcrowdloan/src/index.ts

This file was deleted.

Loading

0 comments on commit b083d95

Please sign in to comment.