-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: open ledger popup window * feat: refactor ledger wrapper methods * feat: trigger ledger command automatically * feat: add auth challenge ledger signing flow
- Loading branch information
1 parent
dd8c1a6
commit f3fdfe2
Showing
25 changed files
with
676 additions
and
249 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,31 @@ | ||
import { createMessage } from 'chrome/messages/create-message' | ||
import { sendMessage } from 'chrome/messages/send-message' | ||
|
||
export const LedgerTabWatcher = () => { | ||
let tabId: number | undefined | ||
let messageId: string | undefined | ||
return { | ||
setWatchedTab: (_tabId: number, _messageId: string) => { | ||
tabId = _tabId | ||
messageId = _messageId | ||
}, | ||
triggerTabRemoval: (justRemovedTabId: number) => { | ||
if (!messageId || !tabId || justRemovedTabId !== tabId) { | ||
return | ||
} | ||
|
||
sendMessage( | ||
createMessage.confirmationError('ledger', messageId, { | ||
reason: 'tabClosed', | ||
}) | ||
) | ||
|
||
tabId = undefined | ||
messageId = undefined | ||
}, | ||
restoreInitial: () => { | ||
tabId = undefined | ||
messageId = undefined | ||
}, | ||
} | ||
} |
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
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,4 @@ | ||
import { createTab } from './create-tab' | ||
|
||
export const createAndFocusTab = (url: string) => | ||
createTab(url).map((tab) => chrome.tabs.update(tab.id!, { active: true })) |
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 |
---|---|---|
@@ -1,24 +1,12 @@ | ||
import { ResultAsync } from 'neverthrow' | ||
import { getExtensionTabsByUrl } from './get-extension-tabs-by-url' | ||
import { createTab } from './create-tab' | ||
|
||
export const createOrFocusTab = (url: string) => | ||
getExtensionTabsByUrl(url).andThen((tabs) => | ||
ResultAsync.fromSafePromise( | ||
tabs.length > 0 && tabs[0].id | ||
? chrome.tabs.update(tabs[0].id, { active: true }) | ||
: new Promise<chrome.tabs.Tab>((resolve) => { | ||
chrome.tabs.create({ url }, async (tab) => { | ||
const listener = ( | ||
tabId: number, | ||
info: chrome.tabs.TabChangeInfo | ||
) => { | ||
if (info.status === 'complete' && tabId === tab.id) { | ||
chrome.tabs.onUpdated.removeListener(listener) | ||
resolve(tab) | ||
} | ||
} | ||
chrome.tabs.onUpdated.addListener(listener) | ||
}) | ||
}) | ||
) | ||
tabs.length > 0 && tabs[0].id | ||
? ResultAsync.fromSafePromise( | ||
chrome.tabs.update(tabs[0].id, { active: true }) | ||
) | ||
: createTab(url) | ||
) |
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,16 @@ | ||
import { ResultAsync } from 'neverthrow' | ||
|
||
export const createTab = (url: string) => | ||
ResultAsync.fromSafePromise( | ||
new Promise<chrome.tabs.Tab>((resolve) => { | ||
chrome.tabs.create({ url }, async (tab) => { | ||
const listener = (tabId: number, info: chrome.tabs.TabChangeInfo) => { | ||
if (info.status === 'complete' && tabId === tab.id) { | ||
chrome.tabs.onUpdated.removeListener(listener) | ||
resolve(tab) | ||
} | ||
} | ||
chrome.tabs.onUpdated.addListener(listener) | ||
}) | ||
}) | ||
) |
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
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
Oops, something went wrong.