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

OK-27755: Add getBTCTipHeight method to Babylon's Provider #4581

Merged
merged 3 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@
"@cmdcode/crypto-utils": "1.9.5",
"@cmdcode/tapscript": "1.2.9",
"@legendapp/state": "^1.2.9",
"@onekeyfe/cross-inpage-provider-core": "1.1.59",
"@onekeyfe/cross-inpage-provider-errors": "1.1.59",
"@onekeyfe/cross-inpage-provider-injected": "1.1.59",
"@onekeyfe/cross-inpage-provider-types": "1.1.59",
"@onekeyfe/extension-bridge-hosted": "1.1.59",
"@onekeyfe/cross-inpage-provider-core": "1.1.60",
"@onekeyfe/cross-inpage-provider-errors": "1.1.60",
"@onekeyfe/cross-inpage-provider-injected": "1.1.60",
"@onekeyfe/cross-inpage-provider-types": "1.1.60",
"@onekeyfe/extension-bridge-hosted": "1.1.60",
"@onekeyfe/hd-ble-sdk": "0.3.47",
"@onekeyfe/hd-core": "0.3.47",
"@onekeyfe/hd-shared": "0.3.47",
"@onekeyfe/hd-transport": "0.3.47",
"@onekeyfe/hd-web-sdk": "0.3.47",
"@onekeyfe/onekey-cross-webview": "1.1.59",
"@onekeyfe/onekey-cross-webview": "1.1.60",
"@starcoin/starcoin": "2.1.5",
"@web3-react/core": "8.0.35-beta.0",
"@web3-react/empty": "8.0.20-beta.0",
Expand Down
19 changes: 18 additions & 1 deletion packages/kit-bg/src/providers/ProviderApiBtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import {
providerApiMethod,
} from '@onekeyhq/shared/src/background/backgroundDecorators';
import { OnekeyNetwork } from '@onekeyhq/shared/src/config/networkIds';
import { IMPL_BTC, IMPL_TBTC } from '@onekeyhq/shared/src/engine/engineConsts';
import {
IMPL_BTC,
IMPL_TBTC,
isBTCNetwork,
} from '@onekeyhq/shared/src/engine/engineConsts';
import debugLogger from '@onekeyhq/shared/src/logger/debugLogger';
import type {
DecodedPsbt,
Expand Down Expand Up @@ -678,6 +682,19 @@ class ProviderApiBtc extends ProviderApiBase {

return result;
}

@providerApiMethod()
public async getBTCTipHeight() {
const { networkId } = getActiveWalletAccount();
if (!isBTCNetwork(networkId)) {
throw new Error('Invalid network');
}
const status = await this.backgroundApi.serviceNetwork.measureRpcStatus(
networkId,
);
const blockHeight = new BigNumber(status?.latestBlock ?? '0').toNumber();
return blockHeight;
}
}

export default ProviderApiBtc;
23 changes: 16 additions & 7 deletions packages/kit-bg/src/services/ServiceDapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,22 @@ class ServiceDapp extends ServiceBase {
if (!impl) {
return false;
}
const accounts = this.backgroundApi.serviceDapp?.getActiveConnectedAccounts(
{
origin: request.origin,
impl,
},
);
return Boolean(accounts && accounts.length);
// hack for multiple impls detect
const impls = [impl];
if (impl === IMPL_BTC) {
impls.push(IMPL_TBTC);
}
for (const implItem of impls) {
const accounts =
this.backgroundApi.serviceDapp?.getActiveConnectedAccounts({
origin: request.origin,
impl: implItem,
});
if (accounts && accounts.length) {
return true;
}
}
return false;
}

@backgroundMethod()
Expand Down
Loading
Loading