diff --git a/packages/extension/package.json b/packages/extension/package.json index 38857ca7e..7dd3c94d4 100644 --- a/packages/extension/package.json +++ b/packages/extension/package.json @@ -1,6 +1,6 @@ { "name": "@enkryptcom/extension", - "version": "1.37.1", + "version": "1.38.0", "private": true, "scripts": { "zip": "cd dist; zip -r release.zip *;", diff --git a/packages/extension/src/providers/polkadot/libs/activity-handlers/providers/subscan/configs.ts b/packages/extension/src/providers/polkadot/libs/activity-handlers/providers/subscan/configs.ts index ed5e9d330..b027ca268 100644 --- a/packages/extension/src/providers/polkadot/libs/activity-handlers/providers/subscan/configs.ts +++ b/packages/extension/src/providers/polkadot/libs/activity-handlers/providers/subscan/configs.ts @@ -14,6 +14,8 @@ const NetworkEndpoints = { [NetworkNames.Quartz]: "https://quartz.api.subscan.io/", [NetworkNames.Unique]: "https://unique.api.subscan.io/", [NetworkNames.Vara]: "https://vara.api.subscan.io/", + [NetworkNames.AssetHubDOT]: "https://assethub-polkadot.api.subscan.io/", + [NetworkNames.AssetHubKSM]: "https://assethub-kusama.api.subscan.io/", }; export { NetworkEndpoints }; diff --git a/packages/extension/src/providers/polkadot/networks/astar/libs/assetinfo.ts b/packages/extension/src/providers/polkadot/libs/asset-handler.ts similarity index 81% rename from packages/extension/src/providers/polkadot/networks/astar/libs/assetinfo.ts rename to packages/extension/src/providers/polkadot/libs/asset-handler.ts index 73edbcbe9..6d6fe6959 100644 --- a/packages/extension/src/providers/polkadot/networks/astar/libs/assetinfo.ts +++ b/packages/extension/src/providers/polkadot/libs/asset-handler.ts @@ -4,7 +4,7 @@ import { SubstrateNetwork } from "@/providers/polkadot/types/substrate-network"; import { hexToString } from "@polkadot/util"; import { toBN } from "web3-utils"; -import { AstarToken, AstarTokenOptions } from "../types/astar-token"; +import { AssetToken, AssetTokenOptions } from "./asset-token"; type AssetMetadata = { name: `0x${string}`; @@ -30,25 +30,19 @@ export default async ( const assetMetadatas = metadata.map(([key, value]) => { const assetKey = (key.toHuman() as string[])[0].replaceAll(",", ""); const assetMetadata = value.toJSON() as AssetMetadata; - const info = { key: assetKey, name: hexToString(assetMetadata.name), symbol: hexToString(assetMetadata.symbol), decimals: assetMetadata.decimals, }; - return info; }); - const queries = assetMetadatas.map((metadata) => metadata.key); - const assetInfos = await apiPromise.query.assets.asset.multi(queries); - const tokenOptions = assetInfos .map((info, index) => { const infoHuman = info.toHuman() as AssetInfo; - if (infoHuman) { const metadata = assetMetadatas[index]; return { @@ -61,7 +55,7 @@ export default async ( }) .filter((asset) => asset !== null) .map((asset) => { - const tokenOptions: AstarTokenOptions = { + const tokenOptions: AssetTokenOptions = { name: asset!.name, symbol: asset!.symbol, decimals: asset!.decimals, @@ -69,50 +63,45 @@ export default async ( id: asset!.key, existentialDeposit: toBN(asset!.minBalance), }; - return tokenOptions; }) .map((tokenOption) => { if (knownTokens) { const knownToken = knownTokens.find( - (knownToken) => - knownToken.name === tokenOption.name && - knownToken.symbol === tokenOption.symbol + (knownToken) => knownToken.id === tokenOption.id ); - if (knownToken) { tokenOption.coingeckoID = knownToken.coingeckoID; tokenOption.icon = knownToken.icon; } } - return tokenOption; }); - if (address) { const queries = tokenOptions.map((options) => { return [options.id, address]; }); - const balances = await apiPromise.query.assets.account.multi(queries); - balances.forEach((balanceInfo, index) => { - const data = balanceInfo.toJSON(); - + const data: { + balance: string; + status?: string; + } = balanceInfo.toJSON() as any; if (data) { - tokenOptions[index].balance = (data as any).balance.toString(); + tokenOptions[index].balance = data.balance.toString(); + if (data.status && data.status.toString() === "Frozen") { + tokenOptions[index].name = `${tokenOptions[index].name} (Frozen)`; + } } }); } - const nativeAsset = new SubstrateNativeToken({ name: network.currencyNameLong, - symbol: network.name, + symbol: network.currencyName, decimals: network.decimals, existentialDeposit: network.existentialDeposit, icon: network.icon, coingeckoID: network.coingeckoID, }); - - return [nativeAsset, ...tokenOptions.map((o) => new AstarToken(o))]; + return [nativeAsset, ...tokenOptions.map((o) => new AssetToken(o))]; }; diff --git a/packages/extension/src/providers/polkadot/networks/astar/types/astar-token.ts b/packages/extension/src/providers/polkadot/libs/asset-token.ts similarity index 77% rename from packages/extension/src/providers/polkadot/networks/astar/types/astar-token.ts rename to packages/extension/src/providers/polkadot/libs/asset-token.ts index d25dbc28f..0a4eff287 100644 --- a/packages/extension/src/providers/polkadot/networks/astar/types/astar-token.ts +++ b/packages/extension/src/providers/polkadot/libs/asset-token.ts @@ -4,13 +4,13 @@ import { ApiPromise } from "@polkadot/api"; import { SubmittableExtrinsic } from "@polkadot/api/types"; import { ISubmittableResult } from "@polkadot/types/types"; -export interface AstarTokenOptions extends BaseTokenOptions { +export interface AssetTokenOptions extends BaseTokenOptions { id: string; } -export class AstarToken extends SubstrateToken { +export class AssetToken extends SubstrateToken { private id: string; - constructor(options: AstarTokenOptions) { + constructor(options: AssetTokenOptions) { super(options); this.id = options.id; } @@ -26,7 +26,6 @@ export class AstarToken extends SubstrateToken { this.balance = balance; return balance; } - return "0"; }); } @@ -35,9 +34,10 @@ export class AstarToken extends SubstrateToken { api: ApiPromise, to: string, amount: string, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - _options?: SendOptions | undefined + options?: SendOptions | undefined ): Promise> { + if (options && options.type === "all") + return api.tx.assets.transfer(this.id, { id: to }, amount); return api.tx.assets.transferKeepAlive(this.id, { id: to }, amount); } } diff --git a/packages/extension/src/providers/polkadot/networks/assethub/assethub-dot.ts b/packages/extension/src/providers/polkadot/networks/assethub/assethub-dot.ts new file mode 100644 index 000000000..226b45faa --- /dev/null +++ b/packages/extension/src/providers/polkadot/networks/assethub/assethub-dot.ts @@ -0,0 +1,37 @@ +import { NetworkNames } from "@enkryptcom/types"; +import { toBN } from "web3-utils"; +import { + SubstrateNetwork, + SubstrateNetworkOptions, +} from "@/providers/polkadot/types/substrate-network"; +import { subscanActivity } from "@/providers/polkadot/libs/activity-handlers"; +import wrapActivityHandler from "@/libs/activity-state/wrap-activity-handler"; +import assetHandler from "@/providers/polkadot/libs/asset-handler"; +import assets from "./assets-dot"; +import { toBase } from "@enkryptcom/utils"; + +const assetHubOptions: SubstrateNetworkOptions = { + name: NetworkNames.AssetHubDOT, + name_long: "Asset Hub | Polkadot", + homePage: "https://polkadot.network", + blockExplorerTX: "https://assethub-polkadot.subscan.io/extrinsic/[[txHash]]", + blockExplorerAddr: "https://assethub-polkadot.subscan.io/account/[[address]]", + isTestNetwork: false, + currencyName: "DOT", + currencyNameLong: "Polkadot", + icon: require("../icons/assethub.png"), + decimals: 10, + prefix: 0, + node: "wss://statemint-rpc.dwellir.com/", + coingeckoID: "polkadot", + genesisHash: + "0x68d56f15f85d3136970ec16946040bc1752654e906147f7e43e9d539d7c3de2f", + activityHandler: wrapActivityHandler(subscanActivity), + existentialDeposit: toBN(toBase("0.01", 10)), + assetHandler, + knownTokens: assets, +}; + +const assetHub = new SubstrateNetwork(assetHubOptions); + +export default assetHub; diff --git a/packages/extension/src/providers/polkadot/networks/assethub/assethub-ksm.ts b/packages/extension/src/providers/polkadot/networks/assethub/assethub-ksm.ts new file mode 100644 index 000000000..ebc3ec06e --- /dev/null +++ b/packages/extension/src/providers/polkadot/networks/assethub/assethub-ksm.ts @@ -0,0 +1,37 @@ +import { NetworkNames } from "@enkryptcom/types"; +import { toBN } from "web3-utils"; +import { + SubstrateNetwork, + SubstrateNetworkOptions, +} from "@/providers/polkadot/types/substrate-network"; +import { subscanActivity } from "@/providers/polkadot/libs/activity-handlers"; +import wrapActivityHandler from "@/libs/activity-state/wrap-activity-handler"; +import assetHandler from "@/providers/polkadot/libs/asset-handler"; +import assets from "./assets-ksm"; +import { toBase } from "@enkryptcom/utils"; + +const assetHubOptions: SubstrateNetworkOptions = { + name: NetworkNames.AssetHubKSM, + name_long: "Asset Hub | Kusama", + homePage: "https://kusama.network/", + blockExplorerTX: "https://assethub-kusama.subscan.io/extrinsic/[[txHash]]", + blockExplorerAddr: "https://assethub-kusama.subscan.io/account/[[address]]", + isTestNetwork: false, + currencyName: "KSM", + currencyNameLong: "Kusama", + icon: require("../icons/assethub.png"), + decimals: 12, + prefix: 2, + node: "wss://kusama-asset-hub-rpc.polkadot.io/", + coingeckoID: "kusama", + genesisHash: + "0x48239ef607d7928874027a43a67689209727dfb3d3dc5e5b03a39bdc2eda771a", + activityHandler: wrapActivityHandler(subscanActivity), + existentialDeposit: toBN(toBase("0.000003333333", 12)), + assetHandler, + knownTokens: assets, +}; + +const assetHub = new SubstrateNetwork(assetHubOptions); + +export default assetHub; diff --git a/packages/extension/src/providers/polkadot/networks/assethub/assets-dot.ts b/packages/extension/src/providers/polkadot/networks/assethub/assets-dot.ts new file mode 100644 index 000000000..02fab2e4a --- /dev/null +++ b/packages/extension/src/providers/polkadot/networks/assethub/assets-dot.ts @@ -0,0 +1,26 @@ +import { KnownTokenDisplay } from "@/providers/polkadot/types"; + +const assets: KnownTokenDisplay[] = [ + { + name: "USD Coin", + symbol: "USDC", + coingeckoID: "usd-coin", + icon: require("./icons/usdc.png"), + id: "1337", + }, + { + name: "Tether USD", + symbol: "USDt", + coingeckoID: "tether", + icon: require("./icons/usdt.png"), + id: "1984", + }, + { + name: "DOT is Dead", + symbol: "DED", + icon: require("./icons/ded.png"), + id: "30", + }, +]; + +export default assets; diff --git a/packages/extension/src/providers/polkadot/networks/assethub/assets-ksm.ts b/packages/extension/src/providers/polkadot/networks/assethub/assets-ksm.ts new file mode 100644 index 000000000..d2b439a21 --- /dev/null +++ b/packages/extension/src/providers/polkadot/networks/assethub/assets-ksm.ts @@ -0,0 +1,20 @@ +import { KnownTokenDisplay } from "@/providers/polkadot/types"; + +const assets: KnownTokenDisplay[] = [ + { + name: "RMRK.app", + symbol: "RMRK", + coingeckoID: "rmrk", + icon: require("./icons/rmrk.png"), + id: "8", + }, + { + name: "Tether USD", + symbol: "USDt", + coingeckoID: "tether", + icon: require("./icons/usdt.png"), + id: "1984", + }, +]; + +export default assets; diff --git a/packages/extension/src/providers/polkadot/networks/assethub/icons/ded.png b/packages/extension/src/providers/polkadot/networks/assethub/icons/ded.png new file mode 100644 index 000000000..c472933e9 Binary files /dev/null and b/packages/extension/src/providers/polkadot/networks/assethub/icons/ded.png differ diff --git a/packages/extension/src/providers/polkadot/networks/assethub/icons/rmrk.png b/packages/extension/src/providers/polkadot/networks/assethub/icons/rmrk.png new file mode 100644 index 000000000..f902d7f90 Binary files /dev/null and b/packages/extension/src/providers/polkadot/networks/assethub/icons/rmrk.png differ diff --git a/packages/extension/src/providers/polkadot/networks/assethub/icons/usdc.png b/packages/extension/src/providers/polkadot/networks/assethub/icons/usdc.png new file mode 100644 index 000000000..310abf6de Binary files /dev/null and b/packages/extension/src/providers/polkadot/networks/assethub/icons/usdc.png differ diff --git a/packages/extension/src/providers/polkadot/networks/assethub/icons/usdt.png b/packages/extension/src/providers/polkadot/networks/assethub/icons/usdt.png new file mode 100644 index 000000000..7f05d0092 Binary files /dev/null and b/packages/extension/src/providers/polkadot/networks/assethub/icons/usdt.png differ diff --git a/packages/extension/src/providers/polkadot/networks/assethub/index.ts b/packages/extension/src/providers/polkadot/networks/assethub/index.ts new file mode 100644 index 000000000..ff07c3041 --- /dev/null +++ b/packages/extension/src/providers/polkadot/networks/assethub/index.ts @@ -0,0 +1,4 @@ +import assethubDOT from "./assethub-dot"; +import assethubKSM from "./assethub-ksm"; + +export { assethubDOT, assethubKSM }; diff --git a/packages/extension/src/providers/polkadot/networks/astar/assets/astar-assets.ts b/packages/extension/src/providers/polkadot/networks/astar/assets/astar-assets.ts index d1b0a9914..040f67976 100644 --- a/packages/extension/src/providers/polkadot/networks/astar/assets/astar-assets.ts +++ b/packages/extension/src/providers/polkadot/networks/astar/assets/astar-assets.ts @@ -6,23 +6,20 @@ const assets: KnownTokenDisplay[] = [ symbol: "ACA", coingeckoID: "acala", icon: require("./icons/ACA.png"), + id: "18446744073709551616", }, { name: "Polkadot", symbol: "DOT", coingeckoID: "polkadot", icon: require("../../icons/polkadot.svg"), - }, - { - name: "Acala Dollar", - symbol: "aUSD", - icon: require("./icons/AUSD.png"), - coingeckoID: "acala-dollar", + id: "340282366920938463463374607431768211455", }, { name: "Liquid DOT", symbol: "LDOT", icon: require("./icons/LDOT.png"), + id: "18446744073709551618", }, ]; diff --git a/packages/extension/src/providers/polkadot/networks/astar/assets/shiden-assets.ts b/packages/extension/src/providers/polkadot/networks/astar/assets/shiden-assets.ts index 5b5d0948f..ca3e92ddc 100644 --- a/packages/extension/src/providers/polkadot/networks/astar/assets/shiden-assets.ts +++ b/packages/extension/src/providers/polkadot/networks/astar/assets/shiden-assets.ts @@ -6,27 +6,19 @@ const assets: KnownTokenDisplay[] = [ symbol: "MOVR", coingeckoID: "moonriver", icon: require("./icons/MOVR.png"), + id: "18446744073709551620", }, { name: "Kusama", symbol: "KSM", icon: require("./icons/KSM.png"), - }, - { - name: "Liquid Kusama", - symbol: "LKSM", - icon: require("./icons/LKSM.png"), - }, - { - name: "Acala Dollar", - symbol: "aUSD", - icon: require("./icons/AUSD.png"), - coingeckoID: "acala-dollar", + id: "340282366920938463463374607431768211455", }, { name: "Karura", symbol: "KAR", icon: require("./icons/KAR.svg"), + id: "18446744073709551618", }, ]; diff --git a/packages/extension/src/providers/polkadot/networks/astar/astar.ts b/packages/extension/src/providers/polkadot/networks/astar/astar.ts index 33a458edd..ddee644f8 100644 --- a/packages/extension/src/providers/polkadot/networks/astar/astar.ts +++ b/packages/extension/src/providers/polkadot/networks/astar/astar.ts @@ -6,7 +6,7 @@ import { SubstrateNetwork, SubstrateNetworkOptions, } from "../../types/substrate-network"; -import assetHandler from "./libs//assetinfo"; +import assetHandler from "@/providers/polkadot/libs/asset-handler"; import { toBN } from "web3-utils"; const astarOptions: SubstrateNetworkOptions = { diff --git a/packages/extension/src/providers/polkadot/networks/astar/shiden.ts b/packages/extension/src/providers/polkadot/networks/astar/shiden.ts index 576372f62..f5910ce05 100644 --- a/packages/extension/src/providers/polkadot/networks/astar/shiden.ts +++ b/packages/extension/src/providers/polkadot/networks/astar/shiden.ts @@ -6,7 +6,7 @@ import { SubstrateNetwork, SubstrateNetworkOptions, } from "../../types/substrate-network"; -import assetHandler from "./libs//assetinfo"; +import assetHandler from "@/providers/polkadot/libs/asset-handler"; import { toBN } from "web3-utils"; const shidenOptions: SubstrateNetworkOptions = { diff --git a/packages/extension/src/providers/polkadot/networks/icons/assethub.png b/packages/extension/src/providers/polkadot/networks/icons/assethub.png new file mode 100644 index 000000000..4d65a43b0 Binary files /dev/null and b/packages/extension/src/providers/polkadot/networks/icons/assethub.png differ diff --git a/packages/extension/src/providers/polkadot/networks/index.ts b/packages/extension/src/providers/polkadot/networks/index.ts index 51c4c8d97..cdc6589d4 100644 --- a/packages/extension/src/providers/polkadot/networks/index.ts +++ b/packages/extension/src/providers/polkadot/networks/index.ts @@ -14,6 +14,10 @@ import uniqueNode from "./unique/unique"; import penNode from "./pendulum/pendulum"; import ampeNode from "./pendulum/amplitude"; import varaNode from "./vara"; +import { + assethubDOT as assetHubDotNode, + assethubKSM as assetHubKsmNode, +} from "./assethub"; export default { acala: acaNode, @@ -32,4 +36,6 @@ export default { pendulum: penNode, amplitude: ampeNode, vara: varaNode, + assetHubDOT: assetHubDotNode, + assetHubKSM: assetHubKsmNode, }; diff --git a/packages/extension/src/providers/polkadot/types/index.ts b/packages/extension/src/providers/polkadot/types/index.ts index ca202416b..e165793cb 100644 --- a/packages/extension/src/providers/polkadot/types/index.ts +++ b/packages/extension/src/providers/polkadot/types/index.ts @@ -64,6 +64,7 @@ export interface KnownTokenDisplay { symbol: string; coingeckoID?: string; icon: string; + id?: string; } export { InjectedProvider }; diff --git a/packages/extension/src/providers/polkadot/types/substrate-network.ts b/packages/extension/src/providers/polkadot/types/substrate-network.ts index f728f9252..4c48a4ec6 100644 --- a/packages/extension/src/providers/polkadot/types/substrate-network.ts +++ b/packages/extension/src/providers/polkadot/types/substrate-network.ts @@ -105,7 +105,7 @@ export class SubstrateNetwork extends BaseNetwork { } else { const nativeToken = new SubstrateNativeToken({ name: this.currencyNameLong, - symbol: this.name, + symbol: this.currencyName, coingeckoID: this.coingeckoID, decimals: this.decimals, icon: this.icon, @@ -124,7 +124,7 @@ export class SubstrateNetwork extends BaseNetwork { if (supported.length === 0) { const nativeToken = new SubstrateNativeToken({ name: this.currencyNameLong, - symbol: this.name, + symbol: this.currencyName, coingeckoID: this.coingeckoID, decimals: this.decimals, icon: this.icon, diff --git a/packages/extension/src/providers/polkadot/ui/send-transaction/components/send-alert.vue b/packages/extension/src/providers/polkadot/ui/send-transaction/components/send-alert.vue index 8a6b48c29..425dfa8aa 100644 --- a/packages/extension/src/providers/polkadot/ui/send-transaction/components/send-alert.vue +++ b/packages/extension/src/providers/polkadot/ui/send-transaction/components/send-alert.vue @@ -1,7 +1,7 @@