Skip to content

Commit 46e7b0d

Browse files
committed
Merge branch 'accountnumber' into staging-send-to-self-dropdown
2 parents 0cbf149 + fb9e967 commit 46e7b0d

File tree

9 files changed

+42
-34
lines changed

9 files changed

+42
-34
lines changed

backend/handlers/handlers.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,8 @@ type accountJSON struct {
400400
IsToken bool `json:"isToken"`
401401
ActiveTokens []activeToken `json:"activeTokens,omitempty"`
402402
BlockExplorerTxPrefix string `json:"blockExplorerTxPrefix"`
403+
// Number of the account per coin per keystore, starting at 0. Nil if unknown.
404+
AccountNumber *uint16 `json:"accountNumber"`
403405
}
404406

405407
func newAccountJSON(
@@ -410,6 +412,11 @@ func newAccountJSON(
410412
eth, ok := account.Coin().(*eth.Coin)
411413
isToken := ok && eth.ERC20Token() != nil
412414
watch := account.Config().Config.Watch
415+
var accountNumberPtr *uint16
416+
accountNumber, err := account.Config().Config.SigningConfigurations.AccountNumber()
417+
if err == nil {
418+
accountNumberPtr = &accountNumber
419+
}
413420
return &accountJSON{
414421
Keystore: keystoreJSON{
415422
Keystore: keystore,
@@ -426,6 +433,7 @@ func newAccountJSON(
426433
IsToken: isToken,
427434
ActiveTokens: activeTokens,
428435
BlockExplorerTxPrefix: account.Coin().BlockExplorerTransactionURLPrefix(),
436+
AccountNumber: accountNumberPtr,
429437
}
430438
}
431439

backend/signing/configuration.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,15 @@ func (configuration *Configuration) String() string {
202202
// fingerprint.
203203
type Configurations []*Configuration
204204

205+
// AccountNumber returns the first config's account number. It assumes all configurations have the
206+
// same account number.
207+
func (configs Configurations) AccountNumber() (uint16, error) {
208+
for _, config := range configs {
209+
return config.AccountNumber()
210+
}
211+
return 0, errp.New("no configs")
212+
}
213+
205214
// RootFingerprint gets the fingerprint of the first config (assuming that all configurations have
206215
// the same rootFingerprint). Returns an error if the list has no entries or does not contain a
207216
// known config.

backend/signing/configuration_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,20 @@ func TestAccountNumber(t *testing.T) {
148148
require.Error(t, err)
149149
require.Equal(t, uint16(0), num)
150150
}
151+
152+
func TestAccountNumberOnConfigurations(t *testing.T) {
153+
xpub, err := hdkeychain.NewMaster(make([]byte, 32), &chaincfg.TestNet3Params)
154+
require.NoError(t, err)
155+
xpub, err = xpub.Neuter()
156+
require.NoError(t, err)
157+
rootFingerprint := []byte{1, 2, 3, 4}
158+
159+
cfg1 := NewBitcoinConfiguration(
160+
ScriptTypeP2WPKH, rootFingerprint, mustKeypath("m/48'/0'/10'"), xpub)
161+
cfg2 := NewBitcoinConfiguration(
162+
ScriptTypeP2WPKH, rootFingerprint, mustKeypath("m/84'/0'/10'"), xpub)
163+
cfgs := Configurations{cfg1, cfg2}
164+
num, err := cfgs.AccountNumber()
165+
require.NoError(t, err)
166+
require.Equal(t, uint16(10), num)
167+
}

frontends/web/src/api/account.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export interface IAccount {
7474
activeTokens?: IActiveToken[];
7575
blockExplorerTxPrefix: string;
7676
bitsuranceStatus?: TDetailStatus;
77+
accountNumber?: number;
7778
}
7879

7980
export const getAccounts = (): Promise<IAccount[]> => {

frontends/web/src/routes/account/send/components/confirm/confirm.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { useTranslation } from 'react-i18next';
1818
import { CoinCode, ConversionUnit, FeeTargetCode, Fiat, IAccount, TAmountWithConversions } from '@/api/account';
1919
import { UseDisableBackButton } from '@/hooks/backbutton';
2020
import { Amount } from '@/components/amount/amount';
21-
import { customFeeUnit, getAccountNumber } from '@/routes/account/utils';
21+
import { customFeeUnit } from '@/routes/account/utils';
2222
import { View, ViewContent, ViewHeader } from '@/components/view/view';
2323
import { Message } from '@/components/message/message';
2424
import { PointToBitBox02 } from '@/components/icon';
@@ -45,7 +45,6 @@ type TConfirmSendProps = {
4545
selectedUTXOs: TSelectedUTXOs;
4646
coinCode: CoinCode;
4747
transactionDetails: TransactionDetails;
48-
activeAccounts?: IAccount[];
4948
}
5049

5150
type TUTXOsByAddress = {
@@ -60,10 +59,9 @@ export const ConfirmSend = ({
6059
selectedUTXOs,
6160
coinCode,
6261
transactionDetails,
63-
activeAccounts: allAccounts
6462
}: TConfirmSendProps) => {
6563

66-
const { t, i18n } = useTranslation();
64+
const { t } = useTranslation();
6765
const {
6866
proposedFee,
6967
proposedAmount,
@@ -75,14 +73,10 @@ export const ConfirmSend = ({
7573
activeCurrency: fiatUnit
7674
} = transactionDetails;
7775

78-
const receiverAccountNumberAndName = selectedReceiverAccount && allAccounts ?
76+
const receiverAccountNumberAndName = selectedReceiverAccount ?
7977
{
8078
name: selectedReceiverAccount.name,
81-
number: getAccountNumber(
82-
selectedReceiverAccount,
83-
allAccounts,
84-
i18n.language
85-
)
79+
number: selectedReceiverAccount.accountNumber ? selectedReceiverAccount.accountNumber + 1 : null,
8680
}
8781
: undefined;
8882

frontends/web/src/routes/account/send/components/inputs/receiver-address-input.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ export const ReceiverAddressInput = ({
123123
) : (
124124
<ReceiverAddressWrapper
125125
accounts={accountsForReceiverDropdown}
126-
allAccounts={activeAccounts}
127126
error={addressError}
128127
onInputChange={onInputChange}
129128
onAccountChange={onAccountChange}

frontends/web/src/routes/account/send/components/inputs/receiver-address-wrapper.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import { useMountedRef } from '@/hooks/mount';
2727
import { useMediaQuery } from '@/hooks/mediaquery';
2828
import { SpinnerRingAnimated } from '@/components/spinner/SpinnerAnimation';
2929
import { Logo } from '@/components/icon';
30-
import { getAccountNumber } from '@/routes/account/utils';
3130
import receiverStyles from './receiver-address-input.module.css';
3231
import styles from './receiver-address-wrapper.module.css';
3332

@@ -40,7 +39,6 @@ type Props = {
4039

4140
type TReceiverAddressWrapperProps = {
4241
accounts?: IAccount[];
43-
allAccounts?: IAccount[];
4442
error?: string | object;
4543
onInputChange: (value: string) => void;
4644
onAccountChange?: (account: IAccount | null) => void;
@@ -68,24 +66,23 @@ const AccountOption = ({ option, isSelectedValue }: Props) => {
6866

6967
export const ReceiverAddressWrapper = ({
7068
accounts,
71-
allAccounts,
7269
error,
7370
onInputChange,
7471
onAccountChange,
7572
recipientAddress,
7673
children,
7774
}: TReceiverAddressWrapperProps) => {
78-
const { t, i18n } = useTranslation();
75+
const { t } = useTranslation();
7976
const mounted = useMountedRef();
8077
const isMobile = useMediaQuery('(max-width: 768px)');
8178
const [selectedAccount, setSelectedAccount] = useState<TOption<IAccount | null> | null>(null);
8279
const [accountSyncStatus, setAccountSyncStatus] = useState<{ [code: string]: accountApi.IStatus }>({});
8380

8481
const accountOptions: TAccountOption[] = accounts && accounts.length > 0 ? accounts.map(account => {
85-
const accountNumber = getAccountNumber(account, allAccounts || accounts, i18n.language);
82+
const accountNumber = account.accountNumber;
8683

8784
return {
88-
label: `${account.name} ${accountNumber ? `(Account #${accountNumber})` : ''}`,
85+
label: `${account.name} ${accountNumber ? `(Account #${accountNumber + 1})` : ''}`,
8986
value: account,
9087
disabled: !accountSyncStatus[account.code]?.synced
9188
};

frontends/web/src/routes/account/send/send.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,6 @@ export const Send = ({
488488
recipientAddress: recipientInput,
489489
activeCurrency,
490490
}}
491-
activeAccounts={activeAccounts}
492491
/>
493492
{sendResult && (
494493
<SendResult

frontends/web/src/routes/account/utils.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -148,19 +148,3 @@ export const getAccountsPerCoin = (accounts: IAccount[]): TAccountCoinMap => {
148148
return accountPerCoin;
149149
}, {});
150150
};
151-
152-
export const getAccountNumber = (targetAccount: IAccount, allAccounts: IAccount[], language: string): number | null => {
153-
try {
154-
const sameKeystoreAndCoin = allAccounts.filter(account =>
155-
account.keystore.rootFingerprint === targetAccount.keystore.rootFingerprint &&
156-
account.coinCode === targetAccount.coinCode
157-
);
158-
159-
sameKeystoreAndCoin.sort((a, b) => a.code.localeCompare(b.code, language));
160-
const position = sameKeystoreAndCoin.findIndex(account => account.code === targetAccount.code);
161-
return position >= 0 ? position + 1 : null;
162-
} catch (error) {
163-
console.error('Error determining account number:', error);
164-
return null;
165-
}
166-
};

0 commit comments

Comments
 (0)