Skip to content

Commit

Permalink
Hot-fix - move keyring use to balance service
Browse files Browse the repository at this point in the history
  • Loading branch information
saltict committed Dec 6, 2023
1 parent 4591606 commit f56988d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,46 @@

import { _AssetType, _ChainInfo } from '@subwallet/chain-list/types';
import { APIItemState } from '@subwallet/extension-base/background/KoniTypes';
import { AccountJson } from '@subwallet/extension-base/background/types';
import { state } from '@subwallet/extension-base/koni/background/handlers';
import { _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
import { _getSubstrateGenesisHash, _isChainEvmCompatible, _isPureEvmChain } from '@subwallet/extension-base/services/chain-service/utils';
import { BalanceItem } from '@subwallet/extension-base/types';
import { categoryAddresses } from '@subwallet/extension-base/utils';
import { getAccountJsonByAddress } from '@subwallet/extension-base/utils/account';
import keyring from '@subwallet/ui-keyring';

import { subscribeEVMBalance } from './evm';
import { subscribeSubstrateBalance } from './substrate';

/**
* @function getAccountJsonByAddress
* @desc Get account info by address
* <p>
* Note: Use on the background only
* </p>
* @param {string} address - Address
* @returns {AccountJson|null} - Account info or null if not found
*/
export const getAccountJsonByAddress = (address: string): AccountJson | null => {
try {
const pair = keyring.getPair(address);

if (pair) {
return {
address: pair.address,
type: pair.type,
...pair.meta
};
} else {
return null;
}
} catch (e) {
console.warn(e);

return null;
}
};

const filterAddress = (addresses: string[], chainInfo: _ChainInfo): [string[], string[]] => {
const isEvmChain = _isChainEvmCompatible(chainInfo);
const [substrateAddresses, evmAddresses] = categoryAddresses(addresses);
Expand Down
32 changes: 1 addition & 31 deletions packages/extension-base/src/utils/account.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { AccountJson, AddressJson } from '@subwallet/extension-base/background/types';
import { AddressJson } from '@subwallet/extension-base/background/types';
import { reformatAddress } from '@subwallet/extension-base/utils/index';
import keyring from '@subwallet/ui-keyring';
import { SubjectInfo } from '@subwallet/ui-keyring/observable/types';

import { decodeAddress, encodeAddress, isAddress, isEthereumAddress } from '@polkadot/util-crypto';
Expand All @@ -27,32 +26,3 @@ export function quickFormatAddressToCompare (address?: string) {
export const convertSubjectInfoToAddresses = (subjectInfo: SubjectInfo): AddressJson[] => {
return Object.values(subjectInfo).map((info): AddressJson => ({ address: info.json.address, type: info.type, ...info.json.meta }));
};

/**
* @function getAccountJsonByAddress
* @desc Get account info by address
* <p>
* Note: Use on the background only
* </p>
* @param {string} address - Address
* @returns {AccountJson|null} - Account info or null if not found
*/
export const getAccountJsonByAddress = (address: string): AccountJson | null => {
try {
const pair = keyring.getPair(address);

if (pair) {
return {
address: pair.address,
type: pair.type,
...pair.meta
};
} else {
return null;
}
} catch (e) {
console.warn(e);

return null;
}
};

2 comments on commit f56988d

@saltict
Copy link
Author

@saltict saltict commented on f56988d Dec 6, 2023

Choose a reason for hiding this comment

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

@saltict
Copy link
Author

@saltict saltict commented on f56988d Dec 6, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.