Skip to content

Commit

Permalink
test undefined provider
Browse files Browse the repository at this point in the history
  • Loading branch information
jhesgodi committed Aug 16, 2024
1 parent 549a631 commit 7c8ed50
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,13 @@ export default function ConnectWidget({
}
}

sendConnectSuccessEvent(eventTarget, provider, walletProviderName ?? undefined, walletProviderInfo);
sendConnectSuccessEvent(
eventTarget,
provider,
walletProviderName ?? undefined,
walletProviderInfo,
'connect-widget-handleConnectSuccess',
);
}, [provider, identify]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,60 @@ export function sendConnectSuccessEvent(
provider: Web3Provider,
walletProviderName?: WalletProviderName,
walletProviderInfo?: EIP6963ProviderInfo,
id = 'some-id',
) {
const successEvent = new CustomEvent<WidgetEvent<WidgetType.CONNECT, ConnectEventType.SUCCESS>>(
IMTBLWidgetEvents.IMTBL_CONNECT_WIDGET_EVENT,
{
detail: {
type: ConnectEventType.SUCCESS,
data: {
provider,
walletProviderName,
walletProviderInfo,
},
const successEvent = new CustomEvent<
WidgetEvent<WidgetType.CONNECT, ConnectEventType.SUCCESS>
>(IMTBLWidgetEvents.IMTBL_CONNECT_WIDGET_EVENT, {
detail: {
type: ConnectEventType.SUCCESS,
data: {
provider,
walletProviderName,
walletProviderInfo,
},
},
);
});

if (provider === undefined) {
throw new Error(`-----> Provider is undefined ${id}`);
}

// eslint-disable-next-line no-console
console.log('success event:', eventTarget, successEvent);
console.log('-----> success event:', id, eventTarget, successEvent, {
provider,
});
if (eventTarget !== undefined) eventTarget.dispatchEvent(successEvent);
}

export function sendCloseWidgetEvent(eventTarget: Window | EventTarget) {
const closeWidgetEvent = new CustomEvent<WidgetEvent<WidgetType.CONNECT, ConnectEventType.CLOSE_WIDGET>>(
IMTBLWidgetEvents.IMTBL_CONNECT_WIDGET_EVENT,
{
detail: {
type: ConnectEventType.CLOSE_WIDGET,
data: {},
},
const closeWidgetEvent = new CustomEvent<
WidgetEvent<WidgetType.CONNECT, ConnectEventType.CLOSE_WIDGET>
>(IMTBLWidgetEvents.IMTBL_CONNECT_WIDGET_EVENT, {
detail: {
type: ConnectEventType.CLOSE_WIDGET,
data: {},
},
);
});
// eslint-disable-next-line no-console
console.log('close event:', eventTarget, closeWidgetEvent);
if (eventTarget !== undefined) eventTarget.dispatchEvent(closeWidgetEvent);
}

export function sendConnectFailedEvent(eventTarget: Window | EventTarget, reason: string) {
const failedEvent = new CustomEvent<WidgetEvent<WidgetType.CONNECT, ConnectEventType.FAILURE>>(
IMTBLWidgetEvents.IMTBL_CONNECT_WIDGET_EVENT,
{
detail: {
type: ConnectEventType.FAILURE,
data: {
reason,
},
export function sendConnectFailedEvent(
eventTarget: Window | EventTarget,
reason: string,
) {
const failedEvent = new CustomEvent<
WidgetEvent<WidgetType.CONNECT, ConnectEventType.FAILURE>
>(IMTBLWidgetEvents.IMTBL_CONNECT_WIDGET_EVENT, {
detail: {
type: ConnectEventType.FAILURE,
data: {
reason,
},
},
);
});
// eslint-disable-next-line no-console
console.log('failed event:', eventTarget, failedEvent);
if (eventTarget !== undefined) eventTarget.dispatchEvent(failedEvent);
Expand All @@ -73,18 +81,18 @@ export function sendWalletConnectProviderUpdatedEvent(
walletConnectManager: WalletConnectManager,
) {
const successEvent = new CustomEvent<
WidgetEvent<WidgetType.CONNECT, ConnectEventType.WALLETCONNECT_PROVIDER_UPDATED>
>(
IMTBLWidgetEvents.IMTBL_CONNECT_WIDGET_EVENT,
{
detail: {
type: ConnectEventType.WALLETCONNECT_PROVIDER_UPDATED,
data: {
ethereumProvider,
walletConnectManager,
},
WidgetEvent<
WidgetType.CONNECT,
ConnectEventType.WALLETCONNECT_PROVIDER_UPDATED
>
>(IMTBLWidgetEvents.IMTBL_CONNECT_WIDGET_EVENT, {
detail: {
type: ConnectEventType.WALLETCONNECT_PROVIDER_UPDATED,
data: {
ethereumProvider,
walletConnectManager,
},
},
);
});
if (eventTarget !== undefined) eventTarget.dispatchEvent(successEvent);
}

0 comments on commit 7c8ed50

Please sign in to comment.