feat: Enable NFTs for Solana wallet (#2082)

* feat: Enable NFTs for Solana wallet

* Add localization for texts

* Adjust file naming

* Adjust file naming
This commit is contained in:
David Adegoke
2025-03-14 18:30:19 +02:00
committed by GitHub
parent 1b5be705f6
commit 0f301a71a2
38 changed files with 816 additions and 245 deletions
+130
View File
@@ -0,0 +1,130 @@
class SolanaNFTAssetModel {
String? address;
String? mint;
String? standard;
String? name;
String? symbol;
String? description;
String? imageOriginalUrl;
String? externalUrl;
String? metadataOriginalUrl;
String? totalSupply;
Metaplex? metaplex;
Collection? collection;
Contract? contract;
SolanaNFTAssetModel({
this.address,
this.mint,
this.standard,
this.name,
this.symbol,
this.description,
this.imageOriginalUrl,
this.externalUrl,
this.metadataOriginalUrl,
this.totalSupply,
this.metaplex,
this.collection,
this.contract,
});
factory SolanaNFTAssetModel.fromJson(Map<String, dynamic> json) {
return SolanaNFTAssetModel(
address: json['address'] as String?,
mint: json['mint'] as String?,
standard: json['standard'] as String?,
name: json['name'] as String?,
symbol: json['symbol'] as String?,
description: json['description'] as String?,
imageOriginalUrl: json['imageOriginalUrl'] as String?,
externalUrl: json['externalUrl'] as String?,
metadataOriginalUrl: json['metadataOriginalUrl'] as String?,
totalSupply: json['totalSupply'] as String?,
metaplex: json['metaplex'] != null
? Metaplex.fromJson(json['metaplex'] as Map<String, dynamic>)
: null,
collection: json['collection'] != null
? Collection.fromJson(json['collection'] as Map<String, dynamic>)
: null,
contract: json['contract'] != null
? Contract.fromJson(json['contract'] as Map<String, dynamic>)
: null,
);
}
}
class Metaplex {
String? metadataUri;
String? updateAuthority;
int? sellerFeeBasisPoints;
int? primarySaleHappened;
bool? isMutable;
bool? masterEdition;
Metaplex(
{this.metadataUri,
this.updateAuthority,
this.sellerFeeBasisPoints,
this.primarySaleHappened,
this.isMutable,
this.masterEdition});
factory Metaplex.fromJson(Map<String, dynamic> json) {
return Metaplex(
metadataUri: json['metadataUri'] as String?,
updateAuthority: json['updateAuthority'] as String?,
sellerFeeBasisPoints: json['sellerFeeBasisPoints'] as int?,
primarySaleHappened: json['primarySaleHappened'] as int?,
isMutable: json['isMutable'] as bool?,
masterEdition: json['masterEdition'] as bool?,
);
}
}
class Collection {
String? collectionAddress;
String? name;
String? description;
String? imageOriginalUrl;
String? externalUrl;
String? metaplexMint;
int? sellerFeeBasisPoints;
Collection(
{this.collectionAddress,
this.name,
this.description,
this.imageOriginalUrl,
this.externalUrl,
this.metaplexMint,
this.sellerFeeBasisPoints});
factory Collection.fromJson(Map<String, dynamic> json) {
return Collection(
collectionAddress: json['collectionAddress'] as String?,
name: json['name'] as String?,
description: json['description'] as String?,
imageOriginalUrl: json['imageOriginalUrl'] as String?,
externalUrl: json['externalUrl'] as String?,
metaplexMint: json['metaplexMint'] as String?,
sellerFeeBasisPoints: json['sellerFeeBasisPoints'] as int?,
);
}
}
class Contract {
String? type;
String? name;
String? symbol;
Contract({this.type, this.name, this.symbol});
factory Contract.fromJson(Map<String, dynamic> json) {
return Contract(
type: json['type'] as String?,
name: json['name'] as String?,
symbol: json['symbol'] as String?,
);
}
}
+12 -1
View File
@@ -12,6 +12,17 @@ bool isEVMCompatibleChain(WalletType walletType) {
}
}
bool isNFTACtivatedChain(WalletType walletType) {
switch (walletType) {
case WalletType.polygon:
case WalletType.ethereum:
case WalletType.solana:
return true;
default:
return false;
}
}
bool isWalletConnectCompatibleChain(WalletType walletType) {
switch (walletType) {
case WalletType.polygon:
@@ -55,7 +66,7 @@ String getChainNameBasedOnWalletType(WalletType walletType) {
case WalletType.polygon:
return 'polygon';
case WalletType.solana:
return 'solana';
return 'mainnet';
default:
return '';
}
+1 -1
View File
@@ -771,7 +771,7 @@ Route<dynamic> createRoute(RouteSettings settings) {
case Routes.nftDetailsPage:
return MaterialPageRoute<void>(
builder: (_) => NFTDetailsPage(
nftAsset: settings.arguments as NFTAssetModel,
arguments: settings.arguments as NFTDetailsPageArguments,
dashboardViewModel: getIt.get<DashboardViewModel>(),
),
);
@@ -23,13 +23,13 @@ class BalancePage extends StatelessWidget {
Widget build(BuildContext context) {
return Observer(
builder: (context) {
final isEVMCompatible = isEVMCompatibleChain(dashboardViewModel.type);
final isNFTActivated = isNFTACtivatedChain(dashboardViewModel.type);
return DefaultTabController(
key: ValueKey<bool>(isEVMCompatible),
length: isEVMCompatible ? 2 : 1,
key: ValueKey<bool>(isNFTActivated),
length: isNFTActivated ? 2 : 1,
child: Column(
children: [
if (isEVMCompatible)
if (isNFTActivated)
Align(
alignment: Alignment.centerLeft,
child: Padding(
@@ -76,7 +76,7 @@ class BalancePage extends StatelessWidget {
physics: NeverScrollableScrollPhysics(),
children: [
CryptoBalanceWidget(dashboardViewModel: dashboardViewModel),
if (isEVMCompatible) NFTListingPage(nftViewModel: nftViewModel)
if (isNFTActivated) NFTListingPage(nftViewModel: nftViewModel)
],
),
),
@@ -1,3 +1,5 @@
import 'package:flutter/material.dart';
import 'package:cake_wallet/entities/solana_nft_asset_model.dart';
import 'package:cake_wallet/entities/wallet_nft_response.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/screens/base_page.dart';
@@ -8,21 +10,23 @@ import 'package:cake_wallet/themes/extensions/balance_page_theme.dart';
import 'package:cake_wallet/themes/extensions/dashboard_page_theme.dart';
import 'package:cake_wallet/themes/extensions/sync_indicator_theme.dart';
import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart';
import 'package:flutter/material.dart';
class NFTDetailsPage extends BasePage {
NFTDetailsPage({required this.dashboardViewModel, required this.nftAsset});
NFTDetailsPage({
required this.dashboardViewModel,
required this.arguments,
Key? key,
});
final DashboardViewModel dashboardViewModel;
final NFTAssetModel nftAsset;
final NFTDetailsPageArguments arguments;
@override
bool get gradientBackground => true;
@override
Widget Function(BuildContext, Widget) get rootWrapper =>
(BuildContext context, Widget scaffold) =>
GradientBackground(scaffold: scaffold);
(BuildContext context, Widget scaffold) => GradientBackground(scaffold: scaffold);
@override
bool get resizeToAvoidBottomInset => false;
@@ -30,15 +34,14 @@ class NFTDetailsPage extends BasePage {
@override
Widget get endDrawer => MenuWidget(
dashboardViewModel,
ValueKey('nft_details_page_menu_widget_key'),
const ValueKey('nft_details_page_menu_widget_key'),
);
@override
Widget trailing(BuildContext context) {
final menuButton = Image.asset(
'assets/images/menu.png',
color:
Theme.of(context).extension<DashboardPageTheme>()!.pageTitleTextColor,
color: Theme.of(context).extension<DashboardPageTheme>()!.pageTitleTextColor,
);
return Container(
@@ -58,119 +61,200 @@ class NFTDetailsPage extends BasePage {
@override
Widget body(BuildContext context) {
return SingleChildScrollView(
child: Column(
children: [
Container(
width: double.infinity,
margin: const EdgeInsets.all(16),
padding: const EdgeInsets.symmetric(vertical: 16),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0),
border: Border.all(
color: Theme.of(context)
.extension<BalancePageTheme>()!
.cardBorderColor,
width: 1,
),
color: Theme.of(context)
.extension<SyncIndicatorTheme>()!
.syncedBackgroundColor,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: MediaQuery.sizeOf(context).height / 2.5,
width: double.infinity,
clipBehavior: Clip.hardEdge,
margin: const EdgeInsets.all(8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16.0),
border: Border.all(
color: Theme.of(context)
.extension<BalancePageTheme>()!
.cardBorderColor,
width: 1,
),
color: Theme.of(context)
.extension<SyncIndicatorTheme>()!
.syncedBackgroundColor,
),
child: CakeImageWidget(
imageUrl: nftAsset.normalizedMetadata?.imageUrl,
),
),
SizedBox(height: 16),
_NFTSingleInfoTile(
infoType: S.current.name,
infoValue: nftAsset.normalizedMetadata?.name ?? '---',
),
if (nftAsset.normalizedMetadata?.description != null) ...[
SizedBox(height: 16),
_NFTSingleInfoTile(
infoType: S.current.description,
infoValue: nftAsset.normalizedMetadata?.description ?? '---',
),
],
SizedBox(height: 16),
_NFTSingleInfoTile(
infoType: S.current.contractName,
infoValue: nftAsset.name ?? '---',
),
SizedBox(height: 8),
_NFTSingleInfoTile(
infoType: S.current.contractSymbol,
infoValue: nftAsset.symbol ?? '---',
),
],
),
child: Container(
width: double.infinity,
margin: const EdgeInsets.all(16),
padding: const EdgeInsets.symmetric(vertical: 16),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0),
border: Border.all(
color: Theme.of(context).extension<BalancePageTheme>()!.cardBorderColor,
width: 1,
),
],
color: Theme.of(context).extension<SyncIndicatorTheme>()!.syncedBackgroundColor,
),
child: arguments.isSolanaNFT
? SolanaNFTDetailsWidget(
solanaNftAsset: arguments.solanaNFTAssetModel,
)
: EVMChainNFTDetailsWidget(
nftAsset: arguments.nftAsset,
),
),
);
}
}
class _NFTImageWidget extends StatelessWidget {
final String? imageUrl;
const _NFTImageWidget({Key? key, this.imageUrl}) : super(key: key);
@override
Widget build(BuildContext context) {
final balanceTheme = Theme.of(context).extension<BalancePageTheme>()!;
final syncTheme = Theme.of(context).extension<SyncIndicatorTheme>()!;
return Container(
height: MediaQuery.sizeOf(context).height / 2.5,
width: double.infinity,
margin: const EdgeInsets.all(8),
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16.0),
border: Border.all(
color: balanceTheme.cardBorderColor,
width: 1,
),
color: syncTheme.syncedBackgroundColor,
),
child: CakeImageWidget(imageUrl: imageUrl),
);
}
}
class EVMChainNFTDetailsWidget extends StatelessWidget {
final NFTAssetModel? nftAsset;
const EVMChainNFTDetailsWidget({Key? key, this.nftAsset}) : super(key: key);
@override
Widget build(BuildContext context) {
if (nftAsset == null) {
return Center(child: Text(S.current.no_extra_detail));
}
final metadata = nftAsset!.normalizedMetadata;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_NFTImageWidget(imageUrl: metadata?.imageUrl),
const SizedBox(height: 16),
_NFTSingleInfoTile(
infoType: S.current.name,
infoValue: metadata?.name ?? '---',
),
if (metadata?.description != null) ...[
const SizedBox(height: 16),
_NFTSingleInfoTile(
infoType: S.current.description,
infoValue: metadata!.description ?? '---',
),
],
const SizedBox(height: 16),
_NFTSingleInfoTile(
infoType: S.current.contractName,
infoValue: nftAsset!.name ?? '---',
),
const SizedBox(height: 8),
_NFTSingleInfoTile(
infoType: S.current.contractSymbol,
infoValue: nftAsset!.symbol ?? '---',
),
],
);
}
}
class SolanaNFTDetailsWidget extends StatelessWidget {
final SolanaNFTAssetModel? solanaNftAsset;
const SolanaNFTDetailsWidget({Key? key, this.solanaNftAsset}) : super(key: key);
@override
Widget build(BuildContext context) {
if (solanaNftAsset == null) {
return Center(child: Text(S.current.no_extra_detail));
}
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_NFTImageWidget(imageUrl: solanaNftAsset?.imageOriginalUrl),
const SizedBox(height: 16),
_NFTSingleInfoTile(
infoType: S.current.name,
infoValue: solanaNftAsset?.name ?? '---',
),
if (solanaNftAsset?.description != null) ...[
const SizedBox(height: 16),
_NFTSingleInfoTile(
infoType: S.current.description,
infoValue: solanaNftAsset!.description ?? '---',
),
],
const SizedBox(height: 16),
_NFTSingleInfoTile(
infoType: S.current.mint_address,
infoValue: solanaNftAsset?.mint ?? '---',
),
const SizedBox(height: 16),
_NFTSingleInfoTile(
infoType: S.current.contractName,
infoValue: solanaNftAsset?.contract?.name ?? '---',
),
const SizedBox(height: 16),
_NFTSingleInfoTile(
infoType: S.current.contractSymbol,
infoValue: solanaNftAsset?.contract?.symbol ?? '---',
),
const SizedBox(height: 16),
_NFTSingleInfoTile(
infoType: S.current.collection_name,
infoValue: solanaNftAsset?.collection?.name ?? '---',
),
const SizedBox(height: 16),
_NFTSingleInfoTile(
infoType: S.current.collection_description,
infoValue: solanaNftAsset?.collection?.description ?? '---',
),
const SizedBox(height: 16),
_NFTSingleInfoTile(
infoType: S.current.collection_address,
infoValue: solanaNftAsset?.collection?.collectionAddress ?? '---',
),
const SizedBox(height: 16),
],
);
}
}
class _NFTSingleInfoTile extends StatelessWidget {
final String infoType;
final String infoValue;
const _NFTSingleInfoTile({
required this.infoType,
required this.infoValue,
});
final String infoType;
final String infoValue;
@override
Widget build(BuildContext context) {
final balanceTheme = Theme.of(context).extension<BalancePageTheme>()!;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
infoType,
infoType,
style: TextStyle(
fontSize: 12,
fontFamily: 'Lato',
fontWeight: FontWeight.w400,
color: Theme.of(context)
.extension<BalancePageTheme>()!
.labelTextColor,
color: balanceTheme.labelTextColor,
height: 1,
),
),
SizedBox(height: 8),
const SizedBox(height: 8),
Text(
infoValue,
style: TextStyle(
fontSize: 16,
fontFamily: 'Lato',
fontWeight: FontWeight.w600,
color: Theme.of(context)
.extension<BalancePageTheme>()!
.assetTitleColor,
color: balanceTheme.assetTitleColor,
height: 1,
),
),
@@ -179,3 +263,15 @@ infoType,
);
}
}
class NFTDetailsPageArguments {
NFTDetailsPageArguments({
this.nftAsset,
this.solanaNFTAssetModel,
required this.isSolanaNFT,
});
final NFTAssetModel? nftAsset;
final SolanaNFTAssetModel? solanaNFTAssetModel;
final bool isSolanaNFT;
}
@@ -6,6 +6,7 @@ import 'package:cake_wallet/src/widgets/primary_button.dart';
import 'package:cake_wallet/themes/extensions/cake_text_theme.dart';
import 'package:cake_wallet/themes/extensions/seed_widget_theme.dart';
import 'package:cake_wallet/view_model/dashboard/nft_view_model.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
@@ -68,7 +69,6 @@ class _ImportNFTPage extends BasePage {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
S.current.address,
textAlign: TextAlign.center,
@@ -76,8 +76,7 @@ class _ImportNFTPage extends BasePage {
fontSize: 16,
fontFamily: 'Lato',
fontWeight: FontWeight.w800,
color:
Theme.of(context).extension<SeedWidgetTheme>()!.hintTextColor,
color: Theme.of(context).extension<SeedWidgetTheme>()!.hintTextColor,
height: 1,
),
),
@@ -92,9 +91,7 @@ class _ImportNFTPage extends BasePage {
tokenAddressController.text = tokenAddress;
}
},
borderColor: Theme.of(context)
.extension<CakeTextTheme>()!
.textfieldUnderlineColor,
borderColor: Theme.of(context).extension<CakeTextTheme>()!.textfieldUnderlineColor,
iconColor: Theme.of(context).primaryColor,
placeholder: '0x...',
textStyle: TextStyle(
@@ -108,46 +105,45 @@ class _ImportNFTPage extends BasePage {
color: PaletteDark.darkCyanBlue,
),
),
SizedBox(height: 48),
Text(
S.current.tokenID,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 16,
fontFamily: 'Lato',
fontWeight: FontWeight.w800,
color: Theme.of(context).extension<SeedWidgetTheme>()!.hintTextColor,
height: 1,
if (nftViewModel.appStore.wallet!.type != WalletType.solana) ...[
SizedBox(height: 48),
Text(
S.current.tokenID,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 16,
fontFamily: 'Lato',
fontWeight: FontWeight.w800,
color: Theme.of(context).extension<SeedWidgetTheme>()!.hintTextColor,
height: 1,
),
),
),
AddressTextField(
controller: tokenIDController,
options: [AddressTextFieldOption.paste],
onPushPasteButton: (context) async {
final clipboard = await Clipboard.getData('text/plain');
final tokenID = clipboard?.text ?? '';
AddressTextField(
controller: tokenIDController,
options: [AddressTextFieldOption.paste],
onPushPasteButton: (context) async {
final clipboard = await Clipboard.getData('text/plain');
final tokenID = clipboard?.text ?? '';
if (tokenID.isNotEmpty) {
tokenIDController.text = tokenID;
}
},
borderColor: Theme.of(context)
.extension<CakeTextTheme>()!
.textfieldUnderlineColor,
iconColor: Theme.of(context).primaryColor,
placeholder: S.current.enterTokenID,
textStyle: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w400,
color: PaletteDark.darkCyanBlue,
if (tokenID.isNotEmpty) {
tokenIDController.text = tokenID;
}
},
borderColor: Theme.of(context).extension<CakeTextTheme>()!.textfieldUnderlineColor,
iconColor: Theme.of(context).primaryColor,
placeholder: S.current.enterTokenID,
textStyle: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w400,
color: PaletteDark.darkCyanBlue,
),
hintStyle: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w400,
color: PaletteDark.darkCyanBlue,
),
),
hintStyle: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w400,
color: PaletteDark.darkCyanBlue,
),
),
],
Spacer(),
Observer(builder: (context) {
return LoadingPrimaryButton(
@@ -161,6 +157,7 @@ class _ImportNFTPage extends BasePage {
},
);
}),
SizedBox(height: 16),
],
),
);
@@ -1,32 +1,37 @@
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/src/screens/dashboard/widgets/nft_tile_widget.dart';
import 'package:cake_wallet/src/screens/dashboard/widgets/solana_nft_tile_widget.dart';
import 'package:cake_wallet/src/widgets/primary_button.dart';
import 'package:cake_wallet/themes/extensions/dashboard_page_theme.dart';
import 'package:cake_wallet/themes/extensions/exchange_page_theme.dart';
import 'package:cake_wallet/themes/extensions/sync_indicator_theme.dart';
import 'package:cake_wallet/view_model/dashboard/nft_view_model.dart';
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:cw_core/wallet_type.dart';
class NFTListingPage extends StatelessWidget {
final NFTViewModel nftViewModel;
const NFTListingPage({super.key, required this.nftViewModel});
@override
Widget build(BuildContext context) {
final dashboardTheme = Theme.of(context).extension<DashboardPageTheme>()!;
final syncIndicatorTheme = Theme.of(context).extension<SyncIndicatorTheme>()!;
final exchangeTheme = Theme.of(context).extension<ExchangePageTheme>()!;
return Observer(
builder: (context) {
return Column(
children: [
SizedBox(height: 16),
const SizedBox(height: 16),
Padding(
padding: EdgeInsets.only(left: 16, right: 16, bottom: 16),
padding: const EdgeInsets.only(left: 16, right: 16, bottom: 16),
child: PrimaryButton(
text: S.current.import,
color: Theme.of(context)
.extension<SyncIndicatorTheme>()!
.syncedBackgroundColor,
color: syncIndicatorTheme.syncedBackgroundColor,
textColor: Colors.white,
onPressed: () => Navigator.pushNamed(
context,
@@ -39,46 +44,75 @@ class NFTListingPage extends StatelessWidget {
Expanded(
child: Center(
child: CircularProgressIndicator(
backgroundColor: Theme.of(context).extension<DashboardPageTheme>()!.textColor,
backgroundColor: dashboardTheme.textColor,
valueColor: AlwaysStoppedAnimation<Color>(
Theme.of(context)
.extension<ExchangePageTheme>()!
.firstGradientBottomPanelColor,
exchangeTheme.firstGradientBottomPanelColor,
),
),
),
),
if (!nftViewModel.isLoading)
Expanded(
child: nftViewModel.nftAssetByWalletModels.isEmpty
? Center(
child: Text(
S.current.noNFTYet,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20,
fontFamily: 'Lato',
fontWeight: FontWeight.w600,
color: Theme.of(context)
.extension<DashboardPageTheme>()!
.pageTitleTextColor,
height: 1,
),
),
)
: ListView.separated(
padding: EdgeInsets.symmetric(horizontal: 4, vertical: 16),
separatorBuilder: (context, index) => SizedBox(height: 8),
itemCount: nftViewModel.nftAssetByWalletModels.length,
itemBuilder: (context, index) {
final nftAsset = nftViewModel.nftAssetByWalletModels[index];
return NFTTileWidget(nftAsset: nftAsset);
},
),
)
else
Expanded(
child: NFTListWidget(nftViewModel: nftViewModel),
),
],
);
},
);
}
}
class NFTListWidget extends StatelessWidget {
const NFTListWidget({required this.nftViewModel, super.key});
final NFTViewModel nftViewModel;
@override
Widget build(BuildContext context) {
return Observer(
builder: (context) {
final isSolana = nftViewModel.appStore.wallet!.type == WalletType.solana;
final emptyMessage = Center(
child: Text(
S.current.noNFTYet,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20,
fontFamily: 'Lato',
fontWeight: FontWeight.w600,
color: Theme.of(context).extension<DashboardPageTheme>()!.pageTitleTextColor,
height: 1,
),
),
);
if (isSolana) {
if (nftViewModel.solanaNftAssetModels.isEmpty) return emptyMessage;
return ListView.separated(
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 16),
separatorBuilder: (context, index) => const SizedBox(height: 8),
itemCount: nftViewModel.solanaNftAssetModels.length,
itemBuilder: (context, index) {
final nftAsset = nftViewModel.solanaNftAssetModels[index];
return SolanaNFTTileWidget(nftAsset: nftAsset);
},
);
} else {
if (nftViewModel.nftAssetByWalletModels.isEmpty) return emptyMessage;
return ListView.separated(
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 16),
separatorBuilder: (context, index) => const SizedBox(height: 8),
itemCount: nftViewModel.nftAssetByWalletModels.length,
itemBuilder: (context, index) {
final nftAsset = nftViewModel.nftAssetByWalletModels[index];
return NFTTileWidget(nftAsset: nftAsset);
},
);
}
},
);
}
}
@@ -1,5 +1,6 @@
import 'package:cake_wallet/entities/wallet_nft_response.dart';
import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/src/screens/dashboard/pages/nft_details_page.dart';
import 'package:cake_wallet/src/widgets/cake_image_widget.dart';
import 'package:cake_wallet/themes/extensions/balance_page_theme.dart';
import 'package:cake_wallet/themes/extensions/sync_indicator_theme.dart';
@@ -12,7 +13,14 @@ class NFTTileWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return InkWell(
onTap: () => Navigator.pushNamed(context, Routes.nftDetailsPage, arguments: nftAsset),
onTap: () => Navigator.pushNamed(
context,
Routes.nftDetailsPage,
arguments: NFTDetailsPageArguments(
isSolanaNFT: false,
nftAsset: nftAsset,
),
),
child: Container(
width: double.infinity,
margin: const EdgeInsets.only(left: 16, right: 16),
@@ -0,0 +1,97 @@
import 'package:flutter/material.dart';
import 'package:cake_wallet/entities/solana_nft_asset_model.dart';
import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/src/screens/dashboard/pages/nft_details_page.dart';
import 'package:cake_wallet/src/widgets/cake_image_widget.dart';
import 'package:cake_wallet/themes/extensions/balance_page_theme.dart';
import 'package:cake_wallet/themes/extensions/sync_indicator_theme.dart';
class SolanaNFTTileWidget extends StatelessWidget {
const SolanaNFTTileWidget({super.key, required this.nftAsset});
final SolanaNFTAssetModel nftAsset;
@override
Widget build(BuildContext context) {
final balanceTheme = Theme.of(context).extension<BalancePageTheme>()!;
final syncTheme = Theme.of(context).extension<SyncIndicatorTheme>()!;
return InkWell(
onTap: () {
Navigator.pushNamed(
context,
Routes.nftDetailsPage,
arguments: NFTDetailsPageArguments(
isSolanaNFT: true,
solanaNFTAssetModel: nftAsset,
),
);
},
child: Container(
width: double.infinity,
margin: const EdgeInsets.symmetric(horizontal: 16),
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16.0),
border: Border.all(
color: balanceTheme.cardBorderColor,
width: 1,
),
color: syncTheme.syncedBackgroundColor,
),
child: Row(
children: [
Container(
height: 100,
width: 100,
margin: const EdgeInsets.all(8),
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16.0),
border: Border.all(
color: balanceTheme.cardBorderColor,
width: 1,
),
color: syncTheme.syncedBackgroundColor,
),
child: CakeImageWidget(
imageUrl: nftAsset.imageOriginalUrl,
),
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Symbol: ${nftAsset.symbol ?? '---'}',
style: TextStyle(
fontSize: 12,
fontFamily: 'Lato',
fontWeight: FontWeight.w400,
color: balanceTheme.labelTextColor,
height: 1,
),
),
const SizedBox(height: 8),
Text(
(nftAsset.name?.isNotEmpty ?? false)
? nftAsset.name!
: (nftAsset.symbol ?? '---'),
style: TextStyle(
fontSize: 20,
fontFamily: 'Lato',
fontWeight: FontWeight.w900,
color: balanceTheme.assetTitleColor,
height: 1,
),
),
],
),
)
],
),
),
);
}
}
+99 -41
View File
@@ -2,8 +2,10 @@ import 'dart:convert';
import 'dart:developer';
import 'package:cake_wallet/core/wallet_connect/wc_bottom_sheet_service.dart';
import 'package:cake_wallet/entities/solana_nft_asset_model.dart';
import 'package:cake_wallet/reactions/wallet_connect.dart';
import 'package:cake_wallet/src/screens/wallet_connect/widgets/message_display_widget.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:http/http.dart' as http;
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/.secrets.g.dart' as secrets;
@@ -19,7 +21,8 @@ abstract class NFTViewModelBase with Store {
NFTViewModelBase(this.appStore, this.bottomSheetService)
: isLoading = false,
isImportNFTLoading = false,
nftAssetByWalletModels = ObservableList() {
nftAssetByWalletModels = ObservableList(),
solanaNftAssetModels = ObservableList() {
getNFTAssetByWallet();
reaction((_) => appStore.wallet, (_) => getNFTAssetByWallet());
@@ -36,31 +39,44 @@ abstract class NFTViewModelBase with Store {
ObservableList<NFTAssetModel> nftAssetByWalletModels;
ObservableList<SolanaNFTAssetModel> solanaNftAssetModels;
@action
Future<void> getNFTAssetByWallet() async {
if (!isEVMCompatibleChain(appStore.wallet!.type)) return;
final walletType = appStore.wallet!.type;
if (!isNFTACtivatedChain(walletType)) return;
final walletAddress = appStore.wallet!.walletInfo.address;
log('Fetching wallet NFTs for $walletAddress');
final chainName = getChainNameBasedOnWalletType(appStore.wallet!.type);
final chainName = getChainNameBasedOnWalletType(walletType);
// the [chain] refers to the chain network that the nft is on
// the [format] refers to the number format type of the responses
// the [normalizedMetadata] field is a boolean that determines if
// the response would include a json string of the NFT Metadata that can be decoded
// and used within the wallet
// the [excludeSpam] field is a boolean that determines if spam nfts be excluded from the response.
final uri = Uri.https(
'deep-index.moralis.io',
'/api/v2.2/$walletAddress/nft',
{
"chain": chainName,
"format": "decimal",
"media_items": "false",
"exclude_spam": "true",
"normalizeMetadata": "true",
},
);
Uri uri;
if (walletType == WalletType.solana) {
uri = Uri.https(
'solana-gateway.moralis.io',
'/account/$chainName/$walletAddress/nft',
);
} else {
uri = Uri.https(
'deep-index.moralis.io',
'/api/v2.2/$walletAddress/nft',
{
"chain": chainName,
"format": "decimal",
"media_items": "false",
"exclude_spam": "true",
"normalizeMetadata": "true",
},
);
}
try {
isLoading = true;
@@ -73,13 +89,30 @@ abstract class NFTViewModelBase with Store {
},
);
final decodedResponse = jsonDecode(response.body) as Map<String, dynamic>;
final decodedResponse = jsonDecode(response.body);
final result = WalletNFTsResponseModel.fromJson(decodedResponse).result ?? [];
if (walletType == WalletType.solana) {
final results = await Future.wait(
(decodedResponse as List<dynamic>).map(
(x) {
final data = x as Map<String, dynamic>;
final mint = data['mint'] as String? ?? '';
return getSolanaNFTDetails(mint, chainName);
},
).toList(),
);
nftAssetByWalletModels.clear();
solanaNftAssetModels.clear();
nftAssetByWalletModels.addAll(result);
solanaNftAssetModels.addAll(results);
} else {
final result =
WalletNFTsResponseModel.fromJson(decodedResponse as Map<String, dynamic>).result ?? [];
nftAssetByWalletModels.clear();
nftAssetByWalletModels.addAll(result);
}
isLoading = false;
} catch (e) {
@@ -94,51 +127,76 @@ abstract class NFTViewModelBase with Store {
}
}
Future<SolanaNFTAssetModel> getSolanaNFTDetails(String address, String chainName) async {
final uri = Uri.https(
'solana-gateway.moralis.io',
'/nft/$chainName/$address/metadata',
);
final response = await http.get(
uri,
headers: {
"Accept": "application/json",
"X-API-Key": secrets.moralisApiKey,
},
);
final decodedResponse = jsonDecode(response.body) as Map<String, dynamic>;
return SolanaNFTAssetModel.fromJson(decodedResponse);
}
@action
Future<void> importNFT(String tokenAddress, String tokenId) async {
Future<void> importNFT(String tokenAddress, String? tokenId) async {
final chainName = getChainNameBasedOnWalletType(appStore.wallet!.type);
// the [chain] refers to the chain network that the nft is on
// the [format] refers to the number format type of the responses
// the [normalizedMetadata] field is a boolean that determines if
// the response would include a json string of the NFT Metadata that can be decoded
// and used within the wallet
final uri = Uri.https(
'deep-index.moralis.io',
'/api/v2.2/nft/$tokenAddress/$tokenId',
{
"chain": chainName,
"format": "decimal",
"media_items": "false",
"normalizeMetadata": "true",
},
);
try {
isImportNFTLoading = true;
final response = await http.get(
uri,
headers: {
"Accept": "application/json",
"X-API-Key": secrets.moralisApiKey,
},
);
if (appStore.wallet!.type == WalletType.solana) {
final result = await getSolanaNFTDetails(tokenAddress, chainName);
final decodedResponse = jsonDecode(response.body) as Map<String, dynamic>;
solanaNftAssetModels.add(result);
} else {
final uri = Uri.https(
'deep-index.moralis.io',
'/api/v2.2/nft/$tokenAddress/$tokenId',
{
"chain": chainName,
"format": "decimal",
"media_items": "false",
"normalizeMetadata": "true",
},
);
final nftAsset = NFTAssetModel.fromJson(decodedResponse);
final response = await http.get(
uri,
headers: {
"Accept": "application/json",
"X-API-Key": secrets.moralisApiKey,
},
);
nftAssetByWalletModels.add(nftAsset);
final decodedResponse = jsonDecode(response.body) as Map<String, dynamic>;
isImportNFTLoading = false;
final nftAsset = NFTAssetModel.fromJson(decodedResponse);
nftAssetByWalletModels.add(nftAsset);
}
} catch (e) {
isImportNFTLoading = false;
bottomSheetService.queueBottomSheet(
isModalDismissible: true,
widget: BottomSheetMessageDisplayWidget(
message: e.toString(),
),
);
} finally {
isImportNFTLoading = false;
}
}
}