Skip to content
This repository was archived by the owner on Sep 25, 2025. It is now read-only.

Commit a72a674

Browse files
committed
solution: create shadow entry when adding new coin
1 parent 7d13a8b commit a72a674

2 files changed

Lines changed: 39 additions & 11 deletions

File tree

packages/react-app/src/create-wallet/CreateWalletScreen.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { connect } from 'react-redux';
1616
import CreateWalletWizard from './CreateWalletWizard';
1717
import { Result, isLedger, isPk, isPkJson, isPkRaw, isSeedCreate, isSeedSelected } from './flow/types';
1818

19-
type NewEntry = AddEntry & { additional: boolean };
19+
type NewEntry = AddEntry & { shadow: boolean };
2020

2121
type StateProps = {
2222
blockchains: IBlockchain[];
@@ -39,7 +39,7 @@ function entriesForBlockchains(
3939
indexes: HDPathIndexes,
4040
): NewEntry[] {
4141
const entries = blockchains.map<NewEntry>((blockchain) => ({
42-
additional: false,
42+
shadow: false,
4343
blockchain: blockchainCodeToId(blockchain),
4444
key: {
4545
address: addresses[blockchain],
@@ -62,7 +62,7 @@ function entriesForBlockchains(
6262
if (entry != null) {
6363
additionalEntries.push({
6464
...entry,
65-
additional: true,
65+
shadow: true,
6666
blockchain: blockchainCodeToId(blockchain === BlockchainCode.ETC ? BlockchainCode.ETH : BlockchainCode.ETC),
6767
});
6868
}
@@ -129,7 +129,7 @@ export default connect(
129129

130130
entries.push({
131131
...pkEntry,
132-
additional: false,
132+
shadow: false,
133133
blockchain: blockchainCodeToId(blockchainCode),
134134
});
135135
} else if (isPkRaw(type)) {
@@ -143,7 +143,7 @@ export default connect(
143143

144144
entries.push({
145145
...pkEntry,
146-
additional: false,
146+
shadow: false,
147147
blockchain: blockchainCodeToId(blockchainCode),
148148
});
149149
}
@@ -156,7 +156,7 @@ export default connect(
156156
entries.push({
157157
...pkEntry,
158158
blockchain,
159-
additional: true,
159+
shadow: true,
160160
});
161161
}
162162
} else if (isLedger(type)) {
@@ -171,8 +171,8 @@ export default connect(
171171
exactEntries: AddEntry[];
172172
receiveDisabled: Array<{ blockchain: number; address?: string }>;
173173
}>(
174-
(carry, { additional, ...entry }) => {
175-
if (additional) {
174+
(carry, { shadow, ...entry }) => {
175+
if (shadow) {
176176
return {
177177
exactEntries: [...carry.exactEntries, entry],
178178
receiveDisabled: [

packages/store/src/accounts/sagas.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from '@emeraldpay/emerald-vault-core';
99
import { BitcoinEntry, isBitcoinEntry, isEthereumEntry } from '@emeraldpay/emerald-vault-core/lib/types';
1010
import {
11+
BlockchainCode,
1112
Blockchains,
1213
IpcCommands,
1314
PersistentState,
@@ -204,14 +205,41 @@ function* createHdAddress(vault: IEmeraldVault, action: ICreateHdEntry): SagaIte
204205
return;
205206
}
206207

207-
ipcRenderer.send(IpcCommands.BALANCE_SUBSCRIBE, blockchain, entry.id, [entry.address.value]);
208-
209208
const tokenRegistry = new TokenRegistry(action.tokens);
210209

211210
const tokens = tokenRegistry.byBlockchain(blockchain);
212211

213-
yield put(requestTokensBalances(blockchain, tokens, entry.address.value));
212+
if (blockchain === BlockchainCode.ETC || blockchain === BlockchainCode.ETH) {
213+
const addShadowEntry = {
214+
...addEntry,
215+
blockchain: blockchainCodeToId(blockchain === BlockchainCode.ETH ? BlockchainCode.ETC : BlockchainCode.ETH),
216+
};
217+
218+
const shadowEntryId = yield call(vault.addEntry, walletId, addShadowEntry);
219+
220+
yield call(vault.setEntryReceiveDisabled, shadowEntryId, true);
221+
222+
wallet = yield call(vault.getWallet, walletId);
223+
224+
const shadowEntry = wallet.entries.find(({ id }) => id === shadowEntryId);
225+
226+
if (shadowEntry?.address?.value != null) {
227+
const { value: shadowAddress } = shadowEntry.address;
228+
229+
ipcRenderer.send(IpcCommands.BALANCE_SUBSCRIBE, blockchain, shadowEntryId, [shadowAddress]);
230+
231+
yield put(requestTokensBalances(blockchain, tokens, shadowAddress));
232+
yield put(hdAccountCreated(wallet.id, shadowEntry));
233+
}
234+
}
235+
236+
const { value: entryAddress } = entry.address;
237+
238+
ipcRenderer.send(IpcCommands.BALANCE_SUBSCRIBE, blockchain, entry.id, [entryAddress]);
239+
240+
yield put(requestTokensBalances(blockchain, tokens, entryAddress));
214241
yield put(hdAccountCreated(wallet.id, entry));
242+
215243
yield put(screen.actions.gotoScreen(screen.Pages.WALLET, wallet.id));
216244
} catch (error) {
217245
if (error instanceof Error) {

0 commit comments

Comments
 (0)