Skip to content

Commit

Permalink
feat: improve ledger simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidsowardx committed May 26, 2023
1 parent 3913f8d commit 1c04f86
Show file tree
Hide file tree
Showing 5 changed files with 310 additions and 225 deletions.
1 change: 1 addition & 0 deletions src/chrome/background/ledger-tab-watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const LedgerTabWatcher = () => {
let tabId: number | undefined
let messageId: string | undefined
return {
getCurrentlyWatched: () => ({ tabId, messageId }),
setWatchedTab: (_tabId: number, _messageId: string) => {
tabId = _tabId
messageId = _messageId
Expand Down
12 changes: 11 additions & 1 deletion src/chrome/background/message-handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { closePopup as closePopupFn } from 'chrome/helpers/close-popup'
import { openParingPopup as openParingPopupFn } from 'chrome/helpers/open-pairing-popup'
import { errAsync, ResultAsync } from 'neverthrow'
import { errAsync, okAsync, ResultAsync } from 'neverthrow'
import { AppLogger } from 'utils/logger'
import {
messageDiscriminator,
Expand Down Expand Up @@ -85,6 +85,16 @@ export const BackgroundMessageHandler =
.mapErr(() => ({ reason: 'failedToOpenLedgerTab' }))
}

case messageDiscriminator.closeLedgerTab: {
const { tabId } = ledgerTabWatcher?.getCurrentlyWatched() ?? {}
ledgerTabWatcher?.restoreInitial()
return tabId
? ResultAsync.fromSafePromise(chrome.tabs.remove(tabId)).map(() => ({
sendConfirmation: false,
}))
: okAsync({ sendConfirmation: false })
}

case messageDiscriminator.walletToLedger:
ledgerTabWatcher?.restoreInitial()
return createAlignedPopupWindow(config.popup.pages.ledger)
Expand Down
Loading

0 comments on commit 1c04f86

Please sign in to comment.