From b64dcad16cbfd060571e5c42203956a42be85107 Mon Sep 17 00:00:00 2001 From: cipriandraghici Date: Wed, 24 Jul 2024 16:36:20 +0300 Subject: [PATCH 01/15] implement generic login and finalize the login with extension provider --- src/core/ProviderFactory.ts | 72 +++++++++++++------ .../login/helpers/resolveLoginMethod.ts | 25 +++++++ src/core/methods/login/login.ts | 60 ++++++++++++++++ src/core/methods/login/webWalletLogin.ts | 2 +- src/core/providers/accountProvider.ts | 8 +-- src/core/providers/helpers/emptyProvider.ts | 29 +++++--- src/types/dappProvider.types.ts | 32 --------- src/types/index.ts | 3 +- 8 files changed, 160 insertions(+), 71 deletions(-) create mode 100644 src/core/methods/login/helpers/resolveLoginMethod.ts create mode 100644 src/core/methods/login/login.ts delete mode 100644 src/types/dappProvider.types.ts diff --git a/src/core/ProviderFactory.ts b/src/core/ProviderFactory.ts index 66791cab..1e9cd20d 100644 --- a/src/core/ProviderFactory.ts +++ b/src/core/ProviderFactory.ts @@ -1,12 +1,22 @@ import { Transaction } from '@multiversx/sdk-core'; import { CrossWindowProvider } from 'lib/sdkWebWalletCrossWindowProvider'; +import { ExtensionProvider } from '@multiversx/sdk-extension-provider/out'; export interface IProvider { - login: (options?: { token?: string }) => Promise; + init: () => Promise; + login: (options?: { token?: string }) => Promise<{ + address: string; + signature: string; + nativeToken: string; + [key: string]: unknown; + }>; + relogin?: () => Promise; logout: () => Promise; signTransactions: (transaction: Transaction[]) => Promise; setAddress: (address: string) => IProvider; setShouldShowConsentPopup?: (shouldShow: boolean) => void; + getAddress(): string | undefined; + getSignature(): string | undefined; } export interface IProviderConfig { network: { @@ -25,18 +35,21 @@ export interface IProviderRecreateFactory extends IProviderFactory { export enum ProviderTypeEnum { iframe = 'iframe', - crossWindow = 'crossWindow' + crossWindow = 'crossWindow', + extension = 'extension', + walletConnect = 'walletConnect', + hardware = 'hardware', + opera = 'opera', + metamask = 'metamask', + wallet = 'wallet', } export class ProviderFactory { - public static async create({ + public async create({ type, - config: { - network: { walletAddress } - }, - address - }: IProviderFactory): Promise { - let createdProvider: IProvider; + config, + }: IProviderFactory): Promise { + let createdProvider: IProvider | undefined = undefined; switch (type) { // case ProviderTypeEnum.iframe: { @@ -47,24 +60,34 @@ export class ProviderFactory { // break; // } - case ProviderTypeEnum.crossWindow: { - const provider = await ProviderFactory.getCrossWindowProvider({ - walletAddress - }); + case ProviderTypeEnum.extension: { + const provider = await this.getExtensionProvider(); createdProvider = provider as unknown as IProvider; + + createdProvider.getAddress = () => { + return provider.account.address; + } + + createdProvider.getSignature = () => { + return provider.account.signature; + } + break; } - default: - const provider = await ProviderFactory.getCrossWindowProvider({ + case ProviderTypeEnum.crossWindow: { + const { walletAddress } = config.network; + + const provider = await this.getCrossWindowProvider({ walletAddress }); createdProvider = provider as unknown as IProvider; + break; - } + } - if (address) { - createdProvider.setAddress(address); + default: + break; } return createdProvider; @@ -72,11 +95,12 @@ export class ProviderFactory { public static async reCreate( config: IProviderRecreateFactory - ): Promise { - return await ProviderFactory.create(config); + ): Promise { + const factory = new ProviderFactory(); + return await factory.create(config); } - private static async getCrossWindowProvider({ + private async getCrossWindowProvider({ walletAddress }: Partial) { // CrossWindowProvider.getInstance().clearInstance(); @@ -85,4 +109,10 @@ export class ProviderFactory { provider.setWalletUrl(String(walletAddress)); return provider; } + + private async getExtensionProvider() { + const provider = ExtensionProvider.getInstance(); + await provider.init(); + return provider; + } } diff --git a/src/core/methods/login/helpers/resolveLoginMethod.ts b/src/core/methods/login/helpers/resolveLoginMethod.ts new file mode 100644 index 00000000..7b97f652 --- /dev/null +++ b/src/core/methods/login/helpers/resolveLoginMethod.ts @@ -0,0 +1,25 @@ +import { ProviderTypeEnum } from 'core/ProviderFactory'; +import { LoginMethodsEnum } from 'types/enums.types'; + +export function resolveLoginMethod(providerType: ProviderTypeEnum) { + switch (providerType) { + case ProviderTypeEnum.iframe: + return LoginMethodsEnum.extra; + case ProviderTypeEnum.extension: + return LoginMethodsEnum.extension; + case ProviderTypeEnum.crossWindow: + return LoginMethodsEnum.crossWindow; + case ProviderTypeEnum.hardware: + return LoginMethodsEnum.ledger; + case ProviderTypeEnum.metamask: + return LoginMethodsEnum.metamask; + case ProviderTypeEnum.walletConnect: + return LoginMethodsEnum.walletconnectv2; + case ProviderTypeEnum.wallet: + return LoginMethodsEnum.wallet; + case ProviderTypeEnum.opera: + return LoginMethodsEnum.opera; + default: + return LoginMethodsEnum.none; + } +} \ No newline at end of file diff --git a/src/core/methods/login/login.ts b/src/core/methods/login/login.ts new file mode 100644 index 00000000..eeb048f6 --- /dev/null +++ b/src/core/methods/login/login.ts @@ -0,0 +1,60 @@ +import { IProviderFactory, ProviderFactory } from 'core/ProviderFactory'; +import { NativeAuthConfigType } from 'types/nativeAuth.types'; +import { nativeAuth } from 'services/nativeAuth'; +import { setAddress } from 'store/actions/account'; +import { setLoginMethod, setTokenLogin } from 'store/actions/loginInfo/loginInfoActions'; +import { resolveLoginMethod } from './helpers/resolveLoginMethod'; +import { setAccountProvider } from '../../providers/accountProvider'; + +export const login = async (config: IProviderFactory, nativeAuthConfig?: NativeAuthConfigType) => { + const factory = new ProviderFactory(); + const provider = await factory.create(config); + + if(!provider) { + throw new Error('Provider not found'); + } + + await provider.init?.(); + + const nativeAuthClient = nativeAuth(nativeAuthConfig); + + const loginToken = await nativeAuthClient.initialize({ + noCache: true + }); + await provider.login({ token: loginToken }); + + const address = provider.getAddress?.(); + const signature = provider.getSignature?.(); + + if(!address) { + throw new Error('Address not found'); + } + + if(!signature) { + throw new Error('Signature not found'); + } + + const nativeAuthToken = nativeAuthClient.getToken({ + address, + token: loginToken, + signature + }); + + setAccountProvider(provider); + setAddress(address); + setTokenLogin({ + loginToken, + signature, + nativeAuthToken, + nativeAuthConfig + }); + setLoginMethod(resolveLoginMethod(config.type)) + + return { + address, + signature, + nativeAuthToken, + loginToken, + nativeAuthConfig + } +} \ No newline at end of file diff --git a/src/core/methods/login/webWalletLogin.ts b/src/core/methods/login/webWalletLogin.ts index 8875f0ea..26f55019 100644 --- a/src/core/methods/login/webWalletLogin.ts +++ b/src/core/methods/login/webWalletLogin.ts @@ -112,7 +112,7 @@ export const webWalletLogin = async ({ return newAccount; } catch (error) { - console.error('error loging in', error); + console.error('error logging in', error); throw error; } }; diff --git a/src/core/providers/accountProvider.ts b/src/core/providers/accountProvider.ts index 44f1ba10..cb4421d6 100644 --- a/src/core/providers/accountProvider.ts +++ b/src/core/providers/accountProvider.ts @@ -1,8 +1,8 @@ -import { IDappProvider } from 'types/dappProvider.types'; import { emptyProvider } from './helpers/emptyProvider'; import { CrossWindowProvider } from 'lib/sdkWebWalletCrossWindowProvider'; +import { IProvider } from 'core/ProviderFactory'; -export type ProvidersType = IDappProvider | CrossWindowProvider; +export type ProvidersType = IProvider | CrossWindowProvider; let accountProvider: ProvidersType = emptyProvider; @@ -12,6 +12,6 @@ export function setAccountProvider( accountProvider = provider; } -export function getAccountProvider(): IDappProvider { - return (accountProvider as IDappProvider) || emptyProvider; +export function getAccountProvider(): IProvider { + return (accountProvider as IProvider) || emptyProvider; } diff --git a/src/core/providers/helpers/emptyProvider.ts b/src/core/providers/helpers/emptyProvider.ts index 45116027..bd1c1098 100644 --- a/src/core/providers/helpers/emptyProvider.ts +++ b/src/core/providers/helpers/emptyProvider.ts @@ -1,6 +1,6 @@ import { SignableMessage, Transaction } from '@multiversx/sdk-core'; -import { IDappProvider } from 'types'; import { EngineTypes } from 'utils/walletconnect/__sdkWalletconnectProvider'; +import { IProvider } from 'core/ProviderFactory'; export const DAPP_INIT_ROUTE = '/dapp/init'; @@ -8,7 +8,7 @@ const notInitializedError = (caller: string) => { return `Unable to perform ${caller}, Provider not initialized`; }; -export class EmptyProvider implements IDappProvider { +export class EmptyProvider implements IProvider { init(): Promise { return Promise.resolve(false); } @@ -25,10 +25,6 @@ export class EmptyProvider implements IDappProvider { throw new Error(notInitializedError(`logout with options: ${options}`)); } - getAddress(): Promise { - throw new Error(notInitializedError('getAddress')); - } - isInitialized(): boolean { return false; } @@ -59,13 +55,12 @@ export class EmptyProvider implements IDappProvider { ); } - signTransactions( - transactions: [], - options?: TOptions - ): Promise { + signTransactions( + transactions: T[] + ): Promise { throw new Error( notInitializedError( - `signTransactions with transactions: ${transactions} options: ${options}` + `signTransactions with transactions: ${transactions}` ) ); } @@ -106,6 +101,18 @@ export class EmptyProvider implements IDappProvider { ping?(): Promise { return Promise.resolve(false); } + + setAddress(address: string): IProvider { + throw new Error(notInitializedError(`setAddress with address: ${address}`)); + } + + getAddress(): string | undefined { + throw new Error(notInitializedError('getAddress')); + } + + getSignature(): string | undefined { + throw new Error(notInitializedError(`getSignature`)); + } } export const emptyProvider = new EmptyProvider(); diff --git a/src/types/dappProvider.types.ts b/src/types/dappProvider.types.ts deleted file mode 100644 index 7260263f..00000000 --- a/src/types/dappProvider.types.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { Transaction } from '@multiversx/sdk-core'; -import type { IDAppProviderBase } from '@multiversx/sdk-dapp-utils/out/models/dappProviderBase'; -import { EngineTypes } from 'utils/walletconnect/__sdkWalletconnectProvider'; -import { Nullable } from './misc.types'; - -export interface DappOptions { - callbackUrl?: string; -} - -export interface IDappProvider extends IDAppProviderBase { - init?(): Promise; - getAddress(): Promise; - isInitialized(): boolean; - isConnected(): Promise; - sendTransaction?( - transaction: Transaction, - options?: DappOptions - ): Promise; - sendCustomMessage?({ - method, - params - }: { - method: string; - params: any; - }): Promise; - sendCustomRequest?(options?: { - request: EngineTypes.RequestParams['request']; - }): Promise; - ping?(): Promise; - relogin?: () => Promise>; - setShouldShowConsentPopup?: (shouldShow: boolean) => void; -} diff --git a/src/types/index.ts b/src/types/index.ts index a7a06d63..9d0a1f80 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,4 +1,3 @@ export * from './enums.types'; export * from './network.types'; -export * from './misc.types'; -export * from './dappProvider.types'; +export * from './misc.types'; \ No newline at end of file From 4869c426bab46efcadd20e69ce92e6eea0c3f268 Mon Sep 17 00:00:00 2001 From: cipriandraghici Date: Wed, 24 Jul 2024 23:30:43 +0300 Subject: [PATCH 02/15] refactoring --- src/core/ProviderFactory.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/core/ProviderFactory.ts b/src/core/ProviderFactory.ts index 1e9cd20d..259b9fe2 100644 --- a/src/core/ProviderFactory.ts +++ b/src/core/ProviderFactory.ts @@ -1,18 +1,12 @@ -import { Transaction } from '@multiversx/sdk-core'; import { CrossWindowProvider } from 'lib/sdkWebWalletCrossWindowProvider'; -import { ExtensionProvider } from '@multiversx/sdk-extension-provider/out'; +import { ExtensionProvider } from '@multiversx/sdk-extension-provider'; +import type { IDAppProviderBase } from '@multiversx/sdk-dapp-utils'; -export interface IProvider { +export interface IProvider extends IDAppProviderBase { init: () => Promise; - login: (options?: { token?: string }) => Promise<{ - address: string; - signature: string; - nativeToken: string; - [key: string]: unknown; - }>; + login: (options?: { token?: string }) => Promise; relogin?: () => Promise; logout: () => Promise; - signTransactions: (transaction: Transaction[]) => Promise; setAddress: (address: string) => IProvider; setShouldShowConsentPopup?: (shouldShow: boolean) => void; getAddress(): string | undefined; From 22edcb1c24c1d2b986f01aa687e3bcb2f043b1be Mon Sep 17 00:00:00 2001 From: cipriandraghici Date: Thu, 25 Jul 2024 10:12:37 +0300 Subject: [PATCH 03/15] refactoring --- src/core/methods/login/login.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/core/methods/login/login.ts b/src/core/methods/login/login.ts index eeb048f6..c4377655 100644 --- a/src/core/methods/login/login.ts +++ b/src/core/methods/login/login.ts @@ -4,11 +4,17 @@ import { nativeAuth } from 'services/nativeAuth'; import { setAddress } from 'store/actions/account'; import { setLoginMethod, setTokenLogin } from 'store/actions/loginInfo/loginInfoActions'; import { resolveLoginMethod } from './helpers/resolveLoginMethod'; -import { setAccountProvider } from '../../providers/accountProvider'; +import { setAccountProvider } from 'core/providers/accountProvider'; -export const login = async (config: IProviderFactory, nativeAuthConfig?: NativeAuthConfigType) => { +export const login = async ({ + providerConfig, + nativeAuthConfig +}: { + providerConfig: IProviderFactory, + nativeAuthConfig?: NativeAuthConfigType +}) => { const factory = new ProviderFactory(); - const provider = await factory.create(config); + const provider = await factory.create(providerConfig); if(!provider) { throw new Error('Provider not found'); @@ -48,7 +54,7 @@ export const login = async (config: IProviderFactory, nativeAuthConfig?: NativeA nativeAuthToken, nativeAuthConfig }); - setLoginMethod(resolveLoginMethod(config.type)) + setLoginMethod(resolveLoginMethod(providerConfig.type)) return { address, From 0c0b7c5f3f5e839f4ef879434941e1d2f218950d Mon Sep 17 00:00:00 2001 From: cipriandraghici Date: Thu, 25 Jul 2024 12:02:32 +0300 Subject: [PATCH 04/15] refactoring around provider type and login methods --- src/core/ProviderFactory.ts | 45 ++++++++----------- .../login/helpers/resolveLoginMethod.ts | 25 ----------- src/core/methods/login/login.ts | 5 +-- src/core/methods/logout/logout.ts | 6 --- src/core/providers/helpers/emptyProvider.ts | 2 +- src/core/providers/helpers/utils.ts | 13 +++--- .../actions/loginInfo/loginInfoActions.ts | 4 +- .../actions/sharedActions/sharedActions.ts | 4 +- src/store/slices/loginInfo/loginInfo.types.ts | 4 +- src/types/enums.types.ts | 26 ++++++----- 10 files changed, 48 insertions(+), 86 deletions(-) delete mode 100644 src/core/methods/login/helpers/resolveLoginMethod.ts diff --git a/src/core/ProviderFactory.ts b/src/core/ProviderFactory.ts index 259b9fe2..3c5960c6 100644 --- a/src/core/ProviderFactory.ts +++ b/src/core/ProviderFactory.ts @@ -1,47 +1,42 @@ import { CrossWindowProvider } from 'lib/sdkWebWalletCrossWindowProvider'; import { ExtensionProvider } from '@multiversx/sdk-extension-provider'; import type { IDAppProviderBase } from '@multiversx/sdk-dapp-utils'; +import { LoginMethodsType, LoginMethodsEnum } from '../types'; export interface IProvider extends IDAppProviderBase { init: () => Promise; + // TODO change return type to { address: string, signature: string } and also change the return type in IDAppProviderBase. login: (options?: { token?: string }) => Promise; - relogin?: () => Promise; logout: () => Promise; setAddress: (address: string) => IProvider; setShouldShowConsentPopup?: (shouldShow: boolean) => void; getAddress(): string | undefined; - getSignature(): string | undefined; + getTokenLoginSignature(): string | undefined; } + export interface IProviderConfig { network: { walletAddress: string; }; } + +export type ProviderType = LoginMethodsType; + export interface IProviderFactory { - type: ProviderTypeEnum; + type: ProviderType; config: IProviderConfig; - address?: string; + customProvider?: IProvider; } -export interface IProviderRecreateFactory extends IProviderFactory { - address: string; -} - -export enum ProviderTypeEnum { - iframe = 'iframe', - crossWindow = 'crossWindow', - extension = 'extension', - walletConnect = 'walletConnect', - hardware = 'hardware', - opera = 'opera', - metamask = 'metamask', - wallet = 'wallet', -} +export const ProviderTypeEnum = { + ...LoginMethodsEnum +} as const; export class ProviderFactory { public async create({ type, config, + customProvider }: IProviderFactory): Promise { let createdProvider: IProvider | undefined = undefined; @@ -62,7 +57,7 @@ export class ProviderFactory { return provider.account.address; } - createdProvider.getSignature = () => { + createdProvider.getTokenLoginSignature = () => { return provider.account.signature; } @@ -80,6 +75,11 @@ export class ProviderFactory { break; } + case ProviderTypeEnum.custom: { + createdProvider = customProvider; + break; + } + default: break; } @@ -87,13 +87,6 @@ export class ProviderFactory { return createdProvider; } - public static async reCreate( - config: IProviderRecreateFactory - ): Promise { - const factory = new ProviderFactory(); - return await factory.create(config); - } - private async getCrossWindowProvider({ walletAddress }: Partial) { diff --git a/src/core/methods/login/helpers/resolveLoginMethod.ts b/src/core/methods/login/helpers/resolveLoginMethod.ts deleted file mode 100644 index 7b97f652..00000000 --- a/src/core/methods/login/helpers/resolveLoginMethod.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { ProviderTypeEnum } from 'core/ProviderFactory'; -import { LoginMethodsEnum } from 'types/enums.types'; - -export function resolveLoginMethod(providerType: ProviderTypeEnum) { - switch (providerType) { - case ProviderTypeEnum.iframe: - return LoginMethodsEnum.extra; - case ProviderTypeEnum.extension: - return LoginMethodsEnum.extension; - case ProviderTypeEnum.crossWindow: - return LoginMethodsEnum.crossWindow; - case ProviderTypeEnum.hardware: - return LoginMethodsEnum.ledger; - case ProviderTypeEnum.metamask: - return LoginMethodsEnum.metamask; - case ProviderTypeEnum.walletConnect: - return LoginMethodsEnum.walletconnectv2; - case ProviderTypeEnum.wallet: - return LoginMethodsEnum.wallet; - case ProviderTypeEnum.opera: - return LoginMethodsEnum.opera; - default: - return LoginMethodsEnum.none; - } -} \ No newline at end of file diff --git a/src/core/methods/login/login.ts b/src/core/methods/login/login.ts index c4377655..732814b4 100644 --- a/src/core/methods/login/login.ts +++ b/src/core/methods/login/login.ts @@ -3,7 +3,6 @@ import { NativeAuthConfigType } from 'types/nativeAuth.types'; import { nativeAuth } from 'services/nativeAuth'; import { setAddress } from 'store/actions/account'; import { setLoginMethod, setTokenLogin } from 'store/actions/loginInfo/loginInfoActions'; -import { resolveLoginMethod } from './helpers/resolveLoginMethod'; import { setAccountProvider } from 'core/providers/accountProvider'; export const login = async ({ @@ -30,7 +29,7 @@ export const login = async ({ await provider.login({ token: loginToken }); const address = provider.getAddress?.(); - const signature = provider.getSignature?.(); + const signature = provider.getTokenLoginSignature?.(); if(!address) { throw new Error('Address not found'); @@ -54,7 +53,7 @@ export const login = async ({ nativeAuthToken, nativeAuthConfig }); - setLoginMethod(resolveLoginMethod(providerConfig.type)) + setLoginMethod(providerConfig.type); return { address, diff --git a/src/core/methods/logout/logout.ts b/src/core/methods/logout/logout.ts index acfd0dbe..15ff992a 100644 --- a/src/core/methods/logout/logout.ts +++ b/src/core/methods/logout/logout.ts @@ -4,7 +4,6 @@ import { LoginMethodsEnum } from 'types'; import { getAddress } from '../account/getAddress'; import { CrossWindowProvider } from 'lib/sdkWebWalletCrossWindowProvider'; import { logoutAction } from 'store/actions/sharedActions/sharedActions'; -import { getWebviewToken } from '../account/getWebviewToken'; import { getAccountProvider } from 'core/providers/accountProvider'; import { getProviderType } from 'core/providers/helpers/utils'; @@ -35,7 +34,6 @@ export type LogoutPropsType = { }; export async function logout( - shouldAttemptReLogin = Boolean(getWebviewToken()), options = { shouldBroadcastLogoutAcrossTabs: true, hasConsentPopup: false @@ -45,10 +43,6 @@ export async function logout( const provider = getAccountProvider(); const providerType = getProviderType(provider); - if (shouldAttemptReLogin && provider?.relogin != null) { - return provider.relogin(); - } - if (options.shouldBroadcastLogoutAcrossTabs) { broadcastLogoutAcrossTabs(address); } diff --git a/src/core/providers/helpers/emptyProvider.ts b/src/core/providers/helpers/emptyProvider.ts index bd1c1098..f1be7930 100644 --- a/src/core/providers/helpers/emptyProvider.ts +++ b/src/core/providers/helpers/emptyProvider.ts @@ -110,7 +110,7 @@ export class EmptyProvider implements IProvider { throw new Error(notInitializedError('getAddress')); } - getSignature(): string | undefined { + getTokenLoginSignature(): string | undefined { throw new Error(notInitializedError(`getSignature`)); } } diff --git a/src/core/providers/helpers/utils.ts b/src/core/providers/helpers/utils.ts index db824436..ea37aac9 100644 --- a/src/core/providers/helpers/utils.ts +++ b/src/core/providers/helpers/utils.ts @@ -3,21 +3,21 @@ import { HWProvider } from '@multiversx/sdk-hw-provider'; import { MetamaskProvider } from '@multiversx/sdk-metamask-provider/out/metamaskProvider'; import { OperaProvider } from '@multiversx/sdk-opera-provider'; import { WalletProvider } from '@multiversx/sdk-web-wallet-provider'; -import { LoginMethodsEnum } from 'types/enums.types'; +import { LoginMethodsType, LoginMethodsEnum } from 'types/enums.types'; import { WalletConnectV2Provider } from 'utils/walletconnect/__sdkWalletconnectProvider'; import { EmptyProvider } from './emptyProvider'; import { CrossWindowProvider } from 'lib/sdkWebWalletCrossWindowProvider'; export const getProviderType = ( provider?: TProvider | null -): LoginMethodsEnum => { +): LoginMethodsType => { switch (provider?.constructor) { case WalletProvider: - return LoginMethodsEnum.wallet; + return LoginMethodsEnum.webhook; case WalletConnectV2Provider: - return LoginMethodsEnum.walletconnectv2; + return LoginMethodsEnum.walletConnect; case HWProvider: - return LoginMethodsEnum.ledger; + return LoginMethodsEnum.hardware; case ExtensionProvider: return LoginMethodsEnum.extension; case MetamaskProvider: @@ -27,8 +27,7 @@ export const getProviderType = ( case CrossWindowProvider: return LoginMethodsEnum.crossWindow; case EmptyProvider: - return LoginMethodsEnum.none; default: - return LoginMethodsEnum.extra; + return LoginMethodsEnum.none; } }; diff --git a/src/store/actions/loginInfo/loginInfoActions.ts b/src/store/actions/loginInfo/loginInfoActions.ts index 71d6a4f2..64649397 100644 --- a/src/store/actions/loginInfo/loginInfoActions.ts +++ b/src/store/actions/loginInfo/loginInfoActions.ts @@ -1,4 +1,4 @@ -import { LoginMethodsEnum } from 'types/enums.types'; +import { LoginMethodsType } from 'types/enums.types'; import { TokenLoginType } from 'types/login.types'; import { LedgerLoginType, @@ -7,7 +7,7 @@ import { } from 'store/slices/loginInfo/loginInfo.types'; import { getStore } from 'store/store'; -export const setLoginMethod = (loginMethod: LoginMethodsEnum) => +export const setLoginMethod = (loginMethod: LoginMethodsType) => getStore().setState(({ loginInfo: state }) => { state.loginMethod = loginMethod; }); diff --git a/src/store/actions/sharedActions/sharedActions.ts b/src/store/actions/sharedActions/sharedActions.ts index a45bf3b4..49adeb1f 100644 --- a/src/store/actions/sharedActions/sharedActions.ts +++ b/src/store/actions/sharedActions/sharedActions.ts @@ -1,12 +1,12 @@ import { Address } from '@multiversx/sdk-core/out'; import { getStore } from '../../store'; -import { LoginMethodsEnum } from 'types/enums.types'; +import { LoginMethodsType } from 'types/enums.types'; import { resetStore } from 'store/middleware/logoutMiddleware'; export const logoutAction = () => getStore().setState(resetStore); export interface LoginActionPayloadType { address: string; - loginMethod: LoginMethodsEnum; + loginMethod: LoginMethodsType; } export const loginAction = ({ address, loginMethod }: LoginActionPayloadType) => diff --git a/src/store/slices/loginInfo/loginInfo.types.ts b/src/store/slices/loginInfo/loginInfo.types.ts index 42013066..4d1013c3 100644 --- a/src/store/slices/loginInfo/loginInfo.types.ts +++ b/src/store/slices/loginInfo/loginInfo.types.ts @@ -1,4 +1,4 @@ -import { LoginMethodsEnum } from 'types/enums.types'; +import { LoginMethodsEnum, LoginMethodsType } from 'types/enums.types'; import { TokenLoginType } from 'types/login.types'; export interface WalletConnectLoginType { @@ -18,7 +18,7 @@ export interface LoginInfoType { } export interface LoginInfoSliceType { - loginMethod: LoginMethodsEnum; + loginMethod: LoginMethodsType; walletConnectLogin: WalletConnectLoginType | null; ledgerLogin: LedgerLoginType | null; tokenLogin: TokenLoginType | null; diff --git a/src/types/enums.types.ts b/src/types/enums.types.ts index d3c01488..684dc622 100644 --- a/src/types/enums.types.ts +++ b/src/types/enums.types.ts @@ -4,18 +4,20 @@ export enum EnvironmentsEnum { mainnet = 'mainnet' } -export enum LoginMethodsEnum { - ledger = 'ledger', - walletconnect = 'walletconnect', - walletconnectv2 = 'walletconnectv2', - wallet = 'wallet', - crossWindow = 'crossWindow', - extension = 'extension', - metamask = 'metamask', - opera = 'opera', - extra = 'extra', - none = '' -} +export const LoginMethodsEnum = { + iframe: 'iframe', + crossWindow: 'crossWindow', + extension: 'extension', + walletConnect: 'walletConnect', + hardware: 'hardware', + opera: 'opera', + metamask: 'metamask', + webhook: 'webhook', + custom: "custom", + none: '' +} as const + +export type LoginMethodsType = typeof LoginMethodsEnum[keyof typeof LoginMethodsEnum]; export enum TypesOfSmartContractCallsEnum { MultiESDTNFTTransfer = 'MultiESDTNFTTransfer', From 6ec1ba6eff85f88c8db98a77324634d3c51b52e1 Mon Sep 17 00:00:00 2001 From: cipriandraghici Date: Thu, 25 Jul 2024 14:13:00 +0300 Subject: [PATCH 05/15] support for normal login and login with native token --- src/core/methods/login/login.ts | 62 +++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/src/core/methods/login/login.ts b/src/core/methods/login/login.ts index 732814b4..c36df2c3 100644 --- a/src/core/methods/login/login.ts +++ b/src/core/methods/login/login.ts @@ -1,31 +1,34 @@ -import { IProviderFactory, ProviderFactory } from 'core/ProviderFactory'; +import { IProvider, IProviderFactory, ProviderFactory } from 'core/ProviderFactory'; import { NativeAuthConfigType } from 'types/nativeAuth.types'; import { nativeAuth } from 'services/nativeAuth'; import { setAddress } from 'store/actions/account'; import { setLoginMethod, setTokenLogin } from 'store/actions/loginInfo/loginInfoActions'; import { setAccountProvider } from 'core/providers/accountProvider'; +import { getNativeAuthConfig } from 'services/nativeAuth/methods'; -export const login = async ({ - providerConfig, - nativeAuthConfig -}: { - providerConfig: IProviderFactory, - nativeAuthConfig?: NativeAuthConfigType -}) => { - const factory = new ProviderFactory(); - const provider = await factory.create(providerConfig); +async function normalLogin(provider: IProvider) { + await provider.login(); - if(!provider) { - throw new Error('Provider not found'); + const address = provider.getAddress?.(); + + if (!address) { + throw new Error('Address not found'); } - await provider.init?.(); + setAddress(address); + + return { + address + }; +} +async function loginWithNativeToken(provider: IProvider, nativeAuthConfig: NativeAuthConfigType) { const nativeAuthClient = nativeAuth(nativeAuthConfig); const loginToken = await nativeAuthClient.initialize({ noCache: true }); + await provider.login({ token: loginToken }); const address = provider.getAddress?.(); @@ -45,7 +48,6 @@ export const login = async ({ signature }); - setAccountProvider(provider); setAddress(address); setTokenLogin({ loginToken, @@ -53,7 +55,6 @@ export const login = async ({ nativeAuthToken, nativeAuthConfig }); - setLoginMethod(providerConfig.type); return { address, @@ -62,4 +63,35 @@ export const login = async ({ loginToken, nativeAuthConfig } +} + +export const login = async ({ + providerConfig, + withNativeAuth +}: { + providerConfig: IProviderFactory, + withNativeAuth?: boolean | NativeAuthConfigType, +}) => { + const factory = new ProviderFactory(); + const provider = await factory.create(providerConfig); + + if(!provider) { + throw new Error('Provider not found'); + } + + await provider.init?.(); + setAccountProvider(provider); + setLoginMethod(providerConfig.type); + + if(withNativeAuth) { + if(typeof withNativeAuth === 'boolean') { + withNativeAuth = getNativeAuthConfig(true); + } + + const nativeAuthConfig = withNativeAuth as NativeAuthConfigType; + + return await loginWithNativeToken(provider, nativeAuthConfig); + } else { + return await normalLogin(provider); + } } \ No newline at end of file From 3611c6442609f726d69f7f48c5d57bb12e358bfb Mon Sep 17 00:00:00 2001 From: cipriandraghici Date: Thu, 25 Jul 2024 16:26:53 +0300 Subject: [PATCH 06/15] refactoring, add initDapp function, set nativeAuthCofig at init --- esbuild.js | 7 +-- src/core/index.ts | 2 +- src/core/methods/init/init.ts | 30 +++++++++ .../methods/login/helpers/getLoginService.ts | 6 +- src/core/methods/login/login.ts | 62 ++++++++++++------- src/core/methods/login/webWalletLogin.ts | 4 +- src/core/methods/logout/logout.ts | 4 +- src/core/{ => providers}/ProviderFactory.ts | 41 +++--------- src/core/providers/accountProvider.ts | 2 +- src/core/providers/helpers/emptyProvider.ts | 10 +-- src/core/providers/helpers/utils.ts | 20 +++--- .../providers/types/providerFactory.types.ts | 38 ++++++++++++ ...AuthConfig.ts => buildNativeAuthConfig.ts} | 19 ++---- .../methods/getDefaultNativeAuthConfig.ts | 10 +++ src/services/nativeAuth/methods/index.ts | 2 +- src/services/nativeAuth/nativeAuth.ts | 7 +-- .../actions/loginInfo/loginInfoActions.ts | 21 ++++++- .../actions/sharedActions/sharedActions.ts | 11 ++-- src/store/slices/loginInfo/loginInfo.types.ts | 4 +- src/store/slices/loginInfo/loginInfoSlice.ts | 3 +- src/types/enums.types.ts | 15 ----- src/types/login.types.ts | 2 +- src/types/nativeAuth.types.ts | 17 ----- src/utils/account/getAddress.ts | 6 ++ src/utils/account/isLoggedIn.ts | 5 ++ 25 files changed, 197 insertions(+), 151 deletions(-) create mode 100644 src/core/methods/init/init.ts rename src/core/{ => providers}/ProviderFactory.ts (66%) create mode 100644 src/core/providers/types/providerFactory.types.ts rename src/services/nativeAuth/methods/{getNativeAuthConfig.ts => buildNativeAuthConfig.ts} (50%) create mode 100644 src/services/nativeAuth/methods/getDefaultNativeAuthConfig.ts delete mode 100644 src/types/nativeAuth.types.ts create mode 100644 src/utils/account/getAddress.ts create mode 100644 src/utils/account/isLoggedIn.ts diff --git a/esbuild.js b/esbuild.js index 632b424c..3571c623 100644 --- a/esbuild.js +++ b/esbuild.js @@ -25,7 +25,7 @@ const executeBuild = () => format: 'esm', outdir: 'out', treeShaking: true, - minify: true, + minify: false, bundle: true, sourcemap: true, chunkNames: '__chunks__/[name]-[hash]', @@ -38,10 +38,7 @@ const executeBuild = () => process: 'process', Buffer: 'Buffer' }, - plugins: [ - plugin(stdLibBrowser), - nodeExternalsPlugin(), - ] + plugins: [plugin(stdLibBrowser), nodeExternalsPlugin()] }) .then(() => { console.log( diff --git a/src/core/index.ts b/src/core/index.ts index 864b2dfd..95a1e567 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -1,2 +1,2 @@ -export * from './ProviderFactory'; +export * from './providers/ProviderFactory'; export * from './Logger'; diff --git a/src/core/methods/init/init.ts b/src/core/methods/init/init.ts new file mode 100644 index 00000000..1e7c369d --- /dev/null +++ b/src/core/methods/init/init.ts @@ -0,0 +1,30 @@ +import { initStore } from 'store/store'; +import { defaultStorageCallback, StorageCallback } from 'store/storage'; +import { setTokenLoginNativeAuthTokenConfig } from 'store/actions/loginInfo/loginInfoActions'; +import { NativeAuthConfigType } from 'services/nativeAuth/nativeAuth.types'; +import { getDefaultNativeAuthConfig } from 'services/nativeAuth/methods/getDefaultNativeAuthConfig'; + +type InitAppType = { + storage?: { + getStorageCallback: StorageCallback; + }; + nativeAuth?: boolean | NativeAuthConfigType; +}; +const defaultInitAppProps = { + storage: { + getStorageCallback: defaultStorageCallback + } +}; +export const initializeDApp = (props?: InitAppType) => { + const { storage, nativeAuth } = { ...defaultInitAppProps, ...props }; + initStore(storage.getStorageCallback); + + if (nativeAuth) { + const nativeAuthConfig: NativeAuthConfigType = + typeof nativeAuth === 'boolean' + ? getDefaultNativeAuthConfig() + : nativeAuth; + + setTokenLoginNativeAuthTokenConfig(nativeAuthConfig); + } +}; diff --git a/src/core/methods/login/helpers/getLoginService.ts b/src/core/methods/login/helpers/getLoginService.ts index 0d8f3c5f..6cf47f3a 100644 --- a/src/core/methods/login/helpers/getLoginService.ts +++ b/src/core/methods/login/helpers/getLoginService.ts @@ -1,12 +1,12 @@ import { Address, SignableMessage } from '@multiversx/sdk-core'; import { nativeAuth } from 'services/nativeAuth'; -import { getNativeAuthConfig } from 'services/nativeAuth/methods'; +import { buildNativeAuthConfig } from 'services/nativeAuth/methods'; import { networkSelector, tokenLoginSelector } from 'store/selectors'; import { getState } from 'store/store'; import { OnProviderLoginType } from 'types/login.types'; import { getAccount } from '../../account/getAccount'; import { setTokenLogin } from 'store/actions/loginInfo/loginInfoActions'; -import { NativeAuthConfigType } from 'types/nativeAuth.types'; +import { NativeAuthConfigType } from 'services/nativeAuth/nativeAuth.types'; const getApiAddress = ( apiAddress: string, @@ -29,7 +29,7 @@ export const getLoginService = (config?: OnProviderLoginType['nativeAuth']) => { const apiAddress = getApiAddress(network.apiAddress, config); - const configuration = getNativeAuthConfig({ + const configuration = buildNativeAuthConfig({ ...(config === true ? {} : config), ...(apiAddress ? { apiAddress } : {}) }); diff --git a/src/core/methods/login/login.ts b/src/core/methods/login/login.ts index c36df2c3..b21acbb2 100644 --- a/src/core/methods/login/login.ts +++ b/src/core/methods/login/login.ts @@ -1,10 +1,20 @@ -import { IProvider, IProviderFactory, ProviderFactory } from 'core/ProviderFactory'; -import { NativeAuthConfigType } from 'types/nativeAuth.types'; import { nativeAuth } from 'services/nativeAuth'; import { setAddress } from 'store/actions/account'; -import { setLoginMethod, setTokenLogin } from 'store/actions/loginInfo/loginInfoActions'; +import { + setProviderType, + setTokenLogin +} from 'store/actions/loginInfo/loginInfoActions'; import { setAccountProvider } from 'core/providers/accountProvider'; -import { getNativeAuthConfig } from 'services/nativeAuth/methods'; +import { + IProvider, + IProviderFactory +} from 'core/providers/types/providerFactory.types'; +import { ProviderFactory } from 'core/providers/ProviderFactory'; +import { tokenLoginSelector } from 'store/selectors'; +import { getState } from 'store/store'; +import { NativeAuthConfigType } from 'services/nativeAuth/nativeAuth.types'; +import { isLoggedIn } from 'utils/account/isLoggedIn'; +import { getAddress } from '../../../utils/account/getAddress'; async function normalLogin(provider: IProvider) { await provider.login(); @@ -22,8 +32,11 @@ async function normalLogin(provider: IProvider) { }; } -async function loginWithNativeToken(provider: IProvider, nativeAuthConfig: NativeAuthConfigType) { - const nativeAuthClient = nativeAuth(nativeAuthConfig); +async function loginWithNativeToken( + provider: IProvider, + nativeAuthConfig: NativeAuthConfigType +) { + const nativeAuthClient = nativeAuth(nativeAuthConfig); const loginToken = await nativeAuthClient.initialize({ noCache: true @@ -34,11 +47,11 @@ async function loginWithNativeToken(provider: IProvider, nativeAuthConfig: Nativ const address = provider.getAddress?.(); const signature = provider.getTokenLoginSignature?.(); - if(!address) { + if (!address) { throw new Error('Address not found'); } - if(!signature) { + if (!signature) { throw new Error('Signature not found'); } @@ -62,36 +75,37 @@ async function loginWithNativeToken(provider: IProvider, nativeAuthConfig: Nativ nativeAuthToken, loginToken, nativeAuthConfig - } + }; } export const login = async ({ - providerConfig, - withNativeAuth + providerConfig }: { - providerConfig: IProviderFactory, - withNativeAuth?: boolean | NativeAuthConfigType, + providerConfig: IProviderFactory; }) => { + const loggedIn = isLoggedIn(); + + if (loggedIn) { + console.warn('Already logged in with:', getAddress()); + return; + } + const factory = new ProviderFactory(); const provider = await factory.create(providerConfig); - if(!provider) { + if (!provider) { throw new Error('Provider not found'); } await provider.init?.(); setAccountProvider(provider); - setLoginMethod(providerConfig.type); + setProviderType(providerConfig.type); - if(withNativeAuth) { - if(typeof withNativeAuth === 'boolean') { - withNativeAuth = getNativeAuthConfig(true); - } - - const nativeAuthConfig = withNativeAuth as NativeAuthConfigType; + const nativeAuthConfig = tokenLoginSelector(getState())?.nativeAuthConfig; + if (nativeAuthConfig) { return await loginWithNativeToken(provider, nativeAuthConfig); - } else { - return await normalLogin(provider); } -} \ No newline at end of file + + return await normalLogin(provider); +}; diff --git a/src/core/methods/login/webWalletLogin.ts b/src/core/methods/login/webWalletLogin.ts index 26f55019..4112087a 100644 --- a/src/core/methods/login/webWalletLogin.ts +++ b/src/core/methods/login/webWalletLogin.ts @@ -1,4 +1,3 @@ -import { LoginMethodsEnum } from 'types/enums.types'; import { OnProviderLoginType } from 'types/login.types'; import { getWindowLocation } from 'utils/window/getWindowLocation'; import { getLoginService } from './helpers/getLoginService'; @@ -14,6 +13,7 @@ import { setAccount } from 'store/actions/account/accountActions'; import { getLatestNonce } from 'utils/account/getLatestNonce'; import { AccountType } from 'types/account.types'; import { CrossWindowProvider } from 'lib/sdkWebWalletCrossWindowProvider'; +import { ProviderTypeEnum } from '../../providers/types/providerFactory.types'; export const webWalletLogin = async ({ token: tokenToSign, @@ -100,7 +100,7 @@ export const webWalletLogin = async ({ loginAction({ address: account.address, - loginMethod: LoginMethodsEnum.crossWindow + providerType: ProviderTypeEnum.crossWindow }); const newAccount: AccountType = { diff --git a/src/core/methods/logout/logout.ts b/src/core/methods/logout/logout.ts index 15ff992a..b29a2bc5 100644 --- a/src/core/methods/logout/logout.ts +++ b/src/core/methods/logout/logout.ts @@ -1,11 +1,11 @@ import { storage } from 'storage'; import { localStorageKeys } from 'storage/local'; -import { LoginMethodsEnum } from 'types'; import { getAddress } from '../account/getAddress'; import { CrossWindowProvider } from 'lib/sdkWebWalletCrossWindowProvider'; import { logoutAction } from 'store/actions/sharedActions/sharedActions'; import { getAccountProvider } from 'core/providers/accountProvider'; import { getProviderType } from 'core/providers/helpers/utils'; +import { ProviderTypeEnum } from 'core/providers/types/providerFactory.types'; const broadcastLogoutAcrossTabs = (address: string) => { const storedData = storage.local?.getItem(localStorageKeys.logoutEvent); @@ -52,7 +52,7 @@ export async function logout( if ( options.hasConsentPopup && - providerType === LoginMethodsEnum.crossWindow + providerType === ProviderTypeEnum.crossWindow ) { (provider as unknown as CrossWindowProvider).setShouldShowConsentPopup( true diff --git a/src/core/ProviderFactory.ts b/src/core/providers/ProviderFactory.ts similarity index 66% rename from src/core/ProviderFactory.ts rename to src/core/providers/ProviderFactory.ts index 3c5960c6..7218a5a3 100644 --- a/src/core/ProviderFactory.ts +++ b/src/core/providers/ProviderFactory.ts @@ -1,36 +1,11 @@ import { CrossWindowProvider } from 'lib/sdkWebWalletCrossWindowProvider'; import { ExtensionProvider } from '@multiversx/sdk-extension-provider'; -import type { IDAppProviderBase } from '@multiversx/sdk-dapp-utils'; -import { LoginMethodsType, LoginMethodsEnum } from '../types'; - -export interface IProvider extends IDAppProviderBase { - init: () => Promise; - // TODO change return type to { address: string, signature: string } and also change the return type in IDAppProviderBase. - login: (options?: { token?: string }) => Promise; - logout: () => Promise; - setAddress: (address: string) => IProvider; - setShouldShowConsentPopup?: (shouldShow: boolean) => void; - getAddress(): string | undefined; - getTokenLoginSignature(): string | undefined; -} - -export interface IProviderConfig { - network: { - walletAddress: string; - }; -} - -export type ProviderType = LoginMethodsType; - -export interface IProviderFactory { - type: ProviderType; - config: IProviderConfig; - customProvider?: IProvider; -} - -export const ProviderTypeEnum = { - ...LoginMethodsEnum -} as const; +import { + IProvider, + IProviderConfig, + IProviderFactory, + ProviderTypeEnum +} from './types/providerFactory.types'; export class ProviderFactory { public async create({ @@ -55,11 +30,11 @@ export class ProviderFactory { createdProvider.getAddress = () => { return provider.account.address; - } + }; createdProvider.getTokenLoginSignature = () => { return provider.account.signature; - } + }; break; } diff --git a/src/core/providers/accountProvider.ts b/src/core/providers/accountProvider.ts index cb4421d6..bdce2ab0 100644 --- a/src/core/providers/accountProvider.ts +++ b/src/core/providers/accountProvider.ts @@ -1,6 +1,6 @@ import { emptyProvider } from './helpers/emptyProvider'; import { CrossWindowProvider } from 'lib/sdkWebWalletCrossWindowProvider'; -import { IProvider } from 'core/ProviderFactory'; +import { IProvider } from 'core/providers/types/providerFactory.types'; export type ProvidersType = IProvider | CrossWindowProvider; diff --git a/src/core/providers/helpers/emptyProvider.ts b/src/core/providers/helpers/emptyProvider.ts index f1be7930..c61606f2 100644 --- a/src/core/providers/helpers/emptyProvider.ts +++ b/src/core/providers/helpers/emptyProvider.ts @@ -1,6 +1,6 @@ import { SignableMessage, Transaction } from '@multiversx/sdk-core'; import { EngineTypes } from 'utils/walletconnect/__sdkWalletconnectProvider'; -import { IProvider } from 'core/ProviderFactory'; +import { IProvider } from 'core/providers/types/providerFactory.types'; export const DAPP_INIT_ROUTE = '/dapp/init'; @@ -55,13 +55,9 @@ export class EmptyProvider implements IProvider { ); } - signTransactions( - transactions: T[] - ): Promise { + signTransactions(transactions: T[]): Promise { throw new Error( - notInitializedError( - `signTransactions with transactions: ${transactions}` - ) + notInitializedError(`signTransactions with transactions: ${transactions}`) ); } diff --git a/src/core/providers/helpers/utils.ts b/src/core/providers/helpers/utils.ts index ea37aac9..4b0341a7 100644 --- a/src/core/providers/helpers/utils.ts +++ b/src/core/providers/helpers/utils.ts @@ -3,31 +3,31 @@ import { HWProvider } from '@multiversx/sdk-hw-provider'; import { MetamaskProvider } from '@multiversx/sdk-metamask-provider/out/metamaskProvider'; import { OperaProvider } from '@multiversx/sdk-opera-provider'; import { WalletProvider } from '@multiversx/sdk-web-wallet-provider'; -import { LoginMethodsType, LoginMethodsEnum } from 'types/enums.types'; import { WalletConnectV2Provider } from 'utils/walletconnect/__sdkWalletconnectProvider'; import { EmptyProvider } from './emptyProvider'; import { CrossWindowProvider } from 'lib/sdkWebWalletCrossWindowProvider'; +import { ProviderTypeEnum } from 'core/providers/types/providerFactory.types'; export const getProviderType = ( provider?: TProvider | null -): LoginMethodsType => { +): ProviderTypeEnum => { switch (provider?.constructor) { case WalletProvider: - return LoginMethodsEnum.webhook; + return ProviderTypeEnum.webhook; case WalletConnectV2Provider: - return LoginMethodsEnum.walletConnect; + return ProviderTypeEnum.walletConnect; case HWProvider: - return LoginMethodsEnum.hardware; + return ProviderTypeEnum.hardware; case ExtensionProvider: - return LoginMethodsEnum.extension; + return ProviderTypeEnum.extension; case MetamaskProvider: - return LoginMethodsEnum.metamask; + return ProviderTypeEnum.metamask; case OperaProvider: - return LoginMethodsEnum.opera; + return ProviderTypeEnum.opera; case CrossWindowProvider: - return LoginMethodsEnum.crossWindow; + return ProviderTypeEnum.crossWindow; case EmptyProvider: default: - return LoginMethodsEnum.none; + return ProviderTypeEnum.none; } }; diff --git a/src/core/providers/types/providerFactory.types.ts b/src/core/providers/types/providerFactory.types.ts new file mode 100644 index 00000000..44f3f2d7 --- /dev/null +++ b/src/core/providers/types/providerFactory.types.ts @@ -0,0 +1,38 @@ +import type { IDAppProviderBase } from '@multiversx/sdk-dapp-utils'; + +export interface IProvider extends IDAppProviderBase { + init: () => Promise; + // TODO change return type to { address: string, signature: string } and also change the return type in IDAppProviderBase. + login: (options?: { token?: string }) => Promise; + logout: () => Promise; + setAddress: (address: string) => IProvider; + setShouldShowConsentPopup?: (shouldShow: boolean) => void; + getAddress(): string | undefined; + // TODO will be removed as soon as the new login method is implemented in the same way for all providers + getTokenLoginSignature(): string | undefined; +} + +export interface IProviderConfig { + network: { + walletAddress: string; + }; +} + +export enum ProviderTypeEnum { + iframe = 'iframe', + crossWindow = 'crossWindow', + extension = 'extension', + walletConnect = 'walletConnect', + hardware = 'hardware', + opera = 'opera', + metamask = 'metamask', + webhook = 'webhook', + custom = 'custom', + none = '' +} + +export interface IProviderFactory { + type: ProviderTypeEnum; + config: IProviderConfig; + customProvider?: IProvider; +} diff --git a/src/services/nativeAuth/methods/getNativeAuthConfig.ts b/src/services/nativeAuth/methods/buildNativeAuthConfig.ts similarity index 50% rename from src/services/nativeAuth/methods/getNativeAuthConfig.ts rename to src/services/nativeAuth/methods/buildNativeAuthConfig.ts index 08bc3e87..51b9ce77 100644 --- a/src/services/nativeAuth/methods/getNativeAuthConfig.ts +++ b/src/services/nativeAuth/methods/buildNativeAuthConfig.ts @@ -1,18 +1,10 @@ -import { getWindowLocation } from 'utils/window/getWindowLocation'; -import { NativeAuthConfigType } from '../../../types/nativeAuth.types'; +import { NativeAuthConfigType } from '../nativeAuth.types'; +import { getDefaultNativeAuthConfig } from './getDefaultNativeAuthConfig'; -const defaultNativeAuthConfig = { - origin: getWindowLocation().origin, - apiAddress: 'https://api.multiversx.com', - expirySeconds: 60 * 60 * 24, // one day - tokenExpirationToastWarningSeconds: 5 * 60 // five minutes -}; +export const buildNativeAuthConfig = (config?: NativeAuthConfigType) => { + const defaultNativeAuthConfig = getDefaultNativeAuthConfig(); -export const getNativeAuthConfig = (config?: NativeAuthConfigType | true) => { - if (config === true) { - return defaultNativeAuthConfig; - } - const nativeAuthConfig = { + return { origin: config?.origin ?? defaultNativeAuthConfig.origin, blockHashShard: config?.blockHashShard, expirySeconds: @@ -25,5 +17,4 @@ export const getNativeAuthConfig = (config?: NativeAuthConfigType | true) => { gatewayUrl: config?.gatewayUrl, extraRequestHeaders: config?.extraRequestHeaders ?? {} }; - return nativeAuthConfig; }; diff --git a/src/services/nativeAuth/methods/getDefaultNativeAuthConfig.ts b/src/services/nativeAuth/methods/getDefaultNativeAuthConfig.ts new file mode 100644 index 00000000..0ae7fe40 --- /dev/null +++ b/src/services/nativeAuth/methods/getDefaultNativeAuthConfig.ts @@ -0,0 +1,10 @@ +import { getWindowLocation } from 'utils/window/getWindowLocation'; + +export const getDefaultNativeAuthConfig = () => { + return { + origin: getWindowLocation().origin, + apiAddress: 'https://api.multiversx.com', + expirySeconds: 60 * 60 * 24, // one day + tokenExpirationToastWarningSeconds: 5 * 60 // five minutes + }; +}; diff --git a/src/services/nativeAuth/methods/index.ts b/src/services/nativeAuth/methods/index.ts index d60dcb4b..8928cf03 100644 --- a/src/services/nativeAuth/methods/index.ts +++ b/src/services/nativeAuth/methods/index.ts @@ -1,2 +1,2 @@ export * from './getTokenExpiration'; -export * from './getNativeAuthConfig'; +export * from './buildNativeAuthConfig'; diff --git a/src/services/nativeAuth/nativeAuth.ts b/src/services/nativeAuth/nativeAuth.ts index 060bc599..1d0948ac 100644 --- a/src/services/nativeAuth/nativeAuth.ts +++ b/src/services/nativeAuth/nativeAuth.ts @@ -1,12 +1,12 @@ import { NativeAuthClient } from '@multiversx/sdk-native-auth-client'; -import { NativeAuthConfigType } from 'types/nativeAuth.types'; import { getLatestBlockHash, LatestBlockHashType } from './helpers/getLatestBlockHash'; -import { getNativeAuthConfig, getTokenExpiration } from './methods'; +import { buildNativeAuthConfig, getTokenExpiration } from './methods'; +import { NativeAuthConfigType } from './nativeAuth.types'; interface NativeAuthInitType { extraInfo?: { [key: string]: string }; @@ -23,7 +23,7 @@ export const nativeAuth = (config?: NativeAuthConfigType) => { extraInfo: extraInfoFromConfig, gatewayUrl, extraRequestHeaders - } = getNativeAuthConfig(config) as NativeAuthConfigType; + } = buildNativeAuthConfig(config) as NativeAuthConfigType; const nativeAuthClient = new NativeAuthClient({ origin, @@ -76,7 +76,6 @@ export const nativeAuth = (config?: NativeAuthConfigType) => { }): string => nativeAuthClient.getToken(address, token, signature); return { - getNativeAuthConfig, initialize, getToken, getTokenExpiration diff --git a/src/store/actions/loginInfo/loginInfoActions.ts b/src/store/actions/loginInfo/loginInfoActions.ts index 64649397..c80971dd 100644 --- a/src/store/actions/loginInfo/loginInfoActions.ts +++ b/src/store/actions/loginInfo/loginInfoActions.ts @@ -1,4 +1,3 @@ -import { LoginMethodsType } from 'types/enums.types'; import { TokenLoginType } from 'types/login.types'; import { LedgerLoginType, @@ -6,10 +5,12 @@ import { WalletConnectLoginType } from 'store/slices/loginInfo/loginInfo.types'; import { getStore } from 'store/store'; +import { ProviderTypeEnum } from 'core/providers/types/providerFactory.types'; +import { NativeAuthConfigType } from 'services/nativeAuth/nativeAuth.types'; -export const setLoginMethod = (loginMethod: LoginMethodsType) => +export const setProviderType = (providerType: ProviderTypeEnum) => getStore().setState(({ loginInfo: state }) => { - state.loginMethod = loginMethod; + state.providerType = providerType; }); export const setTokenLogin = (tokenLogin: TokenLoginType) => @@ -24,6 +25,20 @@ export const setTokenLoginSignature = (signature: string) => } }); +export const setTokenLoginNativeAuthTokenConfig = ( + nativeAuthConfig: NativeAuthConfigType +) => + getStore().setState(({ loginInfo: state }) => { + if (state?.tokenLogin != null) { + state.tokenLogin.nativeAuthConfig = nativeAuthConfig; + } else { + state.tokenLogin = { + nativeAuthConfig, + loginToken: '' + }; + } + }); + export const setWalletLogin = (walletLogin: LoginInfoType | null) => getStore().setState(({ loginInfo: state }) => { state.walletLogin = walletLogin; diff --git a/src/store/actions/sharedActions/sharedActions.ts b/src/store/actions/sharedActions/sharedActions.ts index 49adeb1f..e03b1af8 100644 --- a/src/store/actions/sharedActions/sharedActions.ts +++ b/src/store/actions/sharedActions/sharedActions.ts @@ -1,17 +1,20 @@ import { Address } from '@multiversx/sdk-core/out'; import { getStore } from '../../store'; -import { LoginMethodsType } from 'types/enums.types'; import { resetStore } from 'store/middleware/logoutMiddleware'; +import { ProviderTypeEnum } from 'core/providers/types/providerFactory.types'; export const logoutAction = () => getStore().setState(resetStore); export interface LoginActionPayloadType { address: string; - loginMethod: LoginMethodsType; + providerType: ProviderTypeEnum; } -export const loginAction = ({ address, loginMethod }: LoginActionPayloadType) => +export const loginAction = ({ + address, + providerType +}: LoginActionPayloadType) => getStore().setState(({ account, loginInfo }) => { account.address = address; account.publicKey = new Address(address).hex(); - loginInfo.loginMethod = loginMethod; + loginInfo.providerType = providerType; }); diff --git a/src/store/slices/loginInfo/loginInfo.types.ts b/src/store/slices/loginInfo/loginInfo.types.ts index 4d1013c3..2ff1f3c3 100644 --- a/src/store/slices/loginInfo/loginInfo.types.ts +++ b/src/store/slices/loginInfo/loginInfo.types.ts @@ -1,5 +1,5 @@ -import { LoginMethodsEnum, LoginMethodsType } from 'types/enums.types'; import { TokenLoginType } from 'types/login.types'; +import { ProviderTypeEnum } from 'core/providers/types/providerFactory.types'; export interface WalletConnectLoginType { loginType: string; @@ -18,7 +18,7 @@ export interface LoginInfoType { } export interface LoginInfoSliceType { - loginMethod: LoginMethodsType; + providerType: ProviderTypeEnum | null; walletConnectLogin: WalletConnectLoginType | null; ledgerLogin: LedgerLoginType | null; tokenLogin: TokenLoginType | null; diff --git a/src/store/slices/loginInfo/loginInfoSlice.ts b/src/store/slices/loginInfo/loginInfoSlice.ts index fb455d08..42a16769 100644 --- a/src/store/slices/loginInfo/loginInfoSlice.ts +++ b/src/store/slices/loginInfo/loginInfoSlice.ts @@ -1,10 +1,9 @@ -import { LoginMethodsEnum } from 'types/enums.types'; import { StateCreator } from 'zustand/vanilla'; import { StoreType, MutatorsIn } from 'store/store.types'; import { LoginInfoSliceType } from './loginInfo.types'; export const initialState: LoginInfoSliceType = { - loginMethod: LoginMethodsEnum.none, + providerType: null, walletConnectLogin: null, ledgerLogin: null, tokenLogin: null, diff --git a/src/types/enums.types.ts b/src/types/enums.types.ts index 684dc622..4af22bda 100644 --- a/src/types/enums.types.ts +++ b/src/types/enums.types.ts @@ -4,21 +4,6 @@ export enum EnvironmentsEnum { mainnet = 'mainnet' } -export const LoginMethodsEnum = { - iframe: 'iframe', - crossWindow: 'crossWindow', - extension: 'extension', - walletConnect: 'walletConnect', - hardware: 'hardware', - opera: 'opera', - metamask: 'metamask', - webhook: 'webhook', - custom: "custom", - none: '' -} as const - -export type LoginMethodsType = typeof LoginMethodsEnum[keyof typeof LoginMethodsEnum]; - export enum TypesOfSmartContractCallsEnum { MultiESDTNFTTransfer = 'MultiESDTNFTTransfer', ESDTNFTTransfer = 'ESDTNFTTransfer' diff --git a/src/types/login.types.ts b/src/types/login.types.ts index 148fe05b..4a5f0535 100644 --- a/src/types/login.types.ts +++ b/src/types/login.types.ts @@ -1,4 +1,4 @@ -import { NativeAuthConfigType } from './nativeAuth.types'; +import { NativeAuthConfigType } from 'services/nativeAuth/nativeAuth.types'; export interface OnProviderLoginType { token?: string; diff --git a/src/types/nativeAuth.types.ts b/src/types/nativeAuth.types.ts deleted file mode 100644 index c0c6b885..00000000 --- a/src/types/nativeAuth.types.ts +++ /dev/null @@ -1,17 +0,0 @@ -export interface NativeAuthConfigType { - origin?: string; - apiAddress?: string; - expirySeconds?: number; - blockHashShard?: number; - gatewayUrl?: string; - extraRequestHeaders?: { [key: string]: string }; - extraInfo?: { - [key: string]: string; - }; - /** - * Displays a logout toast warning before token expiration. Defaults to 5 minutes. - * - * If set to `null`, will not trigger any warning. - */ - tokenExpirationToastWarningSeconds?: number | null; -} diff --git a/src/utils/account/getAddress.ts b/src/utils/account/getAddress.ts new file mode 100644 index 00000000..c65e0a53 --- /dev/null +++ b/src/utils/account/getAddress.ts @@ -0,0 +1,6 @@ +import { addressSelector } from 'store/selectors'; +import { getState } from 'store/store'; + +export const getAddress = () => { + return addressSelector(getState()); +}; diff --git a/src/utils/account/isLoggedIn.ts b/src/utils/account/isLoggedIn.ts new file mode 100644 index 00000000..387a2991 --- /dev/null +++ b/src/utils/account/isLoggedIn.ts @@ -0,0 +1,5 @@ +import { getAddress } from './getAddress'; + +export const isLoggedIn = () => { + return Boolean(getAddress()); +}; From 933f4f3470590b2e1707e47d538493dc7dec2552 Mon Sep 17 00:00:00 2001 From: cipriandraghici Date: Thu, 25 Jul 2024 16:29:13 +0300 Subject: [PATCH 07/15] revert minify value --- esbuild.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esbuild.js b/esbuild.js index 3571c623..4e22a75d 100644 --- a/esbuild.js +++ b/esbuild.js @@ -25,7 +25,7 @@ const executeBuild = () => format: 'esm', outdir: 'out', treeShaking: true, - minify: false, + minify: true, bundle: true, sourcemap: true, chunkNames: '__chunks__/[name]-[hash]', From ae10990c79a2d64c6d8ddc1ebf160910ddc8d06b Mon Sep 17 00:00:00 2001 From: cipriandraghici Date: Thu, 25 Jul 2024 16:31:07 +0300 Subject: [PATCH 08/15] fix import --- src/core/methods/login/login.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/methods/login/login.ts b/src/core/methods/login/login.ts index b21acbb2..e3f5a4b8 100644 --- a/src/core/methods/login/login.ts +++ b/src/core/methods/login/login.ts @@ -14,7 +14,7 @@ import { tokenLoginSelector } from 'store/selectors'; import { getState } from 'store/store'; import { NativeAuthConfigType } from 'services/nativeAuth/nativeAuth.types'; import { isLoggedIn } from 'utils/account/isLoggedIn'; -import { getAddress } from '../../../utils/account/getAddress'; +import { getAddress } from 'utils/account/getAddress'; async function normalLogin(provider: IProvider) { await provider.login(); From 271f3b80004386808bb592282dabc297181b602f Mon Sep 17 00:00:00 2001 From: cipriandraghici Date: Thu, 25 Jul 2024 16:56:06 +0300 Subject: [PATCH 09/15] refactoring --- src/utils/account/{isLoggedIn.ts => getIsLoggedIn.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/utils/account/{isLoggedIn.ts => getIsLoggedIn.ts} (100%) diff --git a/src/utils/account/isLoggedIn.ts b/src/utils/account/getIsLoggedIn.ts similarity index 100% rename from src/utils/account/isLoggedIn.ts rename to src/utils/account/getIsLoggedIn.ts From 54786ddbe381c5cc8e236120fbdc4547f96c0b7e Mon Sep 17 00:00:00 2001 From: cipriandraghici Date: Thu, 25 Jul 2024 17:03:48 +0300 Subject: [PATCH 10/15] refactoring --- src/core/methods/login/login.ts | 4 ++-- src/core/providers/ProviderFactory.ts | 2 +- src/core/providers/types/providerFactory.types.ts | 1 - src/services/nativeAuth/nativeAuth.ts | 2 +- src/store/actions/loginInfo/loginInfoActions.ts | 11 ++++++----- src/utils/account/getIsLoggedIn.ts | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/core/methods/login/login.ts b/src/core/methods/login/login.ts index e3f5a4b8..8c99b544 100644 --- a/src/core/methods/login/login.ts +++ b/src/core/methods/login/login.ts @@ -13,7 +13,7 @@ import { ProviderFactory } from 'core/providers/ProviderFactory'; import { tokenLoginSelector } from 'store/selectors'; import { getState } from 'store/store'; import { NativeAuthConfigType } from 'services/nativeAuth/nativeAuth.types'; -import { isLoggedIn } from 'utils/account/isLoggedIn'; +import { getIsLoggedIn } from 'utils/account/getIsLoggedIn'; import { getAddress } from 'utils/account/getAddress'; async function normalLogin(provider: IProvider) { @@ -83,7 +83,7 @@ export const login = async ({ }: { providerConfig: IProviderFactory; }) => { - const loggedIn = isLoggedIn(); + const loggedIn = getIsLoggedIn(); if (loggedIn) { console.warn('Already logged in with:', getAddress()); diff --git a/src/core/providers/ProviderFactory.ts b/src/core/providers/ProviderFactory.ts index 7218a5a3..d11d1c03 100644 --- a/src/core/providers/ProviderFactory.ts +++ b/src/core/providers/ProviderFactory.ts @@ -13,7 +13,7 @@ export class ProviderFactory { config, customProvider }: IProviderFactory): Promise { - let createdProvider: IProvider | undefined = undefined; + let createdProvider: IProvider | undefined; switch (type) { // case ProviderTypeEnum.iframe: { diff --git a/src/core/providers/types/providerFactory.types.ts b/src/core/providers/types/providerFactory.types.ts index 44f3f2d7..4bc2ed79 100644 --- a/src/core/providers/types/providerFactory.types.ts +++ b/src/core/providers/types/providerFactory.types.ts @@ -5,7 +5,6 @@ export interface IProvider extends IDAppProviderBase { // TODO change return type to { address: string, signature: string } and also change the return type in IDAppProviderBase. login: (options?: { token?: string }) => Promise; logout: () => Promise; - setAddress: (address: string) => IProvider; setShouldShowConsentPopup?: (shouldShow: boolean) => void; getAddress(): string | undefined; // TODO will be removed as soon as the new login method is implemented in the same way for all providers diff --git a/src/services/nativeAuth/nativeAuth.ts b/src/services/nativeAuth/nativeAuth.ts index 1d0948ac..00af903b 100644 --- a/src/services/nativeAuth/nativeAuth.ts +++ b/src/services/nativeAuth/nativeAuth.ts @@ -23,7 +23,7 @@ export const nativeAuth = (config?: NativeAuthConfigType) => { extraInfo: extraInfoFromConfig, gatewayUrl, extraRequestHeaders - } = buildNativeAuthConfig(config) as NativeAuthConfigType; + } = buildNativeAuthConfig(config); const nativeAuthClient = new NativeAuthClient({ origin, diff --git a/src/store/actions/loginInfo/loginInfoActions.ts b/src/store/actions/loginInfo/loginInfoActions.ts index c80971dd..887a6702 100644 --- a/src/store/actions/loginInfo/loginInfoActions.ts +++ b/src/store/actions/loginInfo/loginInfoActions.ts @@ -31,12 +31,13 @@ export const setTokenLoginNativeAuthTokenConfig = ( getStore().setState(({ loginInfo: state }) => { if (state?.tokenLogin != null) { state.tokenLogin.nativeAuthConfig = nativeAuthConfig; - } else { - state.tokenLogin = { - nativeAuthConfig, - loginToken: '' - }; + return; } + + state.tokenLogin = { + nativeAuthConfig, + loginToken: '' + }; }); export const setWalletLogin = (walletLogin: LoginInfoType | null) => diff --git a/src/utils/account/getIsLoggedIn.ts b/src/utils/account/getIsLoggedIn.ts index 387a2991..722dd1cb 100644 --- a/src/utils/account/getIsLoggedIn.ts +++ b/src/utils/account/getIsLoggedIn.ts @@ -1,5 +1,5 @@ import { getAddress } from './getAddress'; -export const isLoggedIn = () => { +export const getIsLoggedIn = () => { return Boolean(getAddress()); }; From e2b6dc647f5508ba6bd6c954b8610705c89ad5a2 Mon Sep 17 00:00:00 2001 From: cipriandraghici Date: Thu, 25 Jul 2024 17:05:51 +0300 Subject: [PATCH 11/15] refactoring --- src/core/methods/login/login.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/methods/login/login.ts b/src/core/methods/login/login.ts index 8c99b544..79691a4a 100644 --- a/src/core/methods/login/login.ts +++ b/src/core/methods/login/login.ts @@ -16,7 +16,7 @@ import { NativeAuthConfigType } from 'services/nativeAuth/nativeAuth.types'; import { getIsLoggedIn } from 'utils/account/getIsLoggedIn'; import { getAddress } from 'utils/account/getAddress'; -async function normalLogin(provider: IProvider) { +async function loginWithoutNativeToken(provider: IProvider) { await provider.login(); const address = provider.getAddress?.(); @@ -107,5 +107,5 @@ export const login = async ({ return await loginWithNativeToken(provider, nativeAuthConfig); } - return await normalLogin(provider); + return await loginWithoutNativeToken(provider); }; From db56ccc1a18ca28797438028a29145929c3dfc97 Mon Sep 17 00:00:00 2001 From: cipriandraghici Date: Thu, 25 Jul 2024 17:08:51 +0300 Subject: [PATCH 12/15] add nativeAuthConfig selector --- src/core/methods/login/login.ts | 4 ++-- src/store/selectors/loginInfoSelectors.ts | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/core/methods/login/login.ts b/src/core/methods/login/login.ts index 79691a4a..b3e0ffa9 100644 --- a/src/core/methods/login/login.ts +++ b/src/core/methods/login/login.ts @@ -10,7 +10,7 @@ import { IProviderFactory } from 'core/providers/types/providerFactory.types'; import { ProviderFactory } from 'core/providers/ProviderFactory'; -import { tokenLoginSelector } from 'store/selectors'; +import { nativeAuthConfigSelector } from 'store/selectors'; import { getState } from 'store/store'; import { NativeAuthConfigType } from 'services/nativeAuth/nativeAuth.types'; import { getIsLoggedIn } from 'utils/account/getIsLoggedIn'; @@ -101,7 +101,7 @@ export const login = async ({ setAccountProvider(provider); setProviderType(providerConfig.type); - const nativeAuthConfig = tokenLoginSelector(getState())?.nativeAuthConfig; + const nativeAuthConfig = nativeAuthConfigSelector(getState()); if (nativeAuthConfig) { return await loginWithNativeToken(provider, nativeAuthConfig); diff --git a/src/store/selectors/loginInfoSelectors.ts b/src/store/selectors/loginInfoSelectors.ts index f8251c93..4453da2d 100644 --- a/src/store/selectors/loginInfoSelectors.ts +++ b/src/store/selectors/loginInfoSelectors.ts @@ -4,3 +4,6 @@ export const loginInfoSelector = ({ loginInfo }: StoreType) => loginInfo; export const tokenLoginSelector = ({ loginInfo }: StoreType) => loginInfo.tokenLogin; + +export const nativeAuthConfigSelector = ({ loginInfo }: StoreType) => + loginInfo.tokenLogin?.nativeAuthConfig; From 0d871842e3d749b4696138cc0dbe23f13a7283cb Mon Sep 17 00:00:00 2001 From: cipriandraghici Date: Thu, 25 Jul 2024 17:10:08 +0300 Subject: [PATCH 13/15] refactoring empty provider --- src/core/providers/helpers/emptyProvider.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/core/providers/helpers/emptyProvider.ts b/src/core/providers/helpers/emptyProvider.ts index c61606f2..95d81f67 100644 --- a/src/core/providers/helpers/emptyProvider.ts +++ b/src/core/providers/helpers/emptyProvider.ts @@ -94,14 +94,6 @@ export class EmptyProvider implements IProvider { ); } - ping?(): Promise { - return Promise.resolve(false); - } - - setAddress(address: string): IProvider { - throw new Error(notInitializedError(`setAddress with address: ${address}`)); - } - getAddress(): string | undefined { throw new Error(notInitializedError('getAddress')); } From fc64bad66689ec053712ceccff040cb925b66324 Mon Sep 17 00:00:00 2001 From: cipriandraghici Date: Thu, 25 Jul 2024 17:22:22 +0300 Subject: [PATCH 14/15] changelog update --- CHANGELOG.md | 1 + esbuild.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60c08f12..5d64c9fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- [Generic login + ExtensionProvider login](https://github.com/multiversx/mx-sdk-dapp-core/pull/12) - [Make middlewares registration more scalable](https://github.com/multiversx/mx-sdk-dapp-core/pull/11) - [Fix Node Polyfills](https://github.com/multiversx/mx-sdk-dapp-core/pull/10) - [Removed chain id from network slice & added esbuild and absolute imports](https://github.com/multiversx/mx-sdk-dapp-core/pull/3) diff --git a/esbuild.js b/esbuild.js index 4e22a75d..3571c623 100644 --- a/esbuild.js +++ b/esbuild.js @@ -25,7 +25,7 @@ const executeBuild = () => format: 'esm', outdir: 'out', treeShaking: true, - minify: true, + minify: false, bundle: true, sourcemap: true, chunkNames: '__chunks__/[name]-[hash]', From a19c0c1f27852abd41f9034a0adb25ab6b3e8c78 Mon Sep 17 00:00:00 2001 From: cipriandraghici Date: Thu, 25 Jul 2024 17:22:53 +0300 Subject: [PATCH 15/15] revert minify value --- esbuild.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esbuild.js b/esbuild.js index 3571c623..4e22a75d 100644 --- a/esbuild.js +++ b/esbuild.js @@ -25,7 +25,7 @@ const executeBuild = () => format: 'esm', outdir: 'out', treeShaking: true, - minify: false, + minify: true, bundle: true, sourcemap: true, chunkNames: '__chunks__/[name]-[hash]',