Skip to content

Commit

Permalink
solution: create shadow entry when adding new coin
Browse files Browse the repository at this point in the history
  • Loading branch information
BOOMER74 committed May 22, 2023
1 parent 7d13a8b commit a72a674
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
16 changes: 8 additions & 8 deletions packages/react-app/src/create-wallet/CreateWalletScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { connect } from 'react-redux';
import CreateWalletWizard from './CreateWalletWizard';
import { Result, isLedger, isPk, isPkJson, isPkRaw, isSeedCreate, isSeedSelected } from './flow/types';

type NewEntry = AddEntry & { additional: boolean };
type NewEntry = AddEntry & { shadow: boolean };

type StateProps = {
blockchains: IBlockchain[];
Expand All @@ -39,7 +39,7 @@ function entriesForBlockchains(
indexes: HDPathIndexes,
): NewEntry[] {
const entries = blockchains.map<NewEntry>((blockchain) => ({
additional: false,
shadow: false,
blockchain: blockchainCodeToId(blockchain),
key: {
address: addresses[blockchain],
Expand All @@ -62,7 +62,7 @@ function entriesForBlockchains(
if (entry != null) {
additionalEntries.push({
...entry,
additional: true,
shadow: true,
blockchain: blockchainCodeToId(blockchain === BlockchainCode.ETC ? BlockchainCode.ETH : BlockchainCode.ETC),
});
}
Expand Down Expand Up @@ -129,7 +129,7 @@ export default connect(

entries.push({
...pkEntry,
additional: false,
shadow: false,
blockchain: blockchainCodeToId(blockchainCode),
});
} else if (isPkRaw(type)) {
Expand All @@ -143,7 +143,7 @@ export default connect(

entries.push({
...pkEntry,
additional: false,
shadow: false,
blockchain: blockchainCodeToId(blockchainCode),
});
}
Expand All @@ -156,7 +156,7 @@ export default connect(
entries.push({
...pkEntry,
blockchain,
additional: true,
shadow: true,
});
}
} else if (isLedger(type)) {
Expand All @@ -171,8 +171,8 @@ export default connect(
exactEntries: AddEntry[];
receiveDisabled: Array<{ blockchain: number; address?: string }>;
}>(
(carry, { additional, ...entry }) => {
if (additional) {
(carry, { shadow, ...entry }) => {
if (shadow) {
return {
exactEntries: [...carry.exactEntries, entry],
receiveDisabled: [
Expand Down
34 changes: 31 additions & 3 deletions packages/store/src/accounts/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '@emeraldpay/emerald-vault-core';
import { BitcoinEntry, isBitcoinEntry, isEthereumEntry } from '@emeraldpay/emerald-vault-core/lib/types';
import {
BlockchainCode,
Blockchains,
IpcCommands,
PersistentState,
Expand Down Expand Up @@ -204,14 +205,41 @@ function* createHdAddress(vault: IEmeraldVault, action: ICreateHdEntry): SagaIte
return;
}

ipcRenderer.send(IpcCommands.BALANCE_SUBSCRIBE, blockchain, entry.id, [entry.address.value]);

const tokenRegistry = new TokenRegistry(action.tokens);

const tokens = tokenRegistry.byBlockchain(blockchain);

yield put(requestTokensBalances(blockchain, tokens, entry.address.value));
if (blockchain === BlockchainCode.ETC || blockchain === BlockchainCode.ETH) {
const addShadowEntry = {
...addEntry,
blockchain: blockchainCodeToId(blockchain === BlockchainCode.ETH ? BlockchainCode.ETC : BlockchainCode.ETH),
};

const shadowEntryId = yield call(vault.addEntry, walletId, addShadowEntry);

yield call(vault.setEntryReceiveDisabled, shadowEntryId, true);

wallet = yield call(vault.getWallet, walletId);

const shadowEntry = wallet.entries.find(({ id }) => id === shadowEntryId);

if (shadowEntry?.address?.value != null) {
const { value: shadowAddress } = shadowEntry.address;

ipcRenderer.send(IpcCommands.BALANCE_SUBSCRIBE, blockchain, shadowEntryId, [shadowAddress]);

yield put(requestTokensBalances(blockchain, tokens, shadowAddress));
yield put(hdAccountCreated(wallet.id, shadowEntry));
}
}

const { value: entryAddress } = entry.address;

ipcRenderer.send(IpcCommands.BALANCE_SUBSCRIBE, blockchain, entry.id, [entryAddress]);

yield put(requestTokensBalances(blockchain, tokens, entryAddress));
yield put(hdAccountCreated(wallet.id, entry));

yield put(screen.actions.gotoScreen(screen.Pages.WALLET, wallet.id));
} catch (error) {
if (error instanceof Error) {
Expand Down

0 comments on commit a72a674

Please sign in to comment.