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

Support Rune and BRC-20 #82

Merged
merged 37 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6297dda
[Issue-70] feature: manage runes by chainlist
bluezdot May 9, 2024
c56d599
[Issue-70] fix: update spacer for rune name
bluezdot May 9, 2024
0c4438b
[Issue-70] add util function to handle rune spacer & get all collecti…
bluezdot May 10, 2024
1ca9171
[Issue-70] refactor: update interface and function get rune collections
bluezdot May 10, 2024
bd5c9a6
[Issue-70] fix: update assetType for RUNE: LOCAL -> RUNE
bluezdot May 10, 2024
d33b267
[Issue-70] feature: handle validate custom rune data
bluezdot May 10, 2024
8b48232
[Issue-70] feature: handle submit custom rune data
bluezdot May 10, 2024
b2fac40
[Issue-70] feature: handle delete custom data
bluezdot May 10, 2024
0ae939e
[Issue-70] build: update chainlist
bluezdot May 11, 2024
ec06c14
[Issue-70] test: setup for test
bluezdot May 11, 2024
7638f4a
[Issue-72] build: update chainlist brc20 token
bluezdot May 11, 2024
58f9389
[Issue-72] refactor: refactor code
bluezdot May 11, 2024
347677f
[Issue-72] feature: subscribe brc20 balance
bluezdot May 11, 2024
aa483a6
[Issue-73] feature: add function query brc20 metadata
bluezdot May 13, 2024
45a466d
[Issue-73] feature: handle validate custom brc-20 metdata
bluezdot May 13, 2024
7b5cce2
[Issue-73] feature: handle submit & delete custom brc-20
bluezdot May 13, 2024
c397872
[Issue-73] test: setup for test
bluezdot May 13, 2024
03a54c9
Revert "[Issue-70] test: setup for test"
bluezdot May 20, 2024
f585c79
Merge branch 'koni/dev/issue-70' into koni/dev/issue-81
bluezdot May 20, 2024
e55c0d3
Revert "[Issue-73] test: setup for test"
bluezdot May 20, 2024
1c24a72
Merge branch 'koni/dev/issue-73' into koni/dev/issue-81
bluezdot May 20, 2024
6627bf4
[Issue-81] fix: fix function select chain for import FT and NFT
bluezdot May 20, 2024
4a167d7
[Issue-81] feat: Handle UI for import Rune and BRC-20 token
bluezdot May 20, 2024
f506fbe
[Issue-81] fix: Update API get BRC-20 Metadata
bluezdot May 20, 2024
5d83398
[Issue-81] fix: Handle error empty data returned
bluezdot May 20, 2024
cddd073
[Issue-81] feat: disable bitcoin testnet
bluezdot May 20, 2024
582b355
[Issue-81] fix: fix eslint
bluezdot May 21, 2024
cc9525e
Merge branch 'openbit-dev' into koni/dev/issue-81
bluezdot May 21, 2024
5e5caa5
Merge branch 'openbit-dev' into koni/dev/issue-81
bluezdot May 21, 2024
74218ee
Merge branch 'koni/dev/issue-81' of https://github.com/openbitdev/Ope…
bluezdot May 21, 2024
10f3bf1
[Issue-81] Update endpoint ordhook openbit
bluezdot May 21, 2024
daf632d
[Issue-81] Update endpoint ordhook openbit
bluezdot May 21, 2024
6cce93f
[Issue-81] Update endpoint ordhook openbit for inscription
bluezdot May 21, 2024
76993e3
Merge branch 'koni/dev/issue-81' of https://github.com/openbitdev/Ope…
bluezdot May 21, 2024
2f52d57
Merge branch 'openbit-dev' into koni/dev/issue-81
bluezdot May 21, 2024
00d51ef
Merge openbit-dev
bluezdot May 21, 2024
5a62bd5
[Issue-81] fix: fix token disable after reload extension
bluezdot May 22, 2024
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
21,323 changes: 21,323 additions & 0 deletions local-libs/chain-list/bundle-subwallet-chain-list.js

Large diffs are not rendered by default.

626 changes: 626 additions & 0 deletions local-libs/chain-list/cjs/data/AssetLogoMap.json

Large diffs are not rendered by default.

1,544 changes: 1,544 additions & 0 deletions local-libs/chain-list/cjs/data/AssetRef.json

Large diffs are not rendered by default.

9,329 changes: 9,329 additions & 0 deletions local-libs/chain-list/cjs/data/ChainAsset.json

Large diffs are not rendered by default.

8,345 changes: 8,345 additions & 0 deletions local-libs/chain-list/cjs/data/ChainInfo.json

Large diffs are not rendered by default.

249 changes: 249 additions & 0 deletions local-libs/chain-list/cjs/data/ChainLogoMap.json

Large diffs are not rendered by default.

506 changes: 506 additions & 0 deletions local-libs/chain-list/cjs/data/MultiChainAsset.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion local-libs/chain-list/cjs/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ exports._AssetType = _AssetType;
_AssetType["PSP22"] = "PSP22";
_AssetType["PSP34"] = "PSP34";
_AssetType["UNKNOWN"] = "UNKNOWN";
_AssetType["RUNE"] = "RUNE";
_AssetType["BRC20"] = "BRC20";
})(_AssetType || (exports._AssetType = _AssetType = {}));
let _SubstrateChainType;
exports._SubstrateChainType = _SubstrateChainType;
Expand All @@ -51,4 +53,4 @@ exports._AssetRefPath = _AssetRefPath;
_AssetRefPath["XCM"] = "XCM";
_AssetRefPath["MANTA_ZK"] = "MANTA_ZK";
_AssetRefPath["SWAP"] = "SWAP";
})(_AssetRefPath || (exports._AssetRefPath = _AssetRefPath = {}));
})(_AssetRefPath || (exports._AssetRefPath = _AssetRefPath = {}));
90 changes: 90 additions & 0 deletions local-libs/chain-list/data/ChainAsset.json
Original file line number Diff line number Diff line change
Expand Up @@ -9235,5 +9235,95 @@
"multiChainAsset": null,
"hasValue": false,
"icon": "https://dev.sw-chain-list-assets.pages.dev/assets/chain-assets/botanixevmtest-native-btc.png"
},
"bitcoin-RUNE-RUNING*BITCOIN-841052:1863": {
"originChain": "bitcoin",
"slug": "bitcoin-RUNE-RUNING*BITCOIN-841052:1863",
"name": "RUNING BITCOIN",
"symbol": "RUNING*BITCOIN",
"decimals": 8,
"priceId": null,
"minAmount": "0",
"assetType": "RUNE",
"metadata": {
"runeId": "841052:1863"
},
"multiChainAsset": null,
"hasValue": true,
"icon": "https://dev.sw-chain-list-assets.pages.dev/assets/chain-assets/botanixevmtest-native-btc.png"
},
"bitcoin-RUNE-RUNES*X*BITCOIN-840000:142": {
"originChain": "bitcoin",
"slug": "bitcoin-RUNE-RUNES*X*BITCOIN-840000:142",
"name": "RUNES X BITCOIN",
"symbol": "RUNES*X*BITCOIN",
"decimals": 0,
"priceId": null,
"minAmount": "0",
"assetType": "RUNE",
"metadata": {
"runeId": "840000:142"
},
"multiChainAsset": null,
"hasValue": true,
"icon": "https://dev.sw-chain-list-assets.pages.dev/assets/chain-assets/botanixevmtest-native-btc.png"
},
"bitcoin-RUNE-KERNEL*BITCORN-840015:9": {
"originChain": "bitcoin",
"slug": "bitcoin-RUNE-KERNEL*BITCORN-840015:9",
"name": "KERNEL BITCORN",
"symbol": "KERNEL*BITCORN",
"decimals": 0,
"priceId": null,
"minAmount": "0",
"assetType": "RUNE",
"metadata": {
"runeId": "840015:9"
},
"multiChainAsset": null,
"hasValue": true,
"icon": "https://dev.sw-chain-list-assets.pages.dev/assets/chain-assets/kernal_bitcorn.png"
},
"bitcoin-BRC20-cPen": {
"originChain": "bitcoin",
"slug": "bitcoin-BRC20-cPen",
"name": "cPen",
"symbol": "cPen",
"decimals": 18,
"priceId": null,
"minAmount": "0",
"assetType": "BRC20",
"metadata": null,
"multiChainAsset": null,
"hasValue": true,
"icon": "https://dev.sw-chain-list-assets.pages.dev/assets/chain-assets/kernal_bitcorn.png"
},
"bitcoin-BRC20-PGCH": {
"originChain": "bitcoin",
"slug": "bitcoin-BRC20-PGCH",
"name": "PGCH",
"symbol": "PGCH",
"decimals": 18,
"priceId": null,
"minAmount": "0",
"assetType": "BRC20",
"metadata": null,
"multiChainAsset": null,
"hasValue": true,
"icon": "https://dev.sw-chain-list-assets.pages.dev/assets/chain-assets/kernal_bitcorn.png"
},
"bitcoin-BRC20-\uD83D\uDF0A": {
"originChain": "bitcoin",
"slug": "bitcoin-BRC20-\uD83D\uDF0A",
"name": "\uD83D\uDF0A",
"symbol": "\uD83D\uDF0A",
"decimals": 18,
"priceId": null,
"minAmount": "0",
"assetType": "BRC20",
"metadata": null,
"multiChainAsset": null,
"hasValue": true,
"icon": "https://dev.sw-chain-list-assets.pages.dev/assets/chain-assets/kernal_bitcorn.png"
}
}
4 changes: 3 additions & 1 deletion local-libs/chain-list/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export declare enum _AssetType {
ERC721 = "ERC721",
PSP22 = "PSP22",
PSP34 = "PSP34",
UNKNOWN = "UNKNOWN"
UNKNOWN = "UNKNOWN",
RUNE = "RUNE",
BRC20 = "BRC20"
}
export declare enum _SubstrateChainType {
RELAYCHAIN = "RELAYCHAIN",
Expand Down
4 changes: 3 additions & 1 deletion local-libs/chain-list/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export let _AssetType;
_AssetType["PSP22"] = "PSP22";
_AssetType["PSP34"] = "PSP34";
_AssetType["UNKNOWN"] = "UNKNOWN";
_AssetType["RUNE"] = "RUNE";
_AssetType["BRC20"] = "BRC20";
})(_AssetType || (_AssetType = {}));
export let _SubstrateChainType;
(function (_SubstrateChainType) {
Expand All @@ -40,4 +42,4 @@ export let _AssetRefPath;
_AssetRefPath["XCM"] = "XCM";
_AssetRefPath["MANTA_ZK"] = "MANTA_ZK";
_AssetRefPath["SWAP"] = "SWAP";
})(_AssetRefPath || (_AssetRefPath = {}));
})(_AssetRefPath || (_AssetRefPath = {}));
4 changes: 3 additions & 1 deletion packages/extension-base/src/background/KoniTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { AuthUrls, Resolver } from '@subwallet/extension-base/background/handlers/State';
import { AccountAuthType, AccountJson, AccountProxy, AddressJson, AuthorizeRequest, ConfirmationRequestBase, RequestAccountList, RequestAccountProxy, RequestAccountSubscribe, RequestAccountUnsubscribe, RequestAuthorizeCancel, RequestAuthorizeReject, RequestAuthorizeSubscribe, RequestAuthorizeTab, RequestCurrentAccountAddress, ResponseAuthorizeList, ResponseJsonGetAccountInfo, SeedLengths } from '@subwallet/extension-base/background/types';
import { _CHAIN_VALIDATION_ERROR } from '@subwallet/extension-base/services/chain-service/handler/types';
import { _BitcoinApi, _ChainState, _EvmApi, _NetworkUpsertParams, _SubstrateApi, _ValidateCustomAssetRequest, _ValidateCustomAssetResponse, EnableChainParams, EnableMultiChainParams } from '@subwallet/extension-base/services/chain-service/types';
import { _BitcoinApi, _ChainState, _EvmApi, _NetworkUpsertParams, _SubstrateApi, _ValidateCustomAssetRequest, _ValidateCustomAssetResponse, _ValidateCustomBrc20Request, _ValidateCustomBrc20Response, _ValidateCustomRuneRequest, _ValidateCustomRuneResponse, EnableChainParams, EnableMultiChainParams } from '@subwallet/extension-base/services/chain-service/types';
import { CrowdloanContributionsResponse } from '@subwallet/extension-base/services/subscan-service/types';
import { SWTransactionResponse, SWTransactionResult } from '@subwallet/extension-base/services/transaction-service/types';
import { WalletConnectNotSupportRequest, WalletConnectSessionRequest } from '@subwallet/extension-base/services/wallet-connect-service/types';
Expand Down Expand Up @@ -228,10 +228,10 @@
externalUrl?: string;
rarity?: string;
description?: string;
properties?: Record<any, any> | null;

Check warning on line 231 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unexpected any. Specify a different type

Check warning on line 231 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unexpected any. Specify a different type
type?: _AssetType.ERC721 | _AssetType.PSP34 | RMRK_VER; // for sending
rmrk_ver?: RMRK_VER;
onChainOption?: any; // for sending PSP-34 tokens, should be done better

Check warning on line 234 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unexpected any. Specify a different type
}

export interface NftCollection {
Expand Down Expand Up @@ -537,7 +537,7 @@
[ExtrinsicType.STAKING_COMPOUNDING]: RequestTuringStakeCompound,
[ExtrinsicType.STAKING_CANCEL_COMPOUNDING]: RequestTuringCancelStakeCompound,
[ExtrinsicType.STAKING_CANCEL_UNSTAKE]: RequestStakeCancelWithdrawal,
[ExtrinsicType.STAKING_POOL_WITHDRAW]: any,

Check warning on line 540 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unexpected any. Specify a different type

// Yield
[ExtrinsicType.JOIN_YIELD_POOL]: RequestYieldStepSubmit,
Expand Down Expand Up @@ -566,8 +566,8 @@
[ExtrinsicType.TOKEN_APPROVE]: TokenApproveData,

[ExtrinsicType.EVM_EXECUTE]: TransactionConfig,
[ExtrinsicType.CROWDLOAN]: any,

Check warning on line 569 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unexpected any. Specify a different type
[ExtrinsicType.UNKNOWN]: any

Check warning on line 570 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unexpected any. Specify a different type
}

export enum ExtrinsicStatus {
Expand Down Expand Up @@ -662,7 +662,7 @@
// : T extends ExtrinsicType.MINT_VDOT
// ? Pick<SubmitBifrostLiquidStaking, 'rewardTokenSlug' | 'estimatedAmountReceived'>
// : undefined;
export interface TransactionHistoryItem<ET extends ExtrinsicType = ExtrinsicType.TRANSFER_BALANCE> {

Check warning on line 665 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

'ET' is defined but never used
origin?: 'app' | 'migration' | 'subsquid' | 'subscan' | 'blockstream', // 'app' or history source
callhash?: string,
signature?: string,
Expand Down Expand Up @@ -690,7 +690,7 @@
tip?: AmountData,
fee?: AmountData,
explorerUrl?: string,
additionalInfo?: any,

Check warning on line 693 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unexpected any. Specify a different type
startBlock?: number,
nonce?: number,
}
Expand Down Expand Up @@ -1135,12 +1135,12 @@
recipientAddress: string,

nftItemName?: string, // Use for confirmation view only
params: Record<string, any>,

Check warning on line 1138 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unexpected any. Specify a different type
nftItem: NftItem
}

export interface EvmNftTransaction extends ValidateTransactionResponse {
tx: Record<string, any> | null;

Check warning on line 1143 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unexpected any. Specify a different type
}

export interface EvmNftSubmitTransaction extends BaseRequestSign {
Expand Down Expand Up @@ -2266,7 +2266,9 @@
'pri(chainService.removeChain)': [string, boolean];
'pri(chainService.deleteCustomAsset)': [string, boolean];
'pri(chainService.upsertCustomAsset)': [Record<string, any>, boolean];
'pri(chainService.validateCustomBrc20)': [_ValidateCustomBrc20Request, _ValidateCustomBrc20Response]
'pri(chainService.validateCustomAsset)': [_ValidateCustomAssetRequest, _ValidateCustomAssetResponse];
'pri(chainService.validateCustomRune)': [_ValidateCustomRuneRequest, _ValidateCustomRuneResponse];
'pri(chainService.resetDefaultChains)': [null, boolean];
'pri(chainService.getSupportedContractTypes)': [null, string[]];
'pri(chainService.validateCustomChain)': [ValidateNetworkRequest, ValidateNetworkResponse];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
// SPDX-License-Identifier: Apache-2.0

export const HIRO_API = {
api_status: 'https://api.hiro.so/ordinals/v1/',
api_status: 'https://ordinals-api.openbit.app/ordinals/v1/',

list_of_incriptions: 'https://api.hiro.so/ordinals/v1/inscriptions',
transfers_per_block: 'https://api.hiro.so/ordinals/v1/inscriptions/transfers',
specific_inscription: 'https://api.hiro.so/ordinals/v1/inscriptions/:id',
inscription_content: 'https://api.hiro.so/ordinals/v1/inscriptions/:id/content',
inscription_transfers: 'https://api.hiro.so/ordinals/v1/inscriptions/:id/transfers',
list_of_incriptions: 'https://ordinals-api.openbit.app/ordinals/v1/inscriptions',
transfers_per_block: 'https://ordinals-api.openbit.app/ordinals/v1/inscriptions/transfers',
specific_inscription: 'https://ordinals-api.openbit.app/ordinals/v1/inscriptions/:id',
inscription_content: 'https://ordinals-api.openbit.app/ordinals/v1/inscriptions/:id/content',
inscription_transfers: 'https://ordinals-api.openbit.app/ordinals/v1/inscriptions/:id/transfers',

satoshi_ordinal: 'https://api.hiro.so/ordinals/v1/sats/:ordinal',
satoshi_inscriptions: 'https://api.hiro.so/ordinals/v1/sats/:ordinal/inscriptions',
satoshi_ordinal: 'https://ordinals-api.openbit.app/ordinals/v1/sats/:ordinal',
satoshi_inscriptions: 'https://ordinals-api.openbit.app/ordinals/v1/sats/:ordinal/inscriptions',

inscription_count_per_block: 'https://api.hiro.so/ordinals/v1/stats/inscriptions',
inscription_count_per_block: 'https://ordinals-api.openbit.app/ordinals/v1/stats/inscriptions',

brc20_tokens: 'https://api.hiro.so/ordinals/v1/brc-20/tokens',
brc20_token_details: 'https://api.hiro.so/ordinals/v1/brc-20/tokens/:ticker',
brc20_token_holders: 'https://api.hiro.so/ordinals/v1/brc-20/tokens/:ticker/holders',
brc20_balances: 'https://api.hiro.so/ordinals/v1/brc-20/balances/:address',
brc20_activity: 'https://api.hiro.so/ordinals/v1/brc-20/activity'
brc20_tokens: 'https://ordinals-api.openbit.app/ordinals/v1/brc-20/tokens',
brc20_token_details: 'https://ordinals-api.openbit.app/ordinals/v1/brc-20/tokens/:ticker',
brc20_token_holders: 'https://ordinals-api.openbit.app/ordinals/v1/brc-20/tokens/:ticker/holders',
brc20_balances: 'https://ordinals-api.openbit.app/ordinals/v1/brc-20/balances/:address',
brc20_activity: 'https://ordinals-api.openbit.app/ordinals/v1/brc-20/activity'
};

export const ORD_IO_URL = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { YIELD_EXTRINSIC_TYPES } from '@subwallet/extension-base/koni/api/yield/
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
import { getBitcoinTransactionObject } from '@subwallet/extension-base/services/balance-service/helpers/transfer/bitcoin';
import { _API_OPTIONS_CHAIN_GROUP, _DEFAULT_MANTA_ZK_CHAIN, _MANTA_ZK_CHAIN_GROUP, _ZK_ASSET_PREFIX } from '@subwallet/extension-base/services/chain-service/constants';
import { _ChainApiStatus, _ChainConnectionStatus, _ChainState, _NetworkUpsertParams, _ValidateCustomAssetRequest, _ValidateCustomAssetResponse, EnableChainParams, EnableMultiChainParams } from '@subwallet/extension-base/services/chain-service/types';
import { _ChainApiStatus, _ChainConnectionStatus, _ChainState, _NetworkUpsertParams, _ValidateCustomAssetRequest, _ValidateCustomAssetResponse, _ValidateCustomBrc20Request, _ValidateCustomBrc20Response, _ValidateCustomRuneRequest, _ValidateCustomRuneResponse, EnableChainParams, EnableMultiChainParams } from '@subwallet/extension-base/services/chain-service/types';
import { _getChainNativeTokenBasicInfo, _getContractAddressOfToken, _getEvmChainId, _getSubstrateGenesisHash, _getTokenMinAmount, _isAssetSmartContractNft, _isChainBitcoinCompatible, _isChainEvmCompatible, _isCustomAsset, _isLocalToken, _isMantaZkAsset, _isNativeToken, _isTokenEvmSmartContract, _isTokenTransferredByEvm } from '@subwallet/extension-base/services/chain-service/utils';
import { calculateGasFeeParams } from '@subwallet/extension-base/services/fee-service/utils';
import { EXTENSION_REQUEST_URL } from '@subwallet/extension-base/services/request-service/constants';
Expand Down Expand Up @@ -2219,10 +2219,18 @@ export default class KoniExtension {
return false;
}

private async validateCustomBrc20 (data: _ValidateCustomBrc20Request): Promise<_ValidateCustomBrc20Response> {
return await this.#koniState.validateCustomBrc20(data);
}

private async validateCustomAsset (data: _ValidateCustomAssetRequest): Promise<_ValidateCustomAssetResponse> {
return await this.#koniState.validateCustomAsset(data);
}

private async validateCustomRune (data: _ValidateCustomRuneRequest): Promise<_ValidateCustomRuneResponse> {
return await this.#koniState.validateCustomRune(data);
}

private async getAddressFreeBalance ({ address, networkKey, token }: RequestFreeBalance): Promise<AmountData> {
if (token && _MANTA_ZK_CHAIN_GROUP.includes(networkKey)) {
const tokenInfo = this.#koniState.chainService.getAssetBySlug(token);
Expand Down Expand Up @@ -5258,8 +5266,12 @@ export default class KoniExtension {
return await this.upsertCustomToken(request as _ChainAsset);
case 'pri(chainService.deleteCustomAsset)':
return this.deleteCustomAsset(request as string);
case 'pri(chainService.validateCustomBrc20)':
return await this.validateCustomBrc20(request as _ValidateCustomBrc20Request);
case 'pri(chainService.validateCustomAsset)':
return await this.validateCustomAsset(request as _ValidateCustomAssetRequest);
case 'pri(chainService.validateCustomRune)':
return await this.validateCustomRune(request as _ValidateCustomRuneRequest);
case 'pri(assetSetting.getSubscription)':
return this.subscribeAssetSetting(id, port);
case 'pri(assetSetting.update)':
Expand Down
10 changes: 9 additions & 1 deletion packages/extension-base/src/koni/background/handlers/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import BuyService from '@subwallet/extension-base/services/buy-service';
import CampaignService from '@subwallet/extension-base/services/campaign-service';
import { ChainService } from '@subwallet/extension-base/services/chain-service';
import { _DEFAULT_MANTA_ZK_CHAIN, _MANTA_ZK_CHAIN_GROUP, _PREDEFINED_SINGLE_MODES } from '@subwallet/extension-base/services/chain-service/constants';
import { _ChainState, _NetworkUpsertParams, _ValidateCustomAssetRequest } from '@subwallet/extension-base/services/chain-service/types';
import { _ChainState, _NetworkUpsertParams, _ValidateCustomAssetRequest, _ValidateCustomBrc20Request, _ValidateCustomRuneRequest } from '@subwallet/extension-base/services/chain-service/types';
import { _getEvmChainId, _getSubstrateGenesisHash, _getTokenOnChainAssetId, _isAssetFungibleToken, _isChainEnabled, _isChainTestNet, _parseMetadataForSmartContractAsset } from '@subwallet/extension-base/services/chain-service/utils';
import EarningService from '@subwallet/extension-base/services/earning-service/service';
import { EventService } from '@subwallet/extension-base/services/event-service';
Expand Down Expand Up @@ -1040,10 +1040,18 @@ export default class KoniState {
return this.chainService.getSupportedSmartContractTypes();
}

public async validateCustomBrc20 (data: _ValidateCustomBrc20Request) {
return await this.chainService.validateCustomBrc20(data);
}

public async validateCustomAsset (data: _ValidateCustomAssetRequest) {
return await this.chainService.validateCustomToken(data);
}

public async validateCustomRune (data: _ValidateCustomRuneRequest) {
return await this.chainService.validateCustomRune(data);
}

// ------------------------------------------------

public getActiveChainInfoMap () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { _AssetType, _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types
import { APIItemState } from '@subwallet/extension-base/background/KoniTypes';
import { AccountJson } from '@subwallet/extension-base/background/types';
import { COMMON_REFRESH_BALANCE_INTERVAL } from '@subwallet/extension-base/constants';
import { Brc20BalanceItem } from '@subwallet/extension-base/services/chain-service/handler/bitcoin/strategy/BlockStream/types';
import { _BitcoinApi, _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
import { _getChainNativeTokenSlug, _getRuneId, _isPureBitcoinChain, _isPureEvmChain, _isSupportRuneChain } from '@subwallet/extension-base/services/chain-service/utils';
import { _getChainNativeTokenSlug, _getRuneId, _isPureBitcoinChain, _isPureEvmChain } from '@subwallet/extension-base/services/chain-service/utils';
import { BalanceItem } from '@subwallet/extension-base/types';
import { filterAssetsByChainAndType, filteredOutTxsUtxos, filterOutPendingTxsUtxos, getInscriptionUtxos, getRuneTxsUtxos } from '@subwallet/extension-base/utils';
import { getKeypairTypeByAddress, isBitcoinAddress } from '@subwallet/keyring';
Expand Down Expand Up @@ -76,10 +77,9 @@ const filterAddress = (addresses: string[], chainInfo: _ChainInfo): [string[], s
};

// todo: update bitcoin params
function subscribeAddressesRuneInfo (bitcoinApi: _BitcoinApi, addresses: string[], assetMap: Record<string, _ChainAsset>, chainInfo: _ChainInfo, callback: (rs: BalanceItem[]) => void) {
// todo: currently set decimal of runes on chain list to zero because the amount api return is after decimal
function subscribeRuneBalance (bitcoinApi: _BitcoinApi, addresses: string[], assetMap: Record<string, _ChainAsset>, chainInfo: _ChainInfo, callback: (rs: BalanceItem[]) => void) {
const chain = chainInfo.slug;
const tokenList = filterAssetsByChainAndType(assetMap, chain, [_AssetType.LOCAL]);
const tokenList = filterAssetsByChainAndType(assetMap, chain, [_AssetType.RUNE]);

// todo: check await asset ready before subscribe
if (Object.keys(tokenList).length === 0) {
Expand All @@ -104,6 +104,10 @@ function subscribeAddressesRuneInfo (bitcoinApi: _BitcoinApi, addresses: string[
runes.forEach((rune) => {
const runeId = rune.rune_id;

if (!Object.keys(runeIdToSlugMap).includes(runeId)) {
return;
}

const item = {
address: address,
tokenSlug: runeIdToSlugMap[runeId],
Expand Down Expand Up @@ -141,6 +145,53 @@ function subscribeAddressesRuneInfo (bitcoinApi: _BitcoinApi, addresses: string[
};
}

function subscribeBRC20Balance (bitcoinApi: _BitcoinApi, addresses: string[], assetMap: Record<string, _ChainAsset>, chainInfo: _ChainInfo, callback: (rs: BalanceItem[]) => void) {
const chain = chainInfo.slug;
const tokenList = filterAssetsByChainAndType(assetMap, chain, [_AssetType.BRC20]);

const getBRC20Balance = () => {
Object.values(tokenList).map(async (token) => {
try {
const ticker = token.symbol;
const balances: Brc20BalanceItem[] = await Promise.all(addresses.map(async (address) => {
try {
return await bitcoinApi.api.getAddressBRC20FreeLockedBalance(address, ticker);
} catch (error) {
console.error(`Error on get BRC balance of account ${address} for token ${token.slug}`, error);

return {
free: '0',
locked: '0'
};
}
}));

const items: BalanceItem[] = balances.map((balance, index): BalanceItem => {
return {
address: addresses[index],
tokenSlug: token.slug,
free: balance.free || '0',
locked: balance.locked || '0',
state: APIItemState.READY
};
});

callback(items);
} catch (error) {
console.log(token.slug, error);
}
});
};

getBRC20Balance();

const interval = setInterval(getBRC20Balance, COMMON_REFRESH_BALANCE_INTERVAL);

return () => {
clearInterval(interval);
};
}

async function getBitcoinBalance (bitcoinApi: _BitcoinApi, addresses: string[]) {
return await Promise.all(addresses.map(async (address) => {
try {
Expand Down Expand Up @@ -211,20 +262,17 @@ function subscribeBitcoinBalance (addresses: string[], chainInfo: _ChainInfo, as
};

getBalance();

const interval = setInterval(getBalance, COMMON_REFRESH_BALANCE_INTERVAL);

if (_isSupportRuneChain(chainInfo.slug)) {
const unsub = subscribeAddressesRuneInfo(bitcoinApi, addresses, assetMap, chainInfo, callback);
const unsub = subscribeRuneBalance(bitcoinApi, addresses, assetMap, chainInfo, callback);
const unsub2 = subscribeBRC20Balance(bitcoinApi, addresses, assetMap, chainInfo, callback);

return () => {
clearInterval(interval);
unsub && unsub();
};
} else {
return () => {
clearInterval(interval);
};
}
return () => {
clearInterval(interval);
unsub && unsub();
unsub2 && unsub2();
};
}

// main subscription, use for multiple chains, multiple addresses and multiple tokens
Expand Down
Loading
Loading