Skip to content

Commit

Permalink
Call with config
Browse files Browse the repository at this point in the history
  • Loading branch information
arhtudormorar committed Dec 5, 2024
1 parent d1b1d93 commit 1966b1b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 42 deletions.
4 changes: 1 addition & 3 deletions src/core/providers/DappProvider/helpers/logout/logout.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { getAddress } from 'core/methods/account/getAddress';
import { getProviderType } from 'core/providers/helpers/utils';
import {
IProvider,
ProviderTypeEnum
Expand Down Expand Up @@ -48,7 +47,6 @@ export async function logout({
}
}: IProviderLogout) {
let address = getAddress();
const providerType = getProviderType(provider);

if (options.shouldBroadcastLogoutAcrossTabs) {
broadcastLogoutAcrossTabs(address);
Expand All @@ -59,7 +57,7 @@ export async function logout({

if (
options.hasConsentPopup &&
providerType === ProviderTypeEnum.crossWindow
provider.getType() === ProviderTypeEnum.crossWindow
) {
(provider as unknown as CrossWindowProvider).setShouldShowConsentPopup(
true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Message, Address } from '@multiversx/sdk-core';
import { getAddress } from 'core/methods/account/getAddress';
import { getProviderType } from 'core/providers/helpers/utils';
import {
IProvider,
ProviderTypeEnum
Expand All @@ -22,7 +21,6 @@ export async function signMessage({
options
}: SignMessageType): Promise<Nullable<Message>> {
const address = getAddress();
const providerType = getProviderType(provider);

const messageToSign = new Message({
address: new Address(address),
Expand All @@ -31,7 +29,7 @@ export async function signMessage({

if (
options?.hasConsentPopup &&
providerType === ProviderTypeEnum.crossWindow
provider.getType() === ProviderTypeEnum.crossWindow
) {
(provider as unknown as CrossWindowProvider).setShouldShowConsentPopup(
true
Expand Down
9 changes: 5 additions & 4 deletions src/core/providers/ProviderFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export class ProviderFactory {
config: userConfig
}: IProviderFactory): Promise<DappProvider> {
let createdProvider: IProvider | null = null;
const { account, UI } = await getConfig(userConfig);
const config = await getConfig(userConfig);
const { account, UI } = config;

switch (type) {
case ProviderTypeEnum.extension: {
Expand Down Expand Up @@ -110,9 +111,9 @@ export class ProviderFactory {
}

default: {
this._customProviders.forEach((customProvider) => {
if (customProvider.name === type) {
createdProvider = customProvider.class;
this._customProviders.forEach(async (customProvider) => {
if (customProvider.name !== type) {
createdProvider = await customProvider.constructor(config);
createdProvider.getType = () => type;
}
});
Expand Down
30 changes: 0 additions & 30 deletions src/core/providers/helpers/utils.ts

This file was deleted.

7 changes: 5 additions & 2 deletions src/core/providers/types/providerFactory.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ export interface IProviderFactory {
config?: IProviderConfig;
}

export interface ICustomProvider {
export interface ICustomProvider<
T extends ProviderTypeEnum = ProviderTypeEnum
> {
name: string;
type: T[keyof T];
icon: string;
class: IProvider;
constructor: (config: IProviderConfig) => Promise<IProvider>;
}

0 comments on commit 1966b1b

Please sign in to comment.