Skip to content

Commit

Permalink
fix: web3 browser signing (#2254)
Browse files Browse the repository at this point in the history
Co-authored-by: igroza <[email protected]>
  • Loading branch information
2 people authored and devkudasov committed Jan 14, 2025
1 parent ac6d75e commit faa217a
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/services/sign-json-rpc-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {getRpcProvider} from '@app/helpers/get-rpc-provider';
import {I18N, getText} from '@app/i18n';
import {EstimationVariant} from '@app/models/fee';
import {Provider} from '@app/models/provider';
import {IWalletModel, Wallet} from '@app/models/wallet';
import {IWalletModel, Wallet, WalletModel} from '@app/models/wallet';
import {getDefaultNetwork} from '@app/network';
import {Cosmos} from '@app/services/cosmos';
import {PartialJsonRpcRequest, WalletType} from '@app/types';
Expand All @@ -16,7 +16,6 @@ import {
getSignTypedDataParamsData,
isEthTypedData,
} from '@app/utils';
import {ETH_COIN_TYPE, TRON_COIN_TYPE} from '@app/variables/common';
import {EIP155_SIGNING_METHODS} from '@app/variables/EIP155';

import {Balance} from './balance';
Expand Down Expand Up @@ -91,23 +90,24 @@ export class SignJsonRpcRequest {
request: PartialJsonRpcRequest,
chainId?: number,
) {
let walletModel: WalletModel;
if (typeof wallet === 'string') {
wallet = Wallet.getById(wallet)!;
walletModel = Wallet.getById(wallet)!;
} else {
walletModel = Wallet.getById(wallet.address)!;
}

if (!wallet) {
if (!walletModel) {
throw new Error(getText(I18N.jsonRpcErrorInvalidWallet));
}

const provider =
Provider.getByEthChainId(chainId!) || Provider.selectedProvider;
const instanceProvider = await getProviderInstanceForWallet(
wallet,
walletModel,
false,
provider,
);
Logger.log('Wallet Provider', instanceProvider.constructor.name);
Logger.log('Network Provider', JSON.stringify(provider, null, 2));

if (!instanceProvider) {
throw new Error(getText(I18N.jsonRpcErrorInvalidProvider));
Expand All @@ -117,7 +117,7 @@ export class SignJsonRpcRequest {
? await getRpcProvider(provider)
: getDefaultNetwork();

const path = wallet.path?.replace(TRON_COIN_TYPE, ETH_COIN_TYPE)!;
const path = walletModel.getPath(provider)!;
let result: string | undefined;

switch (request.method) {
Expand Down Expand Up @@ -156,7 +156,7 @@ export class SignJsonRpcRequest {
};

const signedTransaction = await SignJsonRpcRequest.signEIP155Request(
wallet,
walletModel,
signRequest,
chainId,
);
Expand Down Expand Up @@ -238,7 +238,7 @@ export class SignJsonRpcRequest {
throw getSdkError('UNSUPPORTED_METHODS', request.method);
}

if (wallet.type === WalletType.ledgerBt) {
if (walletModel.type === WalletType.ledgerBt) {
hideModal('ledgerAttention');
}

Expand Down

0 comments on commit faa217a

Please sign in to comment.