Skip to content

Commit 4d9c2f6

Browse files
authored
Add Chain type in textfield (#859)
* add chain type in title of textField * add dropdownList * handle colors in dark mode and use ChainType not string * handle case of adding existing contact or wallet * fix adding tfchain contact bug * fix filter on contacts list when sending * update ui only if adding contact of same contacts type
1 parent d379ad6 commit 4d9c2f6

3 files changed

Lines changed: 60 additions & 25 deletions

File tree

app/lib/screens/wallets/contacts.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,12 @@ class _ContactsScreenState extends State<ContactsScreen> {
2828

2929
_loadMyWalletContacts() {
3030
for (final w in widget.wallets) {
31-
if (widget.chainType == ChainType.Stellar) {
31+
if (double.parse(w.stellarBalance) >= 0) {
3232
myWalletContacts.add(PkidContact(
3333
name: w.name, address: w.stellarAddress, type: ChainType.Stellar));
3434
}
35-
if (widget.chainType == ChainType.TFChain) {
36-
myWalletContacts.add(PkidContact(
37-
name: w.name, address: w.tfchainAddress, type: ChainType.TFChain));
38-
}
35+
myWalletContacts.add(PkidContact(
36+
name: w.name, address: w.tfchainAddress, type: ChainType.TFChain));
3937
}
4038
}
4139

@@ -144,7 +142,7 @@ class _ContactsScreenState extends State<ContactsScreen> {
144142
ContactsWidget(
145143
contacts: myWalletContacts
146144
.where(
147-
(c) => c.address != widget.currentWalletAddress)
145+
(c) => c.address != widget.currentWalletAddress && c.type == widget.chainType)
148146
.toList(),
149147
onSelectToAddress: widget.onSelectToAddress),
150148
ContactsWidget(

app/lib/screens/wallets/send.dart

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,7 @@ class _WalletSendScreenState extends ConsumerState<WalletSendScreen> {
268268
chainType: chainType,
269269
currentWalletAddress:
270270
fromController.text,
271-
wallets: chainType == ChainType.Stellar
272-
? wallets
273-
.where((w) =>
274-
double.parse(
275-
w.stellarBalance) >=
276-
0)
277-
.toList()
278-
: wallets,
271+
wallets: wallets,
279272
onSelectToAddress: _selectToAddress),
280273
));
281274
},

app/lib/widgets/wallets/add_edit_contact.dart

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class _AddEditContactState extends State<AddEditContact> {
3939
bool saveLoading = false;
4040
String? nameError;
4141
String? addressError;
42+
ChainType? _selectedChainType;
4243
Future<void> _showDialog(
4344
String title, String message, IconData icon, DialogType type) async {
4445
showDialog(
@@ -94,11 +95,12 @@ class _AddEditContactState extends State<AddEditContact> {
9495

9596
return false;
9697
}
97-
if (widget.chainType == ChainType.TFChain && contactAddress.length != 48) {
98+
if (_selectedChainType == ChainType.TFChain &&
99+
contactAddress.length != 48) {
98100
addressError = 'Address length should be 48 characters';
99101
return false;
100102
}
101-
if (widget.chainType == ChainType.Stellar &&
103+
if (_selectedChainType == ChainType.Stellar &&
102104
!isValidStellarAddress(contactAddress)) {
103105
addressError = 'Invaild Stellar address';
104106
return false;
@@ -107,8 +109,11 @@ class _AddEditContactState extends State<AddEditContact> {
107109
}
108110

109111
_add(String contactName, String contactAddress) async {
112+
final chainType = _selectedChainType == ChainType.Stellar
113+
? ChainType.Stellar
114+
: ChainType.TFChain;
110115
try {
111-
await addContact(contactName, contactAddress, widget.chainType);
116+
await addContact(contactName, contactAddress, chainType);
112117
await _showDialog(
113118
'Contact Added!',
114119
'Contact $contactName has been added successfully',
@@ -120,8 +125,10 @@ class _AddEditContactState extends State<AddEditContact> {
120125
Icons.error, DialogType.Error);
121126
return;
122127
}
123-
widget.onAddContact!(PkidContact(
124-
name: contactName, address: contactAddress, type: widget.chainType));
128+
if (chainType == widget.chainType) {
129+
widget.onAddContact!(PkidContact(
130+
name: contactName, address: contactAddress, type: chainType));
131+
}
125132
if (!context.mounted) return;
126133
Navigator.pop(context);
127134
}
@@ -183,6 +190,7 @@ class _AddEditContactState extends State<AddEditContact> {
183190
_nameController.text = widget.name;
184191
_addressController.text = widget.address;
185192
}
193+
_selectedChainType = widget.chainType;
186194
super.initState();
187195
}
188196

@@ -232,9 +240,47 @@ class _AddEditContactState extends State<AddEditContact> {
232240
),
233241
controller: _addressController,
234242
),
235-
const SizedBox(
236-
height: 30,
237-
),
243+
const SizedBox(height: 20),
244+
if (widget.operation == ContactOperation.Add)
245+
Row(
246+
children: [
247+
Text(
248+
'Chain Type:',
249+
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
250+
color: Theme.of(context).colorScheme.onSurface,
251+
decorationColor:
252+
Theme.of(context).colorScheme.onSurface),
253+
),
254+
const SizedBox(width: 10),
255+
DropdownButton<ChainType>(
256+
value: _selectedChainType,
257+
onChanged: (ChainType? newValue) {
258+
setState(() {
259+
_selectedChainType = newValue!;
260+
});
261+
},
262+
items: ChainType.values
263+
.map<DropdownMenuItem<ChainType>>((ChainType type) {
264+
return DropdownMenuItem<ChainType>(
265+
value: type,
266+
child: Text(
267+
type.name,
268+
style: Theme.of(context)
269+
.textTheme
270+
.bodyMedium!
271+
.copyWith(
272+
color:
273+
Theme.of(context).colorScheme.onSurface,
274+
decorationColor:
275+
Theme.of(context).colorScheme.onSurface,
276+
),
277+
),
278+
);
279+
}).toList(),
280+
),
281+
],
282+
),
283+
const SizedBox(height: 30),
238284
Row(
239285
children: [
240286
const Spacer(),
@@ -244,9 +290,7 @@ class _AddEditContactState extends State<AddEditContact> {
244290
Navigator.pop(context);
245291
},
246292
child: const Text('Close')),
247-
const SizedBox(
248-
width: 5,
249-
),
293+
const SizedBox(width: 5),
250294
ElevatedButton(
251295
onPressed: widget.operation == ContactOperation.Add
252296
? _validateAndAdd

0 commit comments

Comments
 (0)