Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanA101a committed Jul 3, 2023
1 parent 8a6d9fa commit c0b4c8f
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 151 deletions.
2 changes: 2 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:label="batua"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">

<activity
android:name=".MainActivity"
android:exported="true"
Expand Down
5 changes: 3 additions & 2 deletions lib/exceptions/app_exceptions.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
enum AppEType { somethingElse }
enum AppEType { somethingElse, empty }

class AppException {
AppException(this.eType) : _message = _setMessage(eType);
Expand All @@ -9,7 +9,8 @@ class AppException {

static String _setMessage(AppEType eType) {
switch (eType) {

case AppEType.empty:
return "Empty";
case AppEType.somethingElse:
return "Something went wrong!";
}
Expand Down
4 changes: 2 additions & 2 deletions lib/models/mined_transaction_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ class MinedTransaction {
MinedTransaction(
blockHash: json["blockHash"],
blockNumber: json["blockNumber"],
from: json["from"],
from: json["from"].substring(2),
gas: json["gas"],
gasPrice: json["gasPrice"],
maxFeePerGas: json["maxFeePerGas"],
maxPriorityFeePerGas: json["maxPriorityFeePerGas"],
hash: json["hash"],
input: json["input"],
nonce: json["nonce"],
to: json["to"],
to: json["to"].substring(2),
transactionIndex: json["transactionIndex"],
value: json["value"],
type: json["type"],
Expand Down
149 changes: 81 additions & 68 deletions lib/pages/homePage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,78 +64,91 @@ class TokensSectionWidget extends StatelessWidget {
Widget build(BuildContext context) {
List<Token> tokens = context.select<HomePageUiHelper, List<Token>>(
(value) => value.tokens.values.toList());
if (tokens.isNotEmpty) {
return Container(
margin: const EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: Colors.grey.shade200),
child: ListView.separated(
shrinkWrap: true,
itemCount: tokens.length,
separatorBuilder: (context, index) => Divider(
indent: 5,
endIndent: 5,
),
itemBuilder: (context, index) {
// log(tokens[index].logo.toString());
return Container(
margin: EdgeInsets.all(6),
child: ListTile(
onTap: () => Navigator.pushNamed(context, TokenInfoPage.route,
arguments: (
logo: tokens[index].logo,
name: tokens[index].name,
symbol: tokens[index].symbol,
)),
tileColor: Colors.transparent,
leading: tokens[index].logo == null
? CircleAvatar(
backgroundColor: Colors.white,
child: FittedBox(
child: Padding(
padding: EdgeInsets.all(2.0),
child: Text(
tokens[index].symbol,
style: TextStyle(fontWeight: FontWeight.bold),
),
bool loading =
context.select<HomePageUiHelper, bool>((value) => value.loadingTokens);
if (loading) {
return Shimmer.fromColors(
child: Container(
margin: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.grey.shade200,
borderRadius: BorderRadius.circular(12),
)),
baseColor: Colors.grey.shade200,
highlightColor: Colors.white);
}

return Container(
margin: const EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: Colors.grey.shade200),
child: tokens.isEmpty
? const Center(
child: Text(
"No Tokens",
style: TextStyle(fontSize: 20, color: Colors.black),
),
)
: ListView.separated(
shrinkWrap: true,
itemCount: tokens.length,
separatorBuilder: (context, index) => Divider(
indent: 5,
endIndent: 5,
),
itemBuilder: (context, index) {
// log(tokens[index].logo.toString());
return Container(
margin: EdgeInsets.all(6),
child: ListTile(
onTap: () => Navigator.pushNamed(
context, TokenInfoPage.route,
arguments: (
logo: tokens[index].logo,
name: tokens[index].name,
symbol: tokens[index].symbol,
)),
)
: CircleAvatar(
backgroundColor: Colors.white,
backgroundImage: NetworkImage(tokens[index].logo!),
tileColor: Colors.transparent,
leading: tokens[index].logo == null
? CircleAvatar(
backgroundColor: Colors.white,
child: FittedBox(
child: Padding(
padding: EdgeInsets.all(2.0),
child: Text(
tokens[index].symbol,
style: TextStyle(fontWeight: FontWeight.bold),
),
)),
)
: CircleAvatar(
backgroundColor: Colors.white,
backgroundImage:
NetworkImage(tokens[index].logo!),
),
title: Text(
tokens[index].name,
style: const TextStyle(
color: Colors.black,
overflow: TextOverflow.ellipsis),
),
subtitle: Text(tokens[index].symbol),
trailing: Container(
alignment: Alignment.centerRight,
width: MediaQuery.sizeOf(context).width * .3,
child: Text(
tokens[index].amount.toStringAsFixed(4),
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.grey.shade900,
),
),
title: Text(
tokens[index].name,
style: const TextStyle(
color: Colors.black, overflow: TextOverflow.ellipsis),
),
subtitle: Text(tokens[index].symbol),
trailing: Container(
alignment: Alignment.centerRight,
width: MediaQuery.sizeOf(context).width * .3,
child: Text(
tokens[index].amount.toStringAsFixed(4),
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.grey.shade900,
),
),
),
),
);
},
));
}
return Shimmer.fromColors(
child: Container(
margin: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.grey.shade200,
borderRadius: BorderRadius.circular(12),
)),
baseColor: Colors.grey.shade200,
highlightColor: Colors.white);
);
},
));
}
}

Expand Down
4 changes: 1 addition & 3 deletions lib/pages/onboardingPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ class OnboardingPage extends StatelessWidget {
}
}



class ImportAccountBtn extends StatelessWidget {
const ImportAccountBtn({
super.key,
Expand All @@ -82,7 +80,7 @@ class ImportAccountBtn extends StatelessWidget {
shape: MaterialStateProperty.all(
RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))),
),
onPressed: () {},
onPressed: null,
icon: Icon(
Icons.download_rounded,
color: Colors.grey.shade900,
Expand Down
12 changes: 8 additions & 4 deletions lib/pages/transactionHistoryPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,14 @@ class TransactionListWidget extends StatelessWidget {
child: Center(child: Text(exception.message)),
);
}
return Container(
margin: EdgeInsets.all(8.0),
child: const Center(child: CircularProgressIndicator()),
);

if (transactions != null && transactions!.length > 8) {
return Container(
margin: EdgeInsets.all(8.0),
child: const Center(child: CircularProgressIndicator()),
);
}
return Container();
}
},
separatorBuilder: (context, index) => Divider(
Expand Down
5 changes: 4 additions & 1 deletion lib/pages/transactionPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@ class AddressFormFieldDropDown extends StatelessWidget {
.map((String value) {
return PopupMenuItem<String>(
value: value,
child: Text(value),
child: Text(
value,
overflow: TextOverflow.ellipsis,
),
);
}).toList();
},
Expand Down
6 changes: 4 additions & 2 deletions lib/services/account_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ class AccountService {

static Future<void> saveAddress(String myAddress, String address) async {
var box = await Hive.openBox('savedAddresses');
List savedAddresses = box.get(myAddress);
if (!savedAddresses.contains(address)) {
box.put(myAddress, [address, ...savedAddresses]);
}

box.put(myAddress, [address, ...box.get(myAddress)]);
box.close();
}

static Future<List<String>> retrieveSavedAddresses(String address) async {
var box = await Hive.openBox('savedAddresses');

if (!box.containsKey(address)) {
box.put(address, []);
box.close();
Expand Down
33 changes: 20 additions & 13 deletions lib/services/api_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class ApiService {
}
}

static Future<List<TokenModel>?> getErc20Tokens(
static Future<Either<List<TokenModel>,AppException>> getErc20Tokens(
String address, Network network) async {
String path = "/api/v2/0x$address/erc20";
Map<String, String> queryParameters = {};
Expand All @@ -247,20 +247,27 @@ class ApiService {
'X-API-Key': moralisApiKey,
};

final response = await http.get(
Uri.https("deep-index.moralis.io", path, queryParameters),
headers: headers,
);
try {
final response = await http.get(
Uri.https("deep-index.moralis.io", path, queryParameters),
headers: headers,
);

if (response.statusCode == 200) {
var tokensList = json
.decode(response.body)
.map<TokenModel>((e) => TokenModel.fromJson(e))
.toList();
// log(tokensList.toString());
return tokensList;
if (response.statusCode == 200) {
List<TokenModel> tokensList = json
.decode(response.body)
.map<TokenModel>((e) => TokenModel.fromJson(e))
.toList();
// log(tokensList.toString());

return left(tokensList);

}
throw AppException(AppEType.somethingElse);
} catch (e) {
return right(AppException(AppEType.somethingElse));
}
return null;

}

static Future<TokenInfoModel?> getTokenInfo(String tokenSymbol) async {
Expand Down
Loading

0 comments on commit c0b4c8f

Please sign in to comment.