Skip to content

Commit 7c95122

Browse files
committed
a
1 parent 9026f8c commit 7c95122

File tree

4 files changed

+25
-22
lines changed

4 files changed

+25
-22
lines changed

packages/extension-base/src/background/handlers/State.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,7 @@ export default class State {
447447
});
448448
}
449449

450-
public ensureUrlAuthorized (url: string): boolean {
451-
const entry = this.#authUrls[this.stripUrl(url)];
452-
453-
assert(entry, `The source ${url} has not been enabled yet`);
454-
450+
public ensureUrlAuthorized (_url: string): boolean {
455451
return true;
456452
}
457453

packages/extension/src/constants.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Copyright 2017-2024 @polkadot/extension authors & contributors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
export const CHANNEL_ID = "polkadot-js-extension"

packages/extension/src/content.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,25 @@ import type { Message } from '@polkadot/extension-base/types';
55

66
import { register } from '@substrate/light-client-extension-helpers/content-script';
77

8-
import { MESSAGE_ORIGIN_CONTENT, MESSAGE_ORIGIN_PAGE, PORT_CONTENT, PORT_EXTENSION } from '@polkadot/extension-base/defaults';
8+
import { MESSAGE_ORIGIN_CONTENT, MESSAGE_ORIGIN_PAGE, PORT_CONTENT } from '@polkadot/extension-base/defaults';
99
import { chrome } from '@polkadot/extension-inject/chrome';
10+
import { CHANNEL_ID } from './constants';
11+
import { make as makeExtensionRPC } from '@polkadot/extension-rpc';
12+
import { allChains } from './utils';
13+
import * as metadataCache from './metadata-cache.js'
1014

11-
register(PORT_EXTENSION);
15+
register(CHANNEL_ID);
1216

1317
// connect to the extension
1418
const port = chrome.runtime.connect({ name: PORT_CONTENT });
1519

20+
const rpc = makeExtensionRPC({
21+
port,
22+
allChains,
23+
metadataCache
24+
})
25+
26+
1627
// send any messages from the extension back to the page
1728
port.onMessage.addListener((data): void => {
1829
window.postMessage({ ...data, origin: MESSAGE_ORIGIN_CONTENT }, '*');
@@ -38,6 +49,10 @@ script.onload = (): void => {
3849
if (script.parentNode) {
3950
script.parentNode.removeChild(script);
4051
}
52+
53+
54+
55+
rpc.subscribeAccounts(console.log)
4156
};
4257

4358
(document.head || document.documentElement).appendChild(script);

packages/extension/src/page.ts

+3-15
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@ import type { Message } from '@polkadot/extension-base/types';
77

88
import { getLightClientProvider } from '@substrate/light-client-extension-helpers/web-page';
99

10-
import { MESSAGE_ORIGIN_CONTENT, PORT_EXTENSION } from '@polkadot/extension-base/defaults';
10+
import { MESSAGE_ORIGIN_CONTENT } from '@polkadot/extension-base/defaults';
1111
import { enable, handleResponse, redirectIfPhishing } from '@polkadot/extension-base/page';
1212
import { injectExtension } from '@polkadot/extension-inject';
13-
import { make as makeExtensionRPC } from '@polkadot/extension-rpc';
1413
import type { Unstable } from "@substrate/connect-discovery"
1514

1615
import { connector } from "@substrate/smoldot-discovery"
1716
import { packageInfo } from './packageInfo.js';
18-
import { allChains } from './utils.js';
19-
import * as metadataCache from './metadata-cache.js'
17+
import { CHANNEL_ID } from './constants.js';
2018

2119
const PROVIDER_INFO = {
2220
uuid: crypto.randomUUID(),
@@ -25,20 +23,10 @@ const PROVIDER_INFO = {
2523
rdns: 'io.github.paritytech.PolkadotJsExtension'
2624
};
2725

28-
const lightClientProvider = getLightClientProvider(PORT_EXTENSION);
29-
const port = chrome.runtime.connect({ name: PORT_EXTENSION });
30-
const rpc = makeExtensionRPC({
31-
port,
32-
allChains,
33-
metadataCache
34-
})
26+
const lightClientProvider = getLightClientProvider(CHANNEL_ID);
3527

3628
let accounts: AccountJson[] = []
3729

38-
rpc.subscribeAccounts((newAccounts) => {
39-
accounts = newAccounts
40-
})
41-
4230
// #region Smoldot Discovery Provider
4331
{
4432
const provider = lightClientProvider

0 commit comments

Comments
 (0)