-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add open API, ref leather-io/issues#5800
- Loading branch information
1 parent
523d3ca
commit 3df62f7
Showing
5 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { RpcErrorCode } from '@btckit/types'; | ||
|
||
import { RouteUrls } from '@shared/route-urls'; | ||
import { OpenRequest } from '@shared/rpc/methods/open'; | ||
import { makeRpcErrorResponse } from '@shared/rpc/rpc-methods'; | ||
|
||
import { | ||
listenForPopupClose, | ||
makeSearchParamsWithDefaults, | ||
triggerRequestWindowOpen, | ||
} from '../messaging-utils'; | ||
import { trackRpcRequestSuccess } from '../rpc-message-handler'; | ||
|
||
export async function rpcOpen(message: OpenRequest, port: chrome.runtime.Port) { | ||
const { urlParams, tabId } = makeSearchParamsWithDefaults(port, [['requestId', message.id]]); | ||
const { id } = await triggerRequestWindowOpen(RouteUrls.Home, urlParams); | ||
void trackRpcRequestSuccess({ endpoint: message.method }); | ||
|
||
listenForPopupClose({ | ||
tabId, | ||
id, | ||
response: makeRpcErrorResponse('open', { | ||
id: message.id, | ||
error: { | ||
code: RpcErrorCode.USER_REJECTION, | ||
message: 'User rejected request to open wallet', | ||
}, | ||
}), | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { DefineRpcMethod, RpcRequest, RpcResponse } from '@btckit/types'; | ||
import * as yup from 'yup'; | ||
|
||
const rpcOpenParamsSchema = yup.object().shape({ | ||
url: yup.string(), | ||
}); | ||
|
||
type OpenRequestParams = yup.InferType<typeof rpcOpenParamsSchema>; | ||
|
||
export type OpenRequest = RpcRequest<'open', OpenRequestParams>; | ||
|
||
type OpenResponse = RpcResponse<Response>; | ||
|
||
export type Open = DefineRpcMethod<OpenRequest, OpenResponse>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters