Skip to content

Commit

Permalink
Merge pull request #458 from torusresearch/fix/bc-issue
Browse files Browse the repository at this point in the history
fix: broadcast channel
  • Loading branch information
guru-web3 authored Dec 2, 2024
2 parents 44e3ce9 + 3b28f67 commit 35a31d9
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 20 deletions.
9 changes: 9 additions & 0 deletions src/globalValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { broadcastChannelOptions } from "@toruslabs/base-controllers";
import { MethodType } from "@toruslabs/broadcast-channel";

(
broadcastChannelOptions as {
type?: MethodType;
webWorkerSupport: boolean;
}
).type = undefined;
3 changes: 3 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// eslint-disable-next-line
import "@/globalValue";

import "@/main.css";

import { createGtm } from "@gtm-support/vue-gtm";
Expand Down
21 changes: 12 additions & 9 deletions src/modules/controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
BillboardEvent,
BROADCAST_CHANNELS,
BROADCAST_CHANNELS_MSGS,
broadcastChannelOptions,
Contact,
ContactPayload,
DEFAULT_PREFERENCES,
Expand Down Expand Up @@ -391,9 +392,10 @@ class ControllerModule extends VuexModule {
public async changeTheme(theme: "light" | "dark") {
const instanceId = new URLSearchParams(window.location.search).get("instanceId");
if (instanceId) {
const themeChannel = new BroadcastChannel<PopupData<ThemeChannelData>>(`${BROADCAST_CHANNELS.THEME_CHANGE}_${instanceId}`, {
webWorkerSupport: false,
});
const themeChannel = new BroadcastChannel<PopupData<ThemeChannelData>>(
`${BROADCAST_CHANNELS.THEME_CHANGE}_${instanceId}`,
broadcastChannelOptions
);
themeChannel.postMessage({
data: {
type: BROADCAST_CHANNELS_MSGS.SET_THEME,
Expand Down Expand Up @@ -558,9 +560,10 @@ class ControllerModule extends VuexModule {
torus.setOrigin(origin);
const instanceId = new URLSearchParams(window.location.search).get("instanceId");
if (instanceId) {
const logoutChannel = new BroadcastChannel<PopupData<BasePopupChannelData>>(`${BROADCAST_CHANNELS.WALLET_LOGOUT_CHANNEL}_${instanceId}`, {
webWorkerSupport: false,
});
const logoutChannel = new BroadcastChannel<PopupData<BasePopupChannelData>>(
`${BROADCAST_CHANNELS.WALLET_LOGOUT_CHANNEL}_${instanceId}`,
broadcastChannelOptions
);
logoutChannel.postMessage({
data: {
type: BROADCAST_CHANNELS_MSGS.LOGOUT,
Expand All @@ -586,7 +589,7 @@ class ControllerModule extends VuexModule {
if (instanceId) {
const networkChangeChannel = new BroadcastChannel<PopupData<NetworkChangeChannelData>>(
`${BROADCAST_CHANNELS.WALLET_NETWORK_CHANGE_CHANNEL}_${instanceId}`,
{ webWorkerSupport: false }
broadcastChannelOptions
);
networkChangeChannel.postMessage({
data: {
Expand All @@ -607,7 +610,7 @@ class ControllerModule extends VuexModule {
if (instanceId) {
const accountImportChannel = new BroadcastChannel<PopupData<AccountImportedChannelData>>(
`${BROADCAST_CHANNELS.WALLET_ACCOUNT_IMPORT_CHANNEL}_${instanceId}`,
{ webWorkerSupport: false }
broadcastChannelOptions
);
accountImportChannel.postMessage({
data: {
Expand Down Expand Up @@ -637,7 +640,7 @@ class ControllerModule extends VuexModule {
if (instanceId) {
const selectedAddressChannel = new BroadcastChannel<PopupData<SelectedAddresssChangeChannelData>>(
`${BROADCAST_CHANNELS.WALLET_SELECTED_ADDRESS_CHANNEL}_${instanceId}`,
{ webWorkerSupport: false }
broadcastChannelOptions
);
selectedAddressChannel.postMessage({
data: {
Expand Down
6 changes: 3 additions & 3 deletions src/pages/Confirm.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { clusterApiUrl, Connection, TransactionMessage, VersionedMessage, VersionedTransaction } from "@solana/web3.js";
import { BROADCAST_CHANNELS, BroadcastChannelHandler, POPUP_RESULT } from "@toruslabs/base-controllers";
import { BROADCAST_CHANNELS, BroadcastChannelHandler, broadcastChannelOptions, POPUP_RESULT } from "@toruslabs/base-controllers";
import { BroadcastChannel } from "@toruslabs/broadcast-channel";
import log from "loglevel";
import { onErrorCaptured, onMounted, ref } from "vue";
Expand Down Expand Up @@ -84,7 +84,7 @@ onMounted(async () => {
const approveTxn = async (): Promise<void> => {
loading.value = true;
const bc = new BroadcastChannel(channel, { webWorkerSupport: false });
const bc = new BroadcastChannel(channel, broadcastChannelOptions);
await bc.postMessage({
data: { type: POPUP_RESULT, approve: true },
});
Expand All @@ -93,7 +93,7 @@ const approveTxn = async (): Promise<void> => {
const closeModal = async () => {
loading.value = true;
const bc = new BroadcastChannel(channel, { webWorkerSupport: false });
const bc = new BroadcastChannel(channel, broadcastChannelOptions);
await bc.postMessage({ data: { type: POPUP_RESULT, approve: false } });
bc.close();
};
Expand Down
6 changes: 3 additions & 3 deletions src/pages/ConfirmMessage.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { BROADCAST_CHANNELS, BroadcastChannelHandler, POPUP_RESULT } from "@toruslabs/base-controllers";
import { BROADCAST_CHANNELS, BroadcastChannelHandler, broadcastChannelOptions, POPUP_RESULT } from "@toruslabs/base-controllers";
import { BroadcastChannel } from "@toruslabs/broadcast-channel";
import log from "loglevel";
import { onErrorCaptured, onMounted, reactive, ref } from "vue";
Expand Down Expand Up @@ -44,7 +44,7 @@ onMounted(async () => {
const approveTxn = async (): Promise<void> => {
loading.value = true;
const bc = new BroadcastChannel(channel, { webWorkerSupport: false });
const bc = new BroadcastChannel(channel, broadcastChannelOptions);
await bc.postMessage({
data: { type: POPUP_RESULT, approve: true },
});
Expand All @@ -53,7 +53,7 @@ const approveTxn = async (): Promise<void> => {
const closeModal = async () => {
loading.value = true;
const bc = new BroadcastChannel(channel, { webWorkerSupport: false });
const bc = new BroadcastChannel(channel, broadcastChannelOptions);
await bc.postMessage({ data: { type: POPUP_RESULT, approve: false } });
bc.close();
};
Expand Down
4 changes: 2 additions & 2 deletions src/pages/End.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { Keypair } from "@solana/web3.js";
import { PopupData } from "@toruslabs/base-controllers";
import { broadcastChannelOptions, PopupData } from "@toruslabs/base-controllers";
import { BroadcastChannel } from "@toruslabs/broadcast-channel";
import { get } from "@toruslabs/http-helpers";
import { getED25519Key } from "@toruslabs/openlogin-ed25519";
Expand Down Expand Up @@ -45,7 +45,7 @@ const continueToApp = async (selectedIndex: number) => {
}
log.info(accounts);
const bc = new BroadcastChannel(channel, { webWorkerSupport: false });
const bc = new BroadcastChannel(channel, broadcastChannelOptions);
await bc.postMessage({
data: {
userInfo,
Expand Down
6 changes: 3 additions & 3 deletions src/pages/ProviderChange.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { BROADCAST_CHANNELS, BroadcastChannelHandler, POPUP_RESULT, PopupWhitelabelData } from "@toruslabs/base-controllers";
import { BROADCAST_CHANNELS, BroadcastChannelHandler, broadcastChannelOptions, POPUP_RESULT, PopupWhitelabelData } from "@toruslabs/base-controllers";
import { BroadcastChannel } from "@toruslabs/broadcast-channel";
import { onErrorCaptured, onMounted, reactive, ref } from "vue";
Expand Down Expand Up @@ -44,7 +44,7 @@ onMounted(async () => {
const approveProviderChange = async (): Promise<void> => {
loading.value = true;
const bc = new BroadcastChannel(channel, { webWorkerSupport: false });
const bc = new BroadcastChannel(channel, broadcastChannelOptions);
await bc.postMessage({
data: { type: POPUP_RESULT, approve: true },
});
Expand All @@ -53,7 +53,7 @@ const approveProviderChange = async (): Promise<void> => {
const denyProviderChange = async () => {
loading.value = true;
const bc = new BroadcastChannel(channel, { webWorkerSupport: false });
const bc = new BroadcastChannel(channel, broadcastChannelOptions);
await bc.postMessage({ data: { type: POPUP_RESULT, approve: false } });
bc.close();
};
Expand Down

0 comments on commit 35a31d9

Please sign in to comment.