mirror of
https://github.com/zhigang1992/wallet.git
synced 2026-01-12 22:53:27 +08:00
chore: improve rpc message erroring
This commit is contained in:
2
.github/workflows/build-extension.yml
vendored
2
.github/workflows/build-extension.yml
vendored
@@ -21,7 +21,7 @@ jobs:
|
||||
update-pull-request-body:
|
||||
name: Add links to built extensions
|
||||
# Don't run on forks
|
||||
if: github.event.pull_request.head.repo.full_name == github.repository
|
||||
if: github.repository == 'hirosystems/wallet'
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- pre_run
|
||||
|
||||
@@ -2,7 +2,11 @@ import { RpcErrorCode } from '@btckit/types';
|
||||
|
||||
import { isSupportedMessageSigningPaymentType } from '@shared/crypto/bitcoin/bip322/bip322-utils';
|
||||
import { RouteUrls } from '@shared/route-urls';
|
||||
import { WalletRequests, makeRpcErrorResponse } from '@shared/rpc/rpc-methods';
|
||||
import {
|
||||
WalletRequests,
|
||||
makeRpcErrorResponse,
|
||||
makeRpcSuccessResponse,
|
||||
} from '@shared/rpc/rpc-methods';
|
||||
|
||||
import {
|
||||
getTabIdFromPort,
|
||||
@@ -118,6 +122,36 @@ export async function rpcMessageHandler(message: WalletRequests, port: chrome.ru
|
||||
break;
|
||||
}
|
||||
|
||||
case 'supportedMethods': {
|
||||
const { tabId } = makeSearchParamsWithDefaults(port);
|
||||
chrome.tabs.sendMessage(
|
||||
tabId,
|
||||
makeRpcSuccessResponse('supportedMethods', {
|
||||
id: message.id,
|
||||
result: {
|
||||
documentation: 'https://hirowallet.gitbook.io/developers',
|
||||
methods: [
|
||||
{
|
||||
name: 'getAddresses',
|
||||
docsUrl: [
|
||||
'https://hirowallet.gitbook.io/developers/bitcoin/connect-users/get-addresses',
|
||||
'https://btckit.org/docs/requests/getaddresses',
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'signMessage',
|
||||
docsUrl: 'https://hirowallet.gitbook.io/developers/bitcoin/sign-messages',
|
||||
},
|
||||
{
|
||||
name: 'sendTransfer',
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
chrome.tabs.sendMessage(
|
||||
getTabIdFromPort(port),
|
||||
@@ -125,7 +159,7 @@ export async function rpcMessageHandler(message: WalletRequests, port: chrome.ru
|
||||
id: message.id,
|
||||
error: {
|
||||
code: RpcErrorCode.METHOD_NOT_FOUND,
|
||||
message: `${message.method} is not supported`,
|
||||
message: `"${message.method}" is not supported. Try running \`.request('supportedMethods')\` to see what Hiro Wallet can do, or check out our developer documentation at https://hirowallet.gitbook.io/developers`,
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
11
src/shared/rpc/methods/supported-methods.ts
Normal file
11
src/shared/rpc/methods/supported-methods.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { DefineRpcMethod, RpcRequest, RpcSuccessResponse } from '@btckit/types';
|
||||
|
||||
// Demo method used to serve as example while we only have a single method
|
||||
type SupportedMethodsRequest = RpcRequest<'supportedMethods'>;
|
||||
|
||||
type SupportedMethodsResponse = RpcSuccessResponse<{
|
||||
documentation: string;
|
||||
methods: { name: string; docsUrl?: string | string[] }[];
|
||||
}>;
|
||||
|
||||
export type SupportedMethods = DefineRpcMethod<SupportedMethodsRequest, SupportedMethodsResponse>;
|
||||
@@ -2,9 +2,11 @@ import { BtcKitMethodMap, ExtractErrorResponse, ExtractSuccessResponse } from '@
|
||||
|
||||
import { ValueOf } from '@shared/utils/type-utils';
|
||||
|
||||
import { SupportedMethods } from './methods/supported-methods';
|
||||
import { Test } from './methods/test-method';
|
||||
|
||||
export type WalletMethodMap = BtcKitMethodMap & Test;
|
||||
// Supports BtcKit methods, as well as custom Hiro Wallet methods
|
||||
export type WalletMethodMap = BtcKitMethodMap & Test & SupportedMethods;
|
||||
|
||||
export type WalletRequests = ValueOf<WalletMethodMap>['request'];
|
||||
export type WalletResponses = ValueOf<WalletMethodMap>['response'];
|
||||
|
||||
Reference in New Issue
Block a user