Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions app/lib/screens/wallets/contacts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ class _ContactsScreenState extends State<ContactsScreen> {

_loadMyWalletContacts() {
for (final w in widget.wallets) {
if (widget.chainType == ChainType.Stellar) {
if (double.parse(w.stellarBalance) >= 0) {
myWalletContacts.add(PkidContact(
name: w.name, address: w.stellarAddress, type: ChainType.Stellar));
}
if (widget.chainType == ChainType.TFChain) {
myWalletContacts.add(PkidContact(
name: w.name, address: w.tfchainAddress, type: ChainType.TFChain));
}
myWalletContacts.add(PkidContact(
name: w.name, address: w.tfchainAddress, type: ChainType.TFChain));
}
}

Expand Down Expand Up @@ -144,7 +142,7 @@ class _ContactsScreenState extends State<ContactsScreen> {
ContactsWidget(
contacts: myWalletContacts
.where(
(c) => c.address != widget.currentWalletAddress)
(c) => c.address != widget.currentWalletAddress && c.type == widget.chainType)
.toList(),
onSelectToAddress: widget.onSelectToAddress),
ContactsWidget(
Expand Down
9 changes: 1 addition & 8 deletions app/lib/screens/wallets/send.dart
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,7 @@ class _WalletSendScreenState extends ConsumerState<WalletSendScreen> {
chainType: chainType,
currentWalletAddress:
fromController.text,
wallets: chainType == ChainType.Stellar
? wallets
.where((w) =>
double.parse(
w.stellarBalance) >=
0)
.toList()
: wallets,
wallets: wallets,
onSelectToAddress: _selectToAddress),
));
},
Expand Down
66 changes: 55 additions & 11 deletions app/lib/widgets/wallets/add_edit_contact.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class _AddEditContactState extends State<AddEditContact> {
bool saveLoading = false;
String? nameError;
String? addressError;
ChainType? _selectedChainType;
Future<void> _showDialog(
String title, String message, IconData icon, DialogType type) async {
showDialog(
Expand Down Expand Up @@ -94,11 +95,12 @@ class _AddEditContactState extends State<AddEditContact> {

return false;
}
if (widget.chainType == ChainType.TFChain && contactAddress.length != 48) {
if (_selectedChainType == ChainType.TFChain &&
contactAddress.length != 48) {
addressError = 'Address length should be 48 characters';
return false;
}
if (widget.chainType == ChainType.Stellar &&
if (_selectedChainType == ChainType.Stellar &&
!isValidStellarAddress(contactAddress)) {
addressError = 'Invaild Stellar address';
return false;
Expand All @@ -107,8 +109,11 @@ class _AddEditContactState extends State<AddEditContact> {
}

_add(String contactName, String contactAddress) async {
final chainType = _selectedChainType == ChainType.Stellar
? ChainType.Stellar
: ChainType.TFChain;
try {
await addContact(contactName, contactAddress, widget.chainType);
await addContact(contactName, contactAddress, chainType);
await _showDialog(
'Contact Added!',
'Contact $contactName has been added successfully',
Expand All @@ -120,8 +125,10 @@ class _AddEditContactState extends State<AddEditContact> {
Icons.error, DialogType.Error);
return;
}
widget.onAddContact!(PkidContact(
name: contactName, address: contactAddress, type: widget.chainType));
if (chainType == widget.chainType) {
widget.onAddContact!(PkidContact(
name: contactName, address: contactAddress, type: chainType));
}
if (!context.mounted) return;
Navigator.pop(context);
}
Expand Down Expand Up @@ -183,6 +190,7 @@ class _AddEditContactState extends State<AddEditContact> {
_nameController.text = widget.name;
_addressController.text = widget.address;
}
_selectedChainType = widget.chainType;
super.initState();
}

Expand Down Expand Up @@ -232,9 +240,47 @@ class _AddEditContactState extends State<AddEditContact> {
),
controller: _addressController,
),
const SizedBox(
height: 30,
),
const SizedBox(height: 20),
if (widget.operation == ContactOperation.Add)
Row(
children: [
Text(
'Chain Type:',
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
color: Theme.of(context).colorScheme.onSurface,
decorationColor:
Theme.of(context).colorScheme.onSurface),
),
const SizedBox(width: 10),
DropdownButton<ChainType>(
value: _selectedChainType,
onChanged: (ChainType? newValue) {
setState(() {
_selectedChainType = newValue!;
});
},
items: ChainType.values
.map<DropdownMenuItem<ChainType>>((ChainType type) {
return DropdownMenuItem<ChainType>(
value: type,
child: Text(
type.name,
style: Theme.of(context)
.textTheme
.bodyMedium!
.copyWith(
color:
Theme.of(context).colorScheme.onSurface,
decorationColor:
Theme.of(context).colorScheme.onSurface,
),
),
);
}).toList(),
),
],
),
const SizedBox(height: 30),
Row(
children: [
const Spacer(),
Expand All @@ -244,9 +290,7 @@ class _AddEditContactState extends State<AddEditContact> {
Navigator.pop(context);
},
child: const Text('Close')),
const SizedBox(
width: 5,
),
const SizedBox(width: 5),
ElevatedButton(
onPressed: widget.operation == ContactOperation.Add
? _validateAndAdd
Expand Down