Skip to content

Commit 1004500

Browse files
committed
fix: display address as H160 for inkv6
1 parent af82926 commit 1004500

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/ui/components/account/Select.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Dropdown } from '../common/Dropdown';
77
import { Account } from './Account';
88
import { createAccountOptions } from 'ui/util/dropdown';
99
import type { DropdownOption, DropdownProps, ValidFormField } from 'types';
10-
import { useApi, useDatabase } from 'ui/contexts';
10+
import { useApi, useDatabase, useVersion } from 'ui/contexts';
1111
import { classes } from 'lib/util';
1212
import { useDbQuery } from 'ui/hooks';
1313

@@ -43,15 +43,21 @@ function Select({
4343

4444
export function AccountSelect({ placeholder = 'Select account', ...props }: Props) {
4545
const { accounts } = useApi();
46+
const { version } = useVersion();
4647

4748
return (
48-
<Select options={createAccountOptions(accounts || [])} placeholder={placeholder} {...props} />
49+
<Select
50+
options={createAccountOptions(accounts || [], version)}
51+
placeholder={placeholder}
52+
{...props}
53+
/>
4954
);
5055
}
5156

5257
export function AddressSelect({ placeholder = 'Select account', onChange, ...props }: Props) {
5358
const { accounts } = useApi();
5459
const { db } = useDatabase();
60+
const { version } = useVersion();
5561
const [contracts] = useDbQuery(() => db.contracts.toArray(), [db]);
5662
const [recent, setRecent] = useState<DropdownOption<string>[]>([]);
5763

@@ -63,7 +69,7 @@ export function AddressSelect({ placeholder = 'Select account', onChange, ...pro
6369
},
6470
{
6571
label: 'My Accounts',
66-
options: createAccountOptions(accounts || []),
72+
options: createAccountOptions(accounts || [], version),
6773
},
6874
{
6975
label: 'Uploaded Contracts',

src/ui/util/dropdown.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2022-2024 use-ink/contracts-ui authors & contributors
22
// SPDX-License-Identifier: GPL-3.0-only
33

4+
import { InkVersion } from 'ui/contexts';
45
import { MessageSignature } from '../components/message/MessageSignature';
56
import {
67
AbiConstructor,
@@ -10,6 +11,7 @@ import {
1011
Registry,
1112
Account,
1213
} from 'types';
14+
import { toEthAddress } from 'lib/address';
1315

1416
export function createConstructorOptions(
1517
registry: Registry,
@@ -31,10 +33,13 @@ export function createMessageOptions(
3133
}));
3234
}
3335

34-
export function createAccountOptions(data: Account[]): DropdownOption<string>[] {
36+
export function createAccountOptions(
37+
data: Account[],
38+
version: InkVersion,
39+
): DropdownOption<string>[] {
3540
return data.map(pair => ({
3641
label: pair.meta?.name as string,
37-
value: pair.address || '',
42+
value: (version === 'v6' ? toEthAddress(pair.address) : pair.address) || '',
3843
}));
3944
}
4045

0 commit comments

Comments
 (0)