diff --git a/src/core/managers/SignTransactionsStateManager/types/signTransactionsModal.types.ts b/src/core/managers/SignTransactionsStateManager/types/signTransactionsModal.types.ts index 1d3ab1f..75d1edb 100644 --- a/src/core/managers/SignTransactionsStateManager/types/signTransactionsModal.types.ts +++ b/src/core/managers/SignTransactionsStateManager/types/signTransactionsModal.types.ts @@ -11,10 +11,10 @@ export type FungibleTransactionType = { }; export type TokenType = + | 'MetaESDT' | 'SemiFungibleESDT' | 'NonFungibleESDT' - | 'FungibleESDT' - | null; + | 'FungibleESDT'; export interface ISignTransactionsModalData { shouldClose?: true; @@ -22,10 +22,6 @@ export interface ISignTransactionsModalData { receiver?: string; data?: string; transactionsCount: number; - /** - * Token type of the transaction. - * @param {string} `null` - if is EGLD or MultiEsdt transaction. - */ tokenType?: TokenType; egldLabel: string; feeLimit?: string; diff --git a/src/core/providers/strategies/LedgerProviderStrategy/LedgerProviderStrategy.ts b/src/core/providers/strategies/LedgerProviderStrategy/LedgerProviderStrategy.ts index ba2a200..8497e8a 100644 --- a/src/core/providers/strategies/LedgerProviderStrategy/LedgerProviderStrategy.ts +++ b/src/core/providers/strategies/LedgerProviderStrategy/LedgerProviderStrategy.ts @@ -68,55 +68,51 @@ export class LedgerProviderStrategy { public createProvider = async (): Promise => { this.initialize(); await defineCustomElements(safeWindow); + const shouldInitiateLogin = !getIsLoggedIn(); const eventBus = await this.createEventBus(); - if (!eventBus) { - throw new Error(ProviderErrorsEnum.eventBusError); + if (eventBus) { + this.manager = new LedgerConnectStateManager(eventBus); } - const manager = new LedgerConnectStateManager(eventBus); - this.manager = manager; + const buildLedgerProvider = async ( + resolve: (value: Awaited>) => void, + reject: (reason?: string) => void + ) => { + const onRetry = () => buildLedgerProvider(resolve, reject); + const onCancel = () => reject('Device unavailable'); - if (!this.provider) { - const shouldInitiateLogin = !getIsLoggedIn(); - - const { ledgerProvider, ledgerConfig } = await new Promise< - Awaited> - >(async function buildLedgerProvider(resolve, reject) { - const onRetry = () => buildLedgerProvider(resolve, reject); - const onCancel = () => reject('Device unavailable'); + try { + this.manager?.updateAccountScreen({ + isLoading: true + }); - try { - manager?.updateAccountScreen({ - isLoading: true - }); + const data = await getLedgerProvider(); - const data = await getLedgerProvider(); + eventBus?.unsubscribe(LedgerConnectEventsEnum.CONNECT_DEVICE, onRetry); + eventBus?.unsubscribe(LedgerConnectEventsEnum.CLOSE, onCancel); - eventBus?.unsubscribe( - LedgerConnectEventsEnum.CONNECT_DEVICE, - onRetry - ); - eventBus?.unsubscribe(LedgerConnectEventsEnum.CLOSE, onCancel); + resolve(data); + } catch (err) { + if (!shouldInitiateLogin) { + throw err; + } - resolve(data); - } catch (err) { - if (!shouldInitiateLogin) { - throw err; - } + const { errorMessage, defaultErrorMessage } = getLedgerErrorCodes(err); + this.manager?.updateConnectScreen({ + error: errorMessage ?? defaultErrorMessage ?? failInitializeErrorText + }); - const { errorMessage, defaultErrorMessage } = - getLedgerErrorCodes(err); - manager?.updateConnectScreen({ - error: - errorMessage ?? defaultErrorMessage ?? failInitializeErrorText - }); + eventBus?.subscribe(LedgerConnectEventsEnum.CONNECT_DEVICE, onRetry); + eventBus?.subscribe(LedgerConnectEventsEnum.CLOSE, onCancel); + } + }; - eventBus?.subscribe(LedgerConnectEventsEnum.CONNECT_DEVICE, onRetry); - eventBus?.subscribe(LedgerConnectEventsEnum.CLOSE, onCancel); - } - }); + if (!this.provider) { + const { ledgerProvider, ledgerConfig } = await new Promise< + Awaited> + >((resolve, reject) => buildLedgerProvider(resolve, reject)); this.config = ledgerConfig; this.provider = ledgerProvider; @@ -194,6 +190,7 @@ export class LedgerProviderStrategy { callbackUrl?: string; token?: string; }) => { + console.log('OOOOOO', this.provider, { config: this.config }); if (!this.provider || !this.config) { throw new Error(ProviderErrorsEnum.notInitialized); } diff --git a/src/core/providers/strategies/LedgerProviderStrategy/helpers/getAuthTokenText.ts b/src/core/providers/strategies/LedgerProviderStrategy/helpers/getAuthTokenText.ts index 1756d47..8818008 100644 --- a/src/core/providers/strategies/LedgerProviderStrategy/helpers/getAuthTokenText.ts +++ b/src/core/providers/strategies/LedgerProviderStrategy/helpers/getAuthTokenText.ts @@ -10,6 +10,7 @@ export const getAuthTokenText = ({ loginToken?: string; version?: string; }) => { + console.log({ loginToken, version }); if (!loginToken || !version) { return null; } diff --git a/src/core/providers/strategies/helpers/signTransactions/signTransactions.ts b/src/core/providers/strategies/helpers/signTransactions/signTransactions.ts index 542d3ef..40fbf17 100644 --- a/src/core/providers/strategies/helpers/signTransactions/signTransactions.ts +++ b/src/core/providers/strategies/helpers/signTransactions/signTransactions.ts @@ -158,11 +158,16 @@ export async function signTransactions({ }); } + const tokenType = + isNft || type === NftEnumType.MetaESDT + ? type + : EsdtEnumType.FungibleESDT; + const commonData: ISignTransactionsModalData['commonData'] = { receiver: plainTransaction.receiver.toString(), data: currentTransaction.transaction.getData().toString(), egldLabel, - tokenType: isNft ? type : EsdtEnumType.FungibleESDT, + tokenType, feeLimit: feeLimitFormatted, feeInFiatLimit, transactionsCount: allTransactions.length,