From 831e4cb313b61021b41ca71d87cd66ae38b7307b Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 6 Aug 2021 13:08:08 +1000 Subject: [PATCH] Directly return errors from background script to in-page script The listener in `browser.runtime.onMessage.addListener` can handle promises. As such, we can directly _reject_ this promise if there is any error in invoking the various wallet functions. Such a rejected promise is then _caught_ inside the content script and forwarded as an event to the in-page script. The communication of the events between in-page script and content-script has been reworked. 1. The new implementation contains less duplicated code due to the use of a generic `invokeContentScript` function. 2. Every request is tagged with an ID which allows us to uniquely identify, which particular request failed. This should help with race conditions where the same event is fired multiple times. Related: #196. --- extension/package.json | 5 +- extension/src/App.tsx | 8 +- extension/src/background-proxy.ts | 16 +- extension/src/background/index.ts | 220 +++++++++---------- extension/src/components/ConfirmLoan.tsx | 6 +- extension/src/components/ConfirmSwap.tsx | 6 +- extension/src/contentScript/index.ts | 67 +++--- extension/src/in-page/index.ts | 265 +++++++---------------- extension/src/messages.ts | 30 --- extension/src/models.ts | 2 - extension/yarn.lock | 27 ++- 11 files changed, 264 insertions(+), 388 deletions(-) delete mode 100644 extension/src/messages.ts diff --git a/extension/package.json b/extension/package.json index 179569f27..dec4c2906 100644 --- a/extension/package.json +++ b/extension/package.json @@ -40,11 +40,12 @@ "@testing-library/jest-dom": "^5.11.4", "@testing-library/react": "^11.1.0", "@testing-library/user-event": "^12.1.10", - "@types/debug": "^4.1.5", + "@types/debug": "^4.1.7", "@types/jest": "^25.0.0", "@types/node": "^12.0.0", "@types/react": "^16.9.0", "@types/react-dom": "^16.9.0", + "@types/uuid": "^8.3.1", "debug": "^4.3.1", "framer-motion": "^4.0.0", "moment": "^2.29.1", @@ -54,7 +55,9 @@ "react-dom": "^17.0.2", "react-qr-code": "^1.1.1", "react-scripts": "4.0.1", + "type-fest": "^2.0.0", "typescript": "^4.1.2", + "uuid": "^8.3.2", "wasm-pack": "0.10.0", "web-ext": "^6.1.0", "web-vitals": "^1.0.1", diff --git a/extension/src/App.tsx b/extension/src/App.tsx index 1fe745660..31861b621 100644 --- a/extension/src/App.tsx +++ b/extension/src/App.tsx @@ -77,8 +77,8 @@ const App = () => { {!signLoan && !swapToSign && } {swapToSign && { - await rejectSwap(tabId); + onCancel={async () => { + await rejectSwap(); refreshAll(); }} onSuccess={refreshAll} @@ -86,8 +86,8 @@ const App = () => { />} {signLoan && { - await rejectLoan(tabId); + onCancel={async () => { + await rejectLoan(); refreshAll(); }} onSuccess={refreshAll} diff --git a/extension/src/background-proxy.ts b/extension/src/background-proxy.ts index 1f0193e67..27b30ad25 100644 --- a/extension/src/background-proxy.ts +++ b/extension/src/background-proxy.ts @@ -8,14 +8,14 @@ export async function getAddress(): Promise
{ return proxy.getAddress(); } -export async function signAndSendSwap(txHex: string, tabId: number): Promise { +export async function signAndSendSwap(txHex: string): Promise { // @ts-ignore - return proxy.signAndSendSwap(txHex, tabId); + return proxy.signAndSendSwap(txHex); } -export async function signLoan(tabId: number): Promise { +export async function signLoan(): Promise { // @ts-ignore - return proxy.signLoan(tabId); + return proxy.signLoan(); } export async function getLoanToSign(): Promise { @@ -28,14 +28,14 @@ export async function getSwapToSign(): Promise { return proxy.getSwapToSign(); } -export async function rejectLoan(tabId: number): Promise { +export async function rejectLoan(): Promise { // @ts-ignore - return proxy.rejectLoan(tabId); + return proxy.rejectLoan(); } -export async function rejectSwap(tabId: number): Promise { +export async function rejectSwap(): Promise { // @ts-ignore - return proxy.rejectSwap(tabId); + return proxy.rejectSwap(); } export async function withdrawAll(address: string): Promise { diff --git a/extension/src/background/index.ts b/extension/src/background/index.ts index a60322808..a6ea6fc1f 100644 --- a/extension/src/background/index.ts +++ b/extension/src/background/index.ts @@ -1,7 +1,7 @@ import Debug from "debug"; import { browser } from "webextension-polyfill-ts"; -import { Direction, Message, MessageKind } from "../messages"; -import { LoanDetails, LoanToSign, SwapToSign } from "../models"; +import WavesProvider from "../in-page"; +import { LoanDetails, LoanToSign, SwapToSign, Txid } from "../models"; import { bip39SeedWords, createNewBip39Wallet, @@ -26,7 +26,6 @@ import { // TODO: Is this global or do we need one per file? Debug.enable("*"); const debug = Debug("background"); -const error = Debug("background:error"); // First thing we load settings loadSettings(); @@ -34,84 +33,78 @@ loadSettings(); debug("Hello world from background script"); const walletName = "demo"; -var swapToSign: SwapToSign | undefined; -var loanToSign: LoanToSign | undefined; - -browser.runtime.onMessage.addListener(async (msg: Message, sender) => { - debug(`Received: %o from tab %d`, msg, sender.tab?.id); - - if (msg.direction === Direction.ToBackground) { - let message; - switch (msg.kind) { - case MessageKind.WalletStatusRequest: - message = await call_wallet(() => walletStatus(walletName), MessageKind.WalletStatusResponse); - break; - case MessageKind.SellRequest: - message = await call_wallet( - async () => await makeSellCreateSwapPayload(walletName, msg.payload), - MessageKind.SellResponse, - ); - break; - case MessageKind.BuyRequest: - message = await call_wallet( - async () => await makeBuyCreateSwapPayload(walletName, msg.payload), - MessageKind.BuyResponse, - ); - break; - case MessageKind.AddressRequest: - message = await call_wallet( - async () => await getAddress(walletName), - MessageKind.AddressResponse, - ); - break; - case MessageKind.LoanRequest: - message = await call_wallet( - async () => - await makeLoanRequestPayload( - walletName, - msg.payload.collateral, - msg.payload.fee_rate, - ), - MessageKind.LoanResponse, - ); - break; - case MessageKind.SignAndSendSwap: - try { - const txHex = msg.payload; - const decoded = await extractTrade(walletName, txHex); - swapToSign = { txHex, decoded, tabId: sender.tab!.id! }; - updateBadge(); - } catch (e) { - error(e); - message = { kind: MessageKind.SwapTxid, direction: Direction.ToPage, error: e }; - } - break; - case MessageKind.SignLoan: - try { - const details = await extractLoan(walletName, msg.payload); - loanToSign = { details, tabId: sender.tab!.id! }; - updateBadge(); - } catch (e) { - error(e); - message = { kind: MessageKind.SignedLoan, direction: Direction.ToPage, error: e }; - } - break; - } - return message; - } + +var swapToSign: SwapToSign | null; +var resolveSwapSignRequest: ((txid: Txid) => void) | null; +var rejectSwapSignRequest: ((e: any) => void) | null; + +var loanToSign: LoanToSign | null; +var resolveLoanSignRequest: ((txid: Txid) => void) | null; +var rejectLoanSignRequest: ((e: any) => void) | null; + +export interface RpcMessage { + type: "rpc-message"; + method: T; + args: Parameters; +} + +/* + * Defines the public interface of the background script. + * + * To ensure maximum benefit from the type checker, other components like the content script should only use this function to send messages. + */ +export function invokeBackgroundScriptRpc(message: Omit, "type">): Promise { + return browser.runtime.sendMessage({ + type: "rpc-message", + ...message, + }); +} + +addRpcMessageListener("walletStatus", () => walletStatus(walletName)); +addRpcMessageListener("getBuyCreateSwapPayload", ([usdt]) => makeBuyCreateSwapPayload(walletName, usdt)); +addRpcMessageListener("getSellCreateSwapPayload", ([btc]) => makeSellCreateSwapPayload(walletName, btc)); +addRpcMessageListener("getNewAddress", () => getAddress(walletName)); +addRpcMessageListener( + "makeLoanRequestPayload", + ([collateral, feerate]) => makeLoanRequestPayload(walletName, collateral, feerate), +); + +addRpcMessageListener("signAndSendSwap", ([txHex]) => { + extractTrade(walletName, txHex).then(decoded => { + swapToSign = { txHex, decoded }; + updateBadge(); + }); + + return new Promise((resolve, reject) => { + resolveSwapSignRequest = resolve; + rejectSwapSignRequest = reject; + }); +}); +addRpcMessageListener("signLoan", ([loanRequest]) => { + extractLoan(walletName, loanRequest).then(details => { + loanToSign = { details }; + updateBadge(); + }); + + return new Promise((resolve, reject) => { + resolveLoanSignRequest = resolve; + rejectLoanSignRequest = reject; + }); }); -async function call_wallet(wallet_fn: () => Promise, kind: MessageKind): Promise> { - let payload; - let err; - try { - payload = await wallet_fn(); - } catch (e) { - error(e); - err = e; - } +function addRpcMessageListener( + method: T, + callback: (args: Parameters) => ReturnType, +) { + browser.runtime.onMessage.addListener((msg: RpcMessage) => { + if (msg.type !== "rpc-message" || msg.method !== method) { + return; + } + + debug(`Received: %o`, msg); - return { kind, direction: Direction.ToPage, payload, error: err }; + return callback(msg.args); + }); } // @ts-ignore @@ -135,25 +128,28 @@ window.getSwapToSign = async () => { return swapToSign; }; // @ts-ignore -window.signAndSendSwap = async (txHex: string, tabId: number) => { - let payload; - let err; - - try { - payload = await signAndSendSwap(walletName, txHex); - } catch (e) { - error(e); - err = e; +window.signAndSendSwap = (txHex: string) => { + if (!resolveSwapSignRequest || !rejectSwapSignRequest) { + throw new Error("No pending promise functions for swap sign request"); } - browser.tabs.sendMessage(tabId, { direction: Direction.ToPage, kind: MessageKind.SwapTxid, payload, error: err }); - swapToSign = undefined; - updateBadge(); + signAndSendSwap(walletName, txHex).then(resolveSwapSignRequest).catch(rejectSwapSignRequest).then(() => { + resolveSwapSignRequest = null; + rejectSwapSignRequest = null; + swapToSign = null; + updateBadge(); + }); }; // @ts-ignore -window.rejectSwap = (tabId: number) => { - browser.tabs.sendMessage(tabId, { direction: Direction.ToPage, kind: MessageKind.SwapRejected }); - swapToSign = undefined; +window.rejectSwap = () => { + if (!resolveSwapSignRequest || !rejectSwapSignRequest) { + throw new Error("No pending promise functions for swap sign request"); + } + + rejectSwapSignRequest("User declined signing request"); + rejectSwapSignRequest = null; + swapToSign = null; + updateBadge(); }; // @ts-ignore @@ -161,31 +157,31 @@ window.getLoanToSign = () => { return loanToSign; }; // @ts-ignore -window.signLoan = async (tabId: number) => { +window.signLoan = async () => { + if (!resolveLoanSignRequest || !rejectLoanSignRequest) { + throw new Error("No pending promise functions for loan sign request"); + } + // TODO: Currently, we assume that whatever the user has verified // on the pop-up matches what is stored in the extension's // storage. It would be better to send around the swap ID to check // that the wallet is signing the same transaction the user has authorised - - let payload; - let err; - - try { - payload = await signLoan(walletName); - } catch (e) { - error(e); - err = e; - } - - browser.tabs.sendMessage(tabId, { direction: Direction.ToPage, kind: MessageKind.SignedLoan, payload, error: err }); - loanToSign = undefined; - updateBadge(); + signLoan(walletName).then(resolveLoanSignRequest).catch(rejectLoanSignRequest).then(() => { + resolveLoanSignRequest = null; + rejectLoanSignRequest = null; + loanToSign = null; + updateBadge(); + }); }; // @ts-ignore -window.rejectLoan = (tabId: number) => { - browser.tabs.sendMessage(tabId, { direction: Direction.ToPage, kind: MessageKind.LoanRejected }); - loanToSign = undefined; - updateBadge(); +window.rejectLoan = () => { + if (!resolveLoanSignRequest || !rejectLoanSignRequest) { + throw new Error("No pending promise functions for loan sign request"); + } + + rejectLoanSignRequest("User declined signing request"); + rejectLoanSignRequest = null; + loanToSign = null; }; // @ts-ignore window.withdrawAll = async (address: string) => { diff --git a/extension/src/components/ConfirmLoan.tsx b/extension/src/components/ConfirmLoan.tsx index 504bf97fb..88a01b3ab 100644 --- a/extension/src/components/ConfirmLoan.tsx +++ b/extension/src/components/ConfirmLoan.tsx @@ -11,7 +11,7 @@ import Usdt from "./tether.svg"; const debug = Debug("confirmloan:error"); interface ConfirmLoanProps { - onCancel: (tabId: number) => void; + onCancel: () => void; onSuccess: () => void; loanToSign: LoanToSign; } @@ -21,7 +21,7 @@ export default function ConfirmLoan( ) { let { isPending, run } = useAsync({ deferFn: async () => { - await signLoan(loanToSign.tabId); + await signLoan(); onSuccess(); }, }); @@ -92,7 +92,7 @@ export default function ConfirmLoan( diff --git a/extension/src/components/ConfirmSwap.tsx b/extension/src/components/ConfirmSwap.tsx index 48071e3a8..2130a9183 100644 --- a/extension/src/components/ConfirmSwap.tsx +++ b/extension/src/components/ConfirmSwap.tsx @@ -6,7 +6,7 @@ import { SwapToSign } from "../models"; import YouSwapItem from "./SwapItem"; interface ConfirmSwapProps { - onCancel: (tabId: number) => void; + onCancel: () => void; onSuccess: () => void; swapToSign: SwapToSign; } @@ -16,7 +16,7 @@ export default function ConfirmSwap( ) { let { isPending, run } = useAsync({ deferFn: async () => { - await signAndSendSwap(swapToSign.txHex, swapToSign.tabId); + await signAndSendSwap(swapToSign.txHex); onSuccess(); }, }); @@ -47,7 +47,7 @@ export default function ConfirmSwap( diff --git a/extension/src/contentScript/index.ts b/extension/src/contentScript/index.ts index 5dc09a7e1..b372d8e1a 100644 --- a/extension/src/contentScript/index.ts +++ b/extension/src/contentScript/index.ts @@ -1,46 +1,53 @@ import Debug from "debug"; +import { AsyncReturnType } from "type-fest"; import { browser } from "webextension-polyfill-ts"; -import { Direction, Message } from "../messages"; +import { invokeBackgroundScriptRpc } from "../background"; +import WavesProvider from "../in-page"; Debug.enable("*"); const debug = Debug("content"); debug("Hello world from content script"); -async function forwardToBackground(message: Message): Promise> { - try { - return await browser.runtime.sendMessage(message); - } catch (error) { - debug(`Error: ${JSON.stringify(error)}`); - throw error; - } +export interface RequestMessage { + type: "request"; + method: T; + args: Parameters; + id: string; } -window.addEventListener("message", async function(event: MessageEvent>) { - if ( - event.source === window - && event.data.direction === Direction.ToBackground - ) { - debug(`Forwarding request from ips to bs: ${JSON.stringify(event.data)}`); - let response = await forwardToBackground(event.data); +export interface ResponseMessage { + type: "response"; + id: string; + ok?: AsyncReturnType; + err?: string; +} - if (response) { - debug(`Forwarding response from bs to ips: ${JSON.stringify(response)}`); - window.postMessage(response, "*"); - } +window.addEventListener("message", (event: MessageEvent>) => { + if (event.source !== window || event.data.type !== "request") { + return; } -}); -browser.runtime.onMessage.addListener(async function(msg: Message) { - // Some messages from the background script (the ones that depend on - // user interaction via the pop-up), are not a direct response to a - // message we send fro the content script, so we must be ready to - // listen for messages from the background script and forward them to - // the content script too - if (msg.direction === Direction.ToPage) { - debug(`Forwarding message from bs to ips: ${JSON.stringify(msg)}`); - window.postMessage(msg, "*"); - } + invokeBackgroundScriptRpc({ + method: event.data.method, + args: event.data.args, + }).then(ok => { + let responseMessage: ResponseMessage = { + type: "response", + id: event.data.id, + ok, + }; + + window.postMessage(responseMessage, "*"); + }).catch(err => { + let responseMessage: ResponseMessage = { + type: "response", + id: event.data.id, + err: err.toString(), // Unfortunately, we have to send a string representation here + }; + + window.postMessage(responseMessage, "*"); + }); }); /** diff --git a/extension/src/in-page/index.ts b/extension/src/in-page/index.ts index e81e25d32..bed3a9db5 100644 --- a/extension/src/in-page/index.ts +++ b/extension/src/in-page/index.ts @@ -1,5 +1,7 @@ import Debug from "debug"; -import { Direction, Message, MessageKind } from "../messages"; +import { AsyncReturnType } from "type-fest"; +import { v4 } from "uuid"; +import { RequestMessage, ResponseMessage } from "../contentScript"; import { Address, CreateSwapPayload, LoanRequestPayload, Tx, Txid, WalletStatus } from "../models"; Debug.enable("*"); @@ -7,113 +9,19 @@ const debug = Debug("inpage"); export default class WavesProvider { public async walletStatus(): Promise { - debug("Requesting wallet status"); - let promise = new Promise((resolve, reject) => { - let listener = async function(event: MessageEvent>) { - if ( - event.data.direction === Direction.ToPage - && event.data.kind === MessageKind.WalletStatusResponse - ) { - if (event.data.error) { - reject(event.data.error); - } else { - debug(`Received wallet status: ${JSON.stringify(event.data)}`); - - window.removeEventListener("message", listener); - resolve(event.data.payload); - } - } - }; - window.addEventListener("message", listener); - }); - window.postMessage({ - kind: MessageKind.WalletStatusRequest, - direction: Direction.ToBackground, - }, "*"); - return promise; + return invokeContentScript("walletStatus", []); } public async getSellCreateSwapPayload(btc: string): Promise { - debug("Getting sell create-swap payload"); - let promise = new Promise((resolve, reject) => { - let listener = async function(event: MessageEvent>) { - if ( - event.data.direction === Direction.ToPage - && event.data.kind === MessageKind.SellResponse - ) { - if (event.data.error) { - reject(event.data.error); - } else { - debug(`Received sell response: ${JSON.stringify(event.data)}`); - - window.removeEventListener("message", listener); - resolve(event.data.payload); - } - } - }; - window.addEventListener("message", listener); - }); - window.postMessage({ - kind: MessageKind.SellRequest, - direction: Direction.ToBackground, - payload: btc, - }, "*"); - return promise; + return invokeContentScript("getSellCreateSwapPayload", [btc]); } public async getBuyCreateSwapPayload(usdt: string): Promise { - debug("Getting buy create-swap payload"); - let promise = new Promise((resolve, reject) => { - let listener = async function(event: MessageEvent>) { - if ( - event.data.direction === Direction.ToPage - && event.data.kind === MessageKind.BuyResponse - ) { - if (event.data.error) { - reject(event.data.error); - } else { - debug(`Received buy response: ${JSON.stringify(event.data)}`); - - window.removeEventListener("message", listener); - resolve(event.data.payload); - } - } - }; - window.addEventListener("message", listener); - }); - window.postMessage({ - kind: MessageKind.BuyRequest, - direction: Direction.ToBackground, - payload: usdt, - }, "*"); - return promise; + return invokeContentScript("getBuyCreateSwapPayload", [usdt]); } public async getNewAddress(): Promise
{ - debug("Getting address"); - let promise = new Promise
((resolve, reject) => { - let listener = async function(event: MessageEvent>) { - if ( - event.data.direction === Direction.ToPage - && event.data.kind === MessageKind.AddressResponse - ) { - if (event.data.error) { - reject(event.data.kind); - } else { - debug(`Received address: ${JSON.stringify(event.data)}`); - - window.removeEventListener("message", listener); - resolve(event.data.payload); - } - } - }; - window.addEventListener("message", listener); - }); - window.postMessage({ - kind: MessageKind.AddressRequest, - direction: Direction.ToBackground, - }, "*"); - return promise; + return invokeContentScript("getNewAddress", []); } public async makeLoanRequestPayload( @@ -121,103 +29,80 @@ export default class WavesProvider { fee_rate: string, timeout: string, ): Promise { - debug("Making loan request payload"); - let promise = new Promise((resolve, reject) => { - let listener = async function(event: MessageEvent>) { - if ( - event.data.direction === Direction.ToPage - && event.data.kind === MessageKind.LoanResponse - ) { - if (event.data.error) { - reject(event.data.error); - } else { - debug(`Received loan request payload: ${JSON.stringify(event.data)}`); - - window.removeEventListener("message", listener); - resolve(event.data.payload); - } - } - }; - window.addEventListener("message", listener); - }); - window.postMessage({ - kind: MessageKind.LoanRequest, - direction: Direction.ToBackground, - payload: { - collateral: collateral, - fee_rate: fee_rate, - timeout: timeout, - }, - }, "*"); - return promise; + return invokeContentScript("makeLoanRequestPayload", [collateral, fee_rate, timeout]); } public async signAndSendSwap(tx_hex: string): Promise { - debug("Signing and sending swap"); - let promise = new Promise((resolve, reject) => { - let listener = async function(event: MessageEvent>) { - if ( - event.data.direction === Direction.ToPage - ) { - if (event.data.kind === MessageKind.SwapTxid) { - if (event.data.error) { - reject(event.data.error); - } else { - debug(`Received swap txid: ${JSON.stringify(event.data)}`); - - window.removeEventListener("message", listener); - resolve(event.data.payload); - } - } else if (event.data.kind === MessageKind.SwapRejected) { - debug(`Swap rejected: ${JSON.stringify(event.data)}`); - - window.removeEventListener("message", listener); - reject("User rejected swap"); - } - } - }; - window.addEventListener("message", listener); - }); - window.postMessage({ - kind: MessageKind.SignAndSendSwap, - direction: Direction.ToBackground, - payload: tx_hex, - }, "*"); - return promise; + return invokeContentScript("signAndSendSwap", [tx_hex]); } public async signLoan(loan_response: any): Promise { - debug("Signing loan after user confirmation"); - let promise = new Promise((resolve, reject) => { - let listener = async function(event: MessageEvent>) { - if ( - event.data.direction === Direction.ToPage - ) { - if (event.data.kind === MessageKind.SignedLoan) { - if (event.data.error) { - reject(event.data.error); - } else { - debug(`Received signed loan: ${JSON.stringify(event.data)}`); - - window.removeEventListener("message", listener); - resolve(event.data.payload); - } - } else if (event.data.kind === MessageKind.LoanRejected) { - debug(`Loan rejected: ${JSON.stringify(event.data)}`); - - window.removeEventListener("message", listener); - reject("User rejected loan"); - } - } - }; - window.addEventListener("message", listener); - }); - window.postMessage({ - kind: MessageKind.SignLoan, - direction: Direction.ToBackground, - payload: loan_response, - }, "*"); - return promise; + return invokeContentScript("signLoan", [loan_response]); + } +} + +function invokeContentScript( + fn: R, + args: Parameters, +): Promise> { + let request = new Request(fn, args); + + debug(`Sending request for %s with %s`, fn, request.id); + + let promise = new Promise>((resolve, reject) => { + let listener = function(event: MessageEvent) { + if (!request.isRespondedToIn(event)) { + return; + } + + debug(`Received response for %s`, fn); + + if (event.data.err) { + reject(event.data.err); + } else if (event.data.ok) { + resolve(event.data.ok); + } else { + debug("Bad event! %s", JSON.stringify(event.data)); + + throw new Error("Invalid event format!"); + } + + window.removeEventListener("message", listener); + }; + + window.addEventListener("message", listener); + }); + + request.send(); + + return promise; +} + +class Request { + readonly id: string; + + constructor(readonly method: T, readonly args: Parameters) { + this.id = v4(); + } + + /** + * Checks if the given event is the response to this request. + * + * This uses TypeScript's Type Guards: https://www.typescripttutorial.net/typescript-tutorial/typescript-type-guards/ + */ + isRespondedToIn(event: MessageEvent): event is MessageEvent> { + return event.data.type === "response" && event.data.id === this.id; + } + + send() { + let message: RequestMessage = { + type: "request", + method: this.method, + args: this.args, + id: this.id, + }; + + window.postMessage(message, "*"); } } diff --git a/extension/src/messages.ts b/extension/src/messages.ts deleted file mode 100644 index 845b73271..000000000 --- a/extension/src/messages.ts +++ /dev/null @@ -1,30 +0,0 @@ -export enum MessageKind { - WalletStatusRequest = "WalletStatusRequest", - WalletStatusResponse = "WalletStatusResponse", - SellRequest = "SellRequest", - SellResponse = "SellResponse", - BuyRequest = "BuyRequest", - BuyResponse = "BuyResponse", - LoanRequest = "LoanRequest", - LoanResponse = "LoanResponse", // TODO: Choose a better name - SignAndSendSwap = "SignAndSendSwap", - SwapTxid = "SwapTxid", - AddressRequest = "AddressRequest", - AddressResponse = "AddressResponse", - SignLoan = "SignLoan", - SignedLoan = "SignedLoan", - LoanRejected = "LoanRejected", - SwapRejected = "SwapRejected", -} - -export enum Direction { - ToBackground = "ToBackground", - ToPage = "ToPage", -} - -export interface Message { - kind: MessageKind; - direction: Direction; - payload: T; - error: string | undefined; -} diff --git a/extension/src/models.ts b/extension/src/models.ts index a31d30081..e15c58810 100644 --- a/extension/src/models.ts +++ b/extension/src/models.ts @@ -43,7 +43,6 @@ export interface Trade { export interface SwapToSign { txHex: string; decoded: Trade; - tabId: number; } export interface LoanDetails { @@ -56,7 +55,6 @@ export interface LoanDetails { export interface LoanToSign { details: LoanDetails; - tabId: number; } export type Tx = string; diff --git a/extension/yarn.lock b/extension/yarn.lock index ed376c907..ee8a345d4 100644 --- a/extension/yarn.lock +++ b/extension/yarn.lock @@ -3324,10 +3324,12 @@ dependencies: "@babel/types" "^7.3.0" -"@types/debug@^4.1.5": - version "4.1.5" - resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.5.tgz#b14efa8852b7768d898906613c23f688713e02cd" - integrity sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ== +"@types/debug@^4.1.7": + version "4.1.7" + resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.7.tgz#7cc0ea761509124709b8b2d1090d8f6c17aadb82" + integrity sha512-9AonUzyTjXXhEOa0DnqpzZi6VHlqKMswga9EXjpXnnqxwLtdvPPtlO8evrI5D9S6asFRCQ6v+wpiUKbw+vKqyg== + dependencies: + "@types/ms" "*" "@types/eslint@^7.2.6": version "7.2.6" @@ -3442,6 +3444,11 @@ resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.4.tgz#f0ec25dbf2f0e4b18647313ac031134ca5b24b21" integrity sha512-1z8k4wzFnNjVK/tlxvrWuK5WMt6mydWWP7+zvH5eFep4oj+UkrfiJTRtjCeBXNpwaA/FYqqtb4/QS4ianFpIRA== +"@types/ms@*": + version "0.7.31" + resolved "https://registry.yarnpkg.com/@types/ms/-/ms-0.7.31.tgz#31b7ca6407128a3d2bbc27fe2d21b345397f6197" + integrity sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA== + "@types/node@*": version "14.14.31" resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.31.tgz#72286bd33d137aa0d152d47ec7c1762563d34055" @@ -3548,6 +3555,11 @@ dependencies: source-map "^0.6.1" +"@types/uuid@^8.3.1": + version "8.3.1" + resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.1.tgz#1a32969cf8f0364b3d8c8af9cc3555b7805df14f" + integrity sha512-Y2mHTRAbqfFkpjldbkHGY8JIzRN6XqYRliG8/24FcHm2D2PwW24fl5xMRTVGdrb7iMrwCaIEbLWerGIkXuFWVg== + "@types/warning@^3.0.0": version "3.0.0" resolved "https://registry.yarnpkg.com/@types/warning/-/warning-3.0.0.tgz#0d2501268ad8f9962b740d387c4654f5f8e23e52" @@ -14402,6 +14414,11 @@ type-fest@^0.8.1: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.8.1.tgz#09e249ebde851d3b1e48d27c105444667f17b83d" integrity sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA== +type-fest@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-2.0.0.tgz#e9daf5615e89f6d430f34117f88f4ee2cd5a2725" + integrity sha512-BoEUnckjP9oiudy3KxlGdudtBAdJQ74Wp7dYwVPkUzBn+cVHOsBXh2zD2jLyqgbuJ1KMNriczZCI7lTBA94dFg== + type-is@~1.6.17, type-is@~1.6.18: version "1.6.18" resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.18.tgz#4e552cd05df09467dcbc4ef739de89f2cf37c131" @@ -14685,7 +14702,7 @@ uuid@^3.3.2, uuid@^3.4.0: resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee" integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A== -uuid@^8.3.0: +uuid@^8.3.0, uuid@^8.3.2: version "8.3.2" resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==