-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…128) * feat: add method to check if global postage batch is enabled (#122) * test: add test for enabled global postage batch
- Loading branch information
1 parent
bbfd653
commit b56536f
Showing
11 changed files
with
139 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { InterceptorReqMessageFormat, ResponseMessageFormat } from '../../utils/message/message-handler' | ||
import { getItem } from '../../utils/storage' | ||
|
||
export class PostageBatchFeeder { | ||
constructor() { | ||
this.serveEvents() | ||
} | ||
serveEvents(): void { | ||
console.log('Register PostageBatchFeeder event listeners...') | ||
|
||
chrome.runtime.onMessage.addListener((message: InterceptorReqMessageFormat<string>, sender, sendResponse) => { | ||
if (message.key === 'isGlobalPostageBatchEnabled') { | ||
console.log('PostageBatchFeeder:isGlobalPostageBatchEnabled got aimed message from content script', message) | ||
|
||
const response: ResponseMessageFormat = { | ||
key: message.key, | ||
sender: 'background', | ||
target: 'content', | ||
} | ||
|
||
getItem('globalPostageBatch') | ||
.then(value => { | ||
response.answer = Boolean(value) | ||
}) | ||
.catch(e => { | ||
response.error = String(e) | ||
}) | ||
.finally(() => { | ||
sendResponse(response) | ||
}) | ||
|
||
return 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
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,12 +1,14 @@ | ||
import * as BzzLink from './bzz-link' | ||
import { localStorage } from './local-storage' | ||
import { postageBatch } from './postage-batch' | ||
import { web2HelperContent } from './web2-helper.content' | ||
|
||
window.swarm = { | ||
...window.swarm, | ||
web2Helper: web2HelperContent, | ||
localStorage, | ||
bzzLink: BzzLink, | ||
postageBatch: postageBatch, | ||
} | ||
|
||
console.log('window.swarm has been inited') |
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,22 @@ | ||
import { nanoid } from 'nanoid' | ||
import { InpageReqMessageFormat } from '../../utils/message/message-handler' | ||
import { PostageBatchMessage } from '../../utils/message/postage-batch/postage-batch.message' | ||
import { MessengerInpage } from './messenger.inpage' | ||
|
||
export class PostageBatch extends MessengerInpage implements PostageBatchMessage { | ||
/** | ||
* Checks whether the global postage batch is enabled or not | ||
*/ | ||
public isGlobalPostageBatchEnabled(): Promise<string> { | ||
const message: InpageReqMessageFormat<undefined> = { | ||
key: 'isGlobalPostageBatchEnabled', | ||
eventId: nanoid(), | ||
sender: 'inpage', | ||
target: 'content', | ||
} | ||
|
||
return this.messageHandler(message, 'PostageBatch') | ||
} | ||
} | ||
|
||
export const postageBatch = new PostageBatch() |
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,3 @@ | ||
export interface PostageBatchMessage { | ||
isGlobalPostageBatchEnabled(): Promise<string> | ||
} |
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