Skip to content

Commit

Permalink
solution: prepare address only for ledger seed
Browse files Browse the repository at this point in the history
  • Loading branch information
BOOMER74 committed Jun 7, 2023
1 parent d5715df commit 294f3e8
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions packages/store/src/accounts/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function* afterAccountImported(vault: IEmeraldVault, action: IWalletImportedActi
* Create new single-address type of account, with PK from the current seed associated with the wallet
*/
function* createHdAddress(vault: IEmeraldVault, action: ICreateHdEntry): SagaIterator {
const { walletId, blockchain, seedId, seedPassword } = action;
const { walletId, blockchain, seedId } = action;

const chain = Blockchains[blockchain];

Expand Down Expand Up @@ -171,29 +171,34 @@ function* createHdAddress(vault: IEmeraldVault, action: ICreateHdEntry): SagaIte
return;
}

const { seedId: existedSeedId } = hdPathAccount;
const { seedId: accountSeedId } = hdPathAccount;

const blockchainId = blockchainCodeToId(blockchain);
const hdPath = chain.params.hdPath.forAccount(hdPathAccount.accountId).toString();

try {
const { [hdPath]: address } = yield call(
vault.listSeedAddresses,
{
type: 'id',
password: seedPassword,
value: existedSeedId,
},
blockchainId,
[hdPath],
);
const seeds: SeedDescription[] = yield call(vault.listSeeds);

const seed = seeds.find(({ id }) => id === accountSeedId);

let address: string | undefined;

if (address == null) {
console.error(`Cannot find address for seed ${existedSeedId}`);
if (seed?.type === 'ledger') {
try {
({ [hdPath]: address } = yield call(vault.listSeedAddresses, accountSeedId, blockchainId, [hdPath]));

if (address == null) {
console.error(`Cannot find address for seed ${accountSeedId}`);

return;
}
} catch (exception) {
console.error(`Error while getting address for seed ${accountSeedId}:`, exception);

return;
}
}

try {
const addEntry: AddEntry = {
type: 'hd-path',
blockchain: blockchainId,
Expand All @@ -202,8 +207,8 @@ function* createHdAddress(vault: IEmeraldVault, action: ICreateHdEntry): SagaIte
hdPath: hdPath,
seed: {
type: 'id',
password: seedPassword,
value: existedSeedId,
password: action.seedPassword,
value: accountSeedId,
},
},
};
Expand Down

0 comments on commit 294f3e8

Please sign in to comment.