Skip to content

Commit

Permalink
Fix ledger issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mgavrila committed Jan 16, 2025
1 parent 20acb9b commit 2ac6fdd
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,17 @@ export type FungibleTransactionType = {
};

export type TokenType =
| 'MetaESDT'
| 'SemiFungibleESDT'
| 'NonFungibleESDT'
| 'FungibleESDT'
| null;
| 'FungibleESDT';

export interface ISignTransactionsModalData {
shouldClose?: true;
commonData: {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,55 +68,51 @@ export class LedgerProviderStrategy {
public createProvider = async (): Promise<IProvider> => {
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<ReturnType<typeof getLedgerProvider>>) => 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<ReturnType<typeof getLedgerProvider>>
>(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<ReturnType<typeof getLedgerProvider>>
>((resolve, reject) => buildLedgerProvider(resolve, reject));

this.config = ledgerConfig;
this.provider = ledgerProvider;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const getAuthTokenText = ({
loginToken?: string;
version?: string;
}) => {
console.log({ loginToken, version });
if (!loginToken || !version) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 2ac6fdd

Please sign in to comment.