From 0261ba19dd5d8aac20a9ce6c4e343405f124baa4 Mon Sep 17 00:00:00 2001 From: AhsanRns Date: Wed, 1 May 2024 11:07:34 +0500 Subject: [PATCH 1/2] feat:Add Block slayer items to pylon app --- wallet/lib/model/pylon_items.dart | 124 ++++++++++++++ wallet/lib/pages/home/blockslayer_screen.dart | 151 ++++++++++++++++++ wallet/lib/pages/home/home.dart | 11 +- wallet/lib/pages/home/home_provider.dart | 68 +++++++- .../data_stores/remote_data_store.dart | 27 ++++ .../lib/services/repository/repository.dart | 14 ++ 6 files changed, 392 insertions(+), 3 deletions(-) create mode 100644 wallet/lib/model/pylon_items.dart create mode 100644 wallet/lib/pages/home/blockslayer_screen.dart diff --git a/wallet/lib/model/pylon_items.dart b/wallet/lib/model/pylon_items.dart new file mode 100644 index 0000000000..a4bd0f46d4 --- /dev/null +++ b/wallet/lib/model/pylon_items.dart @@ -0,0 +1,124 @@ +class PylonItems { + final String owner; + final String cookBookId; + final String id; + final String nodeVersion; + final bool tradeAble; + final String lastUpdate; + final String tradePercentage; + final String createdAt; + final String updatedAt; + final String recipeId; + + final List doubles; + final List longs; + final List Strings; + final List transferAmount; + + PylonItems({ + required this.owner, + required this.cookBookId, + required this.id, + required this.nodeVersion, + required this.tradeAble, + required this.lastUpdate, + required this.tradePercentage, + required this.createdAt, + required this.updatedAt, + required this.recipeId, + required this.doubles, + required this.longs, + required this.Strings, + required this.transferAmount, + }); + + factory PylonItems.fromJson(Map json) { + final List doubles = []; + + json["doubles"].map((e) { + final keyValue = KeyValue.fromJson(e as Map); + doubles.add(keyValue); + }).toList(); + + final List longs = []; + + json["longs"].map((e) { + final keyValue = KeyValue.fromJson(e as Map); + longs.add(keyValue); + }).toList(); + + final List Strings = []; + + json["strings"].map((e) { + final keyValue = KeyValue.fromJson(e as Map); + Strings.add(keyValue); + }).toList(); + + final List transferAmount = []; + + json["transfer_fee"].map((e) { + final denomAmount = DenomAmount.fromJson(e as Map); + transferAmount.add(denomAmount); + }).toList(); + + return PylonItems( + owner: json["owner"] as String, + cookBookId: json["cookbook_id"] as String, + id: json["id"] as String, + nodeVersion: json["node_version"] as String, + tradeAble: json["tradeable"] as bool, + lastUpdate: json["last_update"] as String, + tradePercentage: json["trade_percentage"] as String, + createdAt: json["created_at"] as String, + updatedAt: json["updated_at"] as String, + recipeId: json["recipe_id"] as String, + doubles: doubles.toList(), + longs: longs.toList(), + Strings: Strings.toList(), + transferAmount: transferAmount.toList(), + ); + } +} + +class KeyValue { + KeyValue({required this.key, required this.value}); + + final String key; + final String value; + + factory KeyValue.fromJson(Map json) { + return KeyValue(key: json["key"] as String, value: json["value"] as String); + } +} + +class DenomAmount { + final String denom; + final String amount; + + DenomAmount({required this.denom, required this.amount}); + + factory DenomAmount.fromJson(Map json) { + return DenomAmount(denom: json["denom"] as String, amount: json["amount"] as String); + } +} + + +class NonEaselItemModel { + NonEaselItemModel( { + required this.cookBookId, + required this.coins, + required this.currentHp, + required this.shards, + required this.swordLevel, + required this.wins, + required this.maxHp, + }); + + final String cookBookId; + final String coins; + final String currentHp; + final String shards; + final String swordLevel; + final String wins; + final String maxHp; +} \ No newline at end of file diff --git a/wallet/lib/pages/home/blockslayer_screen.dart b/wallet/lib/pages/home/blockslayer_screen.dart new file mode 100644 index 0000000000..6f698ad478 --- /dev/null +++ b/wallet/lib/pages/home/blockslayer_screen.dart @@ -0,0 +1,151 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:provider/provider.dart'; +import 'package:pylons_wallet/model/pylon_items.dart'; +import 'package:pylons_wallet/pages/home/home_provider.dart'; + +final _kItemStyle = TextStyle(color: Colors.black, fontSize: 9.sp); + +final _kHeadingStyle = TextStyle(color: Colors.black, fontSize: 9.sp, fontWeight: FontWeight.bold); + +class BlockSlayerScreen extends StatefulWidget { + const BlockSlayerScreen({super.key}); + + @override + State createState() => _BlockSlayerScreenState(); +} + +class _BlockSlayerScreenState extends State { + @override + void initState() { + super.initState(); + context.read().getPylonList(); + } + + Widget _getRow({required NonEaselItemModel nonEaselItemModel}) { + return Row( + children: [ + Expanded( + child: Text( + nonEaselItemModel.cookBookId, + style: _kItemStyle, + textAlign: TextAlign.center, + )), + Expanded( + child: Text( + nonEaselItemModel.coins, + style: _kItemStyle, + textAlign: TextAlign.center, + )), + Expanded( + child: Text( + nonEaselItemModel.currentHp, + style: _kItemStyle, + textAlign: TextAlign.center, + )), + Expanded( + child: Text( + nonEaselItemModel.maxHp, + style: _kItemStyle, + textAlign: TextAlign.center, + )), + Expanded( + child: Text( + nonEaselItemModel.shards, + style: _kItemStyle, + textAlign: TextAlign.center, + )), + Expanded( + child: Text( + nonEaselItemModel.swordLevel, + style: _kItemStyle, + textAlign: TextAlign.center, + )), + Expanded( + child: Text( + nonEaselItemModel.wins, + style: _kItemStyle, + textAlign: TextAlign.center, + )), + ], + ); + } + + Widget _getRowHeading() { + return Row( + children: [ + Expanded( + child: Text( + "CookBook", + style: _kHeadingStyle, + textAlign: TextAlign.center, + )), + Expanded( + child: Text( + "Coins", + style: _kHeadingStyle, + textAlign: TextAlign.center, + )), + Expanded( + child: Text( + "Hp", + style: _kHeadingStyle, + textAlign: TextAlign.center, + )), + Expanded( + child: Text( + "Max Hp", + style: _kHeadingStyle, + textAlign: TextAlign.center, + )), + Expanded( + child: Text( + "Shards", + style: _kHeadingStyle, + textAlign: TextAlign.center, + )), + Expanded( + child: Text( + "Level", + style: _kHeadingStyle, + textAlign: TextAlign.center, + )), + Expanded( + child: Text( + "Wins", + style: _kHeadingStyle, + textAlign: TextAlign.center, + )), + ], + ); + } + + @override + Widget build(BuildContext context) { + return Consumer(builder: (context, provider, _) { + final noEaselPylonItemList = provider.getNoNEaselItems(); + + return Padding( + padding: EdgeInsets.symmetric(horizontal: 10.w), + child: Column( + children: [ + SizedBox(height: 20.h), + if (noEaselPylonItemList.isNotEmpty) _getRowHeading(), + SizedBox(height: 20.h), + Expanded( + child: ListView.separated( + itemBuilder: (context, index) { + return _getRow(nonEaselItemModel: noEaselPylonItemList[index]); + }, + separatorBuilder: (_, __) => SizedBox( + height: 30.h, + ), + itemCount: noEaselPylonItemList.length, + ), + ), + ], + ), + ); + }); + } +} diff --git a/wallet/lib/pages/home/home.dart b/wallet/lib/pages/home/home.dart index 2f9aa0b687..a8cd050ca1 100644 --- a/wallet/lib/pages/home/home.dart +++ b/wallet/lib/pages/home/home.dart @@ -14,6 +14,7 @@ import 'package:pylons_wallet/components/user_image_widget.dart'; import 'package:pylons_wallet/components/maintenance_mode_widgets.dart'; import 'package:pylons_wallet/gen/assets.gen.dart'; import 'package:pylons_wallet/main_prod.dart'; +import 'package:pylons_wallet/pages/home/blockslayer_screen.dart'; import 'package:pylons_wallet/pages/home/collection_screen/collection_view_model.dart'; import 'package:pylons_wallet/pages/home/home_provider.dart'; import 'package:pylons_wallet/pages/home/widget/pylons_drawer.dart'; @@ -46,7 +47,7 @@ class HomeScreenState extends State with SingleTickerProviderStateMi HomeProvider get homeProvider => GetIt.I.get(); RemoteConfigService get remoteConfigService => GetIt.I.get(); - final List pages = [const CollectionScreen(), const WalletScreen()]; + final List pages = [const CollectionScreen(), const WalletScreen(), const BlockSlayerScreen()]; @override void initState() { @@ -247,6 +248,10 @@ class HomeScreenState extends State with SingleTickerProviderStateMi WalletTab( tabName: provider.tabs[1], index: 1, + ), + WalletTab( + tabName: provider.tabs[2], + index: 2, ) ]), SizedBox(height: 5.h), @@ -382,6 +387,10 @@ class HomeScreenState extends State with SingleTickerProviderStateMi WalletTab( tabName: provider.tabs[1], index: 1, + ), + WalletTab( + tabName: provider.tabs[2], + index: 2, ) ], ), diff --git a/wallet/lib/pages/home/home_provider.dart b/wallet/lib/pages/home/home_provider.dart index 43ce222091..3ed8c2be60 100644 --- a/wallet/lib/pages/home/home_provider.dart +++ b/wallet/lib/pages/home/home_provider.dart @@ -2,7 +2,9 @@ import 'package:dartz/dartz.dart' as dz; import 'package:flutter/material.dart'; import 'package:get_it/get_it.dart'; import 'package:pylons_wallet/model/balance.dart'; +import 'package:pylons_wallet/model/common.dart'; import 'package:pylons_wallet/model/notification_message.dart'; +import 'package:pylons_wallet/model/pylon_items.dart'; import 'package:pylons_wallet/model/transaction.dart'; import 'package:pylons_wallet/pages/home/currency_screen/model/ibc_coins.dart'; import 'package:pylons_wallet/pages/home/wallet_screen/model/currency.dart'; @@ -13,7 +15,6 @@ import 'package:pylons_wallet/utils/extension.dart'; import 'package:pylons_wallet/utils/failure/failure.dart'; import 'package:transaction_signing_gateway/transaction_signing_gateway.dart'; - class HomeProvider extends ChangeNotifier { final Repository repository; @@ -21,7 +22,7 @@ class HomeProvider extends ChangeNotifier { HomeProvider({required this.repository, required this.accountPublicInfo}); - final tabs = ['collection', 'wallet']; + final tabs = ['collection', 'wallet', 'items']; int _selectedIndex = 0; @@ -60,6 +61,62 @@ class HomeProvider extends ChangeNotifier { notifyListeners(); } + List _pylonItemList = []; + + set pylonItemList(List pylonItemList) { + _pylonItemList = pylonItemList; + notifyListeners(); + } + + List get pylonItemList => _pylonItemList; + + List getNoEaselPylonList() { + return pylonItemList.where((element) => !element.cookBookId.toLowerCase().contains("easel")).toList(); + } + + List getNoNEaselItems() { + final List nonEaselItems = []; + + final List pylonsItem = getNoEaselPylonList(); + + pylonsItem.map((e) { + final Map attributeValues = _extractAttributeValues(e.longs); + + final nonEaselItem = NonEaselItemModel( + cookBookId: e.cookBookId, + coins: attributeValues["coins"] ?? "", + currentHp: attributeValues["currentHp"] ?? "", + shards: attributeValues["shards"] ?? "", + swordLevel: attributeValues["swordLevel"] ?? "", + wins: attributeValues["wins"] ?? "", + maxHp: attributeValues["maxHp"] ?? "", + ); + nonEaselItems.add(nonEaselItem); + }).toList(); + + return nonEaselItems.toList(); + } + + Map _extractAttributeValues(List attributes) { + final Map attributeValues = {}; + for (final attribute in attributes) { + switch (attribute.key) { + case 'coins': + case 'currentHp': + case 'maxHp': + case 'shards': + case 'swordLevel': + case 'wins': + attributeValues[attribute.key] = attribute.value; + break; + default: + continue; // Skip unknown keys + } + } + + return attributeValues; + } + Future> callGetNotificationApi() async { final response = await repository.getAllNotificationsMessages( walletAddress: accountPublicInfo.publicAddress, @@ -219,4 +276,11 @@ class HomeProvider extends ChangeNotifier { void refreshScreen() { notifyListeners(); } + + Future getPylonList() async { + final response = await repository.getPylonItem(address: Address(accountPublicInfo.publicAddress)); + if (response.isRight()) { + pylonItemList = response.getOrElse(() => []); + } + } } diff --git a/wallet/lib/services/data_stores/remote_data_store.dart b/wallet/lib/services/data_stores/remote_data_store.dart index 5156acbf11..4b56dcfd6c 100644 --- a/wallet/lib/services/data_stores/remote_data_store.dart +++ b/wallet/lib/services/data_stores/remote_data_store.dart @@ -22,6 +22,7 @@ import 'package:pylons_wallet/model/export.dart'; import 'package:pylons_wallet/model/nft.dart'; import 'package:pylons_wallet/model/nft_ownership_history.dart'; import 'package:pylons_wallet/model/notification_message.dart'; +import 'package:pylons_wallet/model/pylon_items.dart'; import 'package:pylons_wallet/model/stripe_get_login_based_address.dart'; import 'package:pylons_wallet/model/transaction.dart'; import 'package:pylons_wallet/model/wallet_creation_model.dart'; @@ -352,6 +353,8 @@ abstract class RemoteDataStore { Future cancelTrade({required TradeId tradeId, required Address address}); Future createTrade({required pylons.MsgCreateTrade msgCreateTrade}); + + Future> getPylonItem({required Address address}); } class RemoteDataStoreImp implements RemoteDataStore { @@ -1415,6 +1418,30 @@ class RemoteDataStoreImp implements RemoteDataStore { final FirestoreHelper firebaseHelper; final AnalyticsHelper analyticsHelper; final OnLogError onLogError; + + @override + Future> getPylonItem({required Address address}) async{ + final baseApiUrl = getBaseEnv().baseApiUrl; + + final uri = Uri.parse("$baseApiUrl/pylons/items/${address.id}"); + + final pylonItemsResponse = await httpClient.get(uri).timeout(timeOutDuration); + + if (pylonItemsResponse.statusCode != API_SUCCESS_CODE) { + throw HandlerFactory.ERR_SOMETHING_WENT_WRONG; + } + + final pylonItemsMap = jsonDecode(pylonItemsResponse.body); + + final List pylonListItems= []; + + pylonItemsMap["items"].map((data) { + final pylonItems= PylonItems.fromJson(data as Map); + pylonListItems.add(pylonItems); + }).toList(); + + return pylonListItems.toList(); + } } class AppleInAppPurchaseModel { diff --git a/wallet/lib/services/repository/repository.dart b/wallet/lib/services/repository/repository.dart index 64ab1c6af7..f12b0f879d 100644 --- a/wallet/lib/services/repository/repository.dart +++ b/wallet/lib/services/repository/repository.dart @@ -17,6 +17,7 @@ import 'package:pylons_wallet/model/nft.dart'; import 'package:pylons_wallet/model/nft_ownership_history.dart'; import 'package:pylons_wallet/model/notification_message.dart'; import 'package:pylons_wallet/model/pick_image_model.dart'; +import 'package:pylons_wallet/model/pylon_items.dart'; import 'package:pylons_wallet/model/stripe_get_login_based_address.dart'; import 'package:pylons_wallet/model/stripe_loginlink_request.dart'; import 'package:pylons_wallet/model/stripe_loginlink_response.dart'; @@ -578,6 +579,8 @@ abstract class Repository { Future> createTrade({required pylons.MsgCreateTrade msgCreateTrade}); Future> cancelTrade({required TradeId tradeId, required Address address}); + + Future>> getPylonItem({required Address address}); } class RepositoryImp implements Repository { @@ -2445,4 +2448,15 @@ class RepositoryImp implements Repository { final ICloudDriverApiImpl iCloudDriverApi; final OnLogError onLogError; final BaseEnv Function() getBaseEnv; + + @override + Future>> getPylonItem({required Address address}) async{ + try { + final response = await remoteDataStore.getPylonItem(address: address); + return Right(response); + } on Exception catch (e) { + recordErrorInCrashlytics(e); + return Left(ServerFailure(e.toString())); + } + } } From 112e6b9e348f059c4cc72432157e6c05f59af016 Mon Sep 17 00:00:00 2001 From: AhsanRns Date: Wed, 1 May 2024 11:14:04 +0500 Subject: [PATCH 2/2] feat: language code added --- wallet/i18n/de.json | 3 ++- wallet/i18n/en.json | 3 ++- wallet/i18n/es.json | 3 ++- wallet/i18n/id.json | 3 ++- wallet/i18n/ja.json | 3 ++- wallet/i18n/ko.json | 3 ++- wallet/i18n/ru.json | 3 ++- wallet/i18n/vi.json | 3 ++- 8 files changed, 16 insertions(+), 8 deletions(-) diff --git a/wallet/i18n/de.json b/wallet/i18n/de.json index fcf6aee7bc..8070a7a1f8 100644 --- a/wallet/i18n/de.json +++ b/wallet/i18n/de.json @@ -402,5 +402,6 @@ "discord": "Discord", "twitter": "Twitter", "connected": "In Verbindung gebracht", - "no_account_found": "Kein Konto gefunden" + "no_account_found": "Kein Konto gefunden", + "items": "Artikel" } diff --git a/wallet/i18n/en.json b/wallet/i18n/en.json index c660cd7d06..528e9d3ebc 100644 --- a/wallet/i18n/en.json +++ b/wallet/i18n/en.json @@ -404,5 +404,6 @@ "discord": "Discord", "twitter": "Twitter", "connected": "Connected", - "no_account_found": "No account found" + "no_account_found": "No account found", + "items": "Items" } diff --git a/wallet/i18n/es.json b/wallet/i18n/es.json index daf06f5184..7f5180478b 100644 --- a/wallet/i18n/es.json +++ b/wallet/i18n/es.json @@ -401,5 +401,6 @@ "discord": "Discord", "twitter": "Twitter", "connected": "Conectada", - "no_account_found": "No se encontró ninguna cuenta" + "no_account_found": "No se encontró ninguna cuenta", + "items": "Elementos" } \ No newline at end of file diff --git a/wallet/i18n/id.json b/wallet/i18n/id.json index 5c9633fa92..518042422c 100644 --- a/wallet/i18n/id.json +++ b/wallet/i18n/id.json @@ -402,5 +402,6 @@ "discord": "Discord", "twitter": "Twitter", "connected": "Terhubung", - "no_account_found": "Tidak ada akun yang ditemukan" + "no_account_found": "Tidak ada akun yang ditemukan", + "items": "Barang" } \ No newline at end of file diff --git a/wallet/i18n/ja.json b/wallet/i18n/ja.json index ed71cf0a97..6ae35215d0 100644 --- a/wallet/i18n/ja.json +++ b/wallet/i18n/ja.json @@ -402,5 +402,6 @@ "discord": "Discord", "twitter": "Twitter", "connected": "接続済み", - "no_account_found": "アカウントが見つかりません" + "no_account_found": "アカウントが見つかりません", + "items": "アイテム" } diff --git a/wallet/i18n/ko.json b/wallet/i18n/ko.json index d48b15a9ef..17b4818172 100644 --- a/wallet/i18n/ko.json +++ b/wallet/i18n/ko.json @@ -401,5 +401,6 @@ "discord": "Discord", "twitter": "Twitter", "connected": "연결됨", - "no_account_found": "계정을 찾을 수 없습니다." + "no_account_found": "계정을 찾을 수 없습니다.", + "items": "품목" } \ No newline at end of file diff --git a/wallet/i18n/ru.json b/wallet/i18n/ru.json index a8edf7f970..4792c9e553 100644 --- a/wallet/i18n/ru.json +++ b/wallet/i18n/ru.json @@ -402,6 +402,7 @@ "discord": "Discord", "twitter": "Twitter", "connected": "Связано", - "no_account_found": "Аккаунт не найден" + "no_account_found": "Аккаунт не найден", + "items": "Предметы" } diff --git a/wallet/i18n/vi.json b/wallet/i18n/vi.json index b4660596d1..2a6bda4914 100644 --- a/wallet/i18n/vi.json +++ b/wallet/i18n/vi.json @@ -402,5 +402,6 @@ "discord": "Discord", "twitter": "Twitter", "connected": "kết nối", - "no_account_found": "Không có tài khoản nào được tìm thấy" + "no_account_found": "Không có tài khoản nào được tìm thấy", + "items": "Mặt hàng" }