Skip to content

Commit db06dfd

Browse files
committed
chore: improve code and replace test
1 parent 1004500 commit db06dfd

File tree

7 files changed

+308
-252
lines changed

7 files changed

+308
-252
lines changed

cypress/e2e/contracts/erc20.spec.ts

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ describe('ERC20 Contract ', () => {
2323
});
2424

2525
it('contract file uploads', () => {
26-
// TODO: In the contract, replaced Address with H160. Fix https://github.com/use-ink/contracts-ui/issues/582
2726
assertUpload('erc20.contract');
2827
});
2928

@@ -54,54 +53,30 @@ describe('ERC20 Contract ', () => {
5453

5554
it(`transfers ${transferValue} Units to another account`, () => {
5655
selectMessage('transfer', 3);
57-
cy.get('.form-field.to')
58-
.find("input[type='text']")
59-
.clear()
60-
.type('0x60afa252b554aabc4b3253ca2be60dc1d536ec10')
61-
.should('have.value', '0x60afa252b554aabc4b3253ca2be60dc1d536ec10');
56+
cy.get('.form-field.to').find('.dropdown').click().find('.dropdown__option').eq(3).click();
6257
cy.get('.form-field.value').find('input[type="number"]').type(`${transferValue}`);
6358
assertCall();
6459
selectMessage('balanceOf', 1);
6560

66-
cy.get('.form-field.owner')
67-
.find("input[type='text']")
68-
.clear()
69-
.type('0x9621dde636de098b43efb0fa9b61facfe328f99d')
70-
.should('have.value', '0x9621dde636de098b43efb0fa9b61facfe328f99d');
61+
cy.get('.form-field.owner').find('.dropdown').click().find('.dropdown__option').eq(3).click();
62+
7163
assertReturnValue('balanceOf', `${initialSupply - transferValue}`);
7264
});
7365

7466
it(`successfully approves allowance`, () => {
7567
selectMessage('approve', 4);
76-
cy.get('.form-field.spender')
77-
.find("input[type='text']")
78-
.clear()
79-
.type('0x41dccbd49b26c50d34355ed86ff0fa9e489d1e01')
80-
.should('have.value', '0x41dccbd49b26c50d34355ed86ff0fa9e489d1e01');
68+
cy.get('.form-field.spender').find('.dropdown').click().find('.dropdown__option').eq(2).click();
8169
cy.get('.form-field.value').find('input[type="number"]').type(`${allowance}`);
8270
assertCall();
8371
selectMessage('allowance', 2);
84-
cy.get('.form-field.owner')
85-
.find("input[type='text']")
86-
.clear()
87-
.type('0x9621dde636de098b43efb0fa9b61facfe328f99d')
88-
.should('have.value', '0x9621dde636de098b43efb0fa9b61facfe328f99d');
89-
cy.get('.form-field.spender')
90-
.find("input[type='text']")
91-
.clear()
92-
.type('0x41dccbd49b26c50d34355ed86ff0fa9e489d1e01')
93-
.should('have.value', '0x41dccbd49b26c50d34355ed86ff0fa9e489d1e01');
72+
cy.get('.form-field.spender').find('.dropdown').click().find('.dropdown__option').eq(2).click();
9473
assertReturnValue('allowance', `${allowance}`);
9574
});
9675

9776
it(`transfers ${transferValue} on behalf of alice`, () => {
9877
cy.get('.form-field.caller').click().find('.dropdown__option').eq(2).click();
9978
selectMessage('transferFrom', 5);
100-
cy.get('.form-field.from')
101-
.find("input[type='text']")
102-
.clear()
103-
.type('0x9621dde636de098b43efb0fa9b61facfe328f99d')
104-
.should('have.value', '0x9621dde636de098b43efb0fa9b61facfe328f99d');
79+
cy.get('.form-field.to').find('.dropdown').click().find('.dropdown__option').eq(2).click();
10580
cy.get('.form-field.to')
10681
.find("input[type='text']")
10782
.clear()
@@ -110,11 +85,7 @@ describe('ERC20 Contract ', () => {
11085
cy.get('.form-field.value').find('input[type="number"]').type(`${transferValue}`);
11186
assertCall();
11287
selectMessage('balanceOf', 1);
113-
cy.get('.form-field.owner')
114-
.find("input[type='text']")
115-
.clear()
116-
.type('0x41dccbd49b26c50d34355ed86ff0fa9e489d1e01')
117-
.should('have.value', '0x41dccbd49b26c50d34355ed86ff0fa9e489d1e01');
88+
cy.get('.form-field.owner').find('.dropdown').click().find('.dropdown__option').eq(2).click();
11889
assertReturnValue('balanceOf', `${transferValue}`);
11990
});
12091
});

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
"dependencies": {
3434
"@headlessui/react": "^1.7.18",
3535
"@heroicons/react": "^1.0.6",
36-
"@polkadot/api": "^16.4.1",
37-
"@polkadot/api-contract": "^16.4.1",
36+
"@polkadot/api": "^16.4.7",
37+
"@polkadot/api-contract": "^16.4.7",
3838
"@polkadot/extension-dapp": "^0.58.6",
39-
"@polkadot/types": "^16.4.1",
39+
"@polkadot/types": "^16.4.7",
4040
"@polkadot/ui-keyring": "^3.12.2",
4141
"@polkadot/ui-shared": "^3.12.2",
4242
"big.js": "^6.2.1",

src/lib/callOptions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ export function transformUserInput(
6666
if (type === 'U256') {
6767
return registry.createType('U256', value);
6868
}
69+
// TODO: CHeck this, not getting value for Address.
70+
// if (type === 'Address') {
71+
// return registry.createType('H160', value);
72+
// }
6973

7074
return value;
7175
});

src/ui/components/account/Select.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,9 @@ function Select({
4343

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

4847
return (
49-
<Select
50-
options={createAccountOptions(accounts || [], version)}
51-
placeholder={placeholder}
52-
{...props}
53-
/>
48+
<Select options={createAccountOptions(accounts || [])} placeholder={placeholder} {...props} />
5449
);
5550
}
5651

@@ -79,7 +74,7 @@ export function AddressSelect({ placeholder = 'Select account', onChange, ...pro
7974
})),
8075
},
8176
];
82-
}, [accounts, contracts, recent]);
77+
}, [accounts, contracts, recent, version]);
8378

8479
const handleCreate = (inputValue: string) => {
8580
setRecent([...recent, { label: inputValue, value: inputValue }]);

src/ui/components/form/findComponent.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export function findComponent(
131131
switch (type.type) {
132132
case 'AccountId':
133133
case 'Address':
134+
case 'H160':
134135
return AddressSelect;
135136

136137
case 'Balance':

src/ui/util/dropdown.tsx

Lines changed: 10 additions & 5 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 { decodeAddress } from '@polkadot/keyring';
45
import { InkVersion } from 'ui/contexts';
56
import { MessageSignature } from '../components/message/MessageSignature';
67
import {
@@ -35,12 +36,16 @@ export function createMessageOptions(
3536

3637
export function createAccountOptions(
3738
data: Account[],
38-
version: InkVersion,
39+
version?: InkVersion,
3940
): DropdownOption<string>[] {
40-
return data.map(pair => ({
41-
label: pair.meta?.name as string,
42-
value: (version === 'v6' ? toEthAddress(pair.address) : pair.address) || '',
43-
}));
41+
return data.map(pair => {
42+
const address = version === 'v6' ? toEthAddress(decodeAddress(pair.address)) : pair.address;
43+
44+
return {
45+
label: pair.meta?.name as string,
46+
value: address || '',
47+
};
48+
});
4449
}
4550

4651
export function createContractOptions(data: ContractDocument[]): DropdownOption<string>[] {

0 commit comments

Comments
 (0)