Skip to content

Commit

Permalink
add NFTAttributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Yii committed Apr 22, 2022
1 parent 31ccdc2 commit 341db32
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 58 deletions.
3 changes: 1 addition & 2 deletions lib/core/util/web3/wallet_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:decimal/decimal.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:web3dart/web3dart.dart';

import '../../../pages/begin/data/models/nft_info.dart';
import '../../../pages/begin/data/models/nft.dart';
import '../../../pages/begin/data/models/token_info.dart';
import '../../../pages/begin/data/models/wallet_info.dart';
import '../../error/exceptions.dart';
Expand Down Expand Up @@ -134,7 +134,6 @@ class WalletHelper {
(int index) => NFTInfo(
tokenId: ownTokenIdList[index],
imgPath: nftImageUrlList[index],
bgColor: CustomTheme.nftBgColors[index % 3],
),
growable: true,
);
Expand Down
47 changes: 47 additions & 0 deletions lib/pages/begin/data/models/nft.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'package:json_annotation/json_annotation.dart';

import '../../../../core/util/web3/abi/stream_chicken_2.g.dart';

part 'nft.g.dart';

class NFTCollection {
final List<NFTInfo> nftInfoList;
final String name;
final String tokenName;
final Stream_chicken_2 contract;

NFTCollection({
required this.nftInfoList,
required this.name,
required this.tokenName,
required this.contract,
});
}

@JsonSerializable(fieldRename: FieldRename.snake)
class NFTInfo {
final int tokenId;
final String imgPath;
List<NFTAttributes> attributes = [];

NFTInfo({
required this.tokenId,
required this.imgPath,
});
}

@JsonSerializable(fieldRename: FieldRename.snake)
class NFTAttributes {
@JsonKey(defaultValue: '')
String type = '';
@JsonKey(defaultValue: '')
String value = '';

NFTAttributes({
required this.type,
required this.value,
});

factory NFTAttributes.fromJson(Map<String, dynamic> json) => _$NFTAttributesFromJson(json);
Map<String, dynamic> toJson() => _$NFTAttributesToJson(this);
}
29 changes: 29 additions & 0 deletions lib/pages/begin/data/models/nft.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 0 additions & 36 deletions lib/pages/begin/data/models/nft_info.dart

This file was deleted.

2 changes: 1 addition & 1 deletion lib/pages/begin/data/models/wallet_info.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'nft_info.dart';
import 'nft.dart';
import 'token_info.dart';

enum WalletImportMethod { metamask, privateKey, local }
Expand Down
13 changes: 13 additions & 0 deletions lib/pages/begin/data/repositories/begin_repository_impl.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import 'dart:convert';

import 'package:dio/dio.dart';

import '../../../../core/network/network_connection.dart';
import '../../domain/repositories/begin_repository.dart';
import '../datasources/begin_local_data_source.dart';
import '../datasources/begin_remote_data_source.dart';
import '../models/nft.dart';
import '../models/user.dart';

class BeginRepositoryImpl implements BeginRepository {
Expand All @@ -27,4 +32,12 @@ class BeginRepositoryImpl implements BeginRepository {
return data;
}
}

// Future<NFTAttributes?> getTokenMetaData({required String uri}) async {
// final response = await Dio().get(uri);
// if (response.statusCode != 200) return null;
// final data = const JsonDecoder().convert(response.data);
// return NFTAttributes.fromJson(data);
// }

}
2 changes: 1 addition & 1 deletion lib/pages/begin/data/states/load_nft_state.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:freezed_annotation/freezed_annotation.dart';

import '../models/nft_info.dart';
import '../models/nft.dart';


part 'load_nft_state.freezed.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:nft_wallet/pages/begin/domain/providers/home_provider.dart';
import '../../../../core/provider/shared_provider.dart';
import '../../../../core/util/theme.dart';
import '../../../../core/util/web3/abi/stream_chicken_2.g.dart';
import '../../data/models/nft_info.dart';
import '../../data/models/nft.dart';
import '../../data/models/wallet_info.dart';
import '../widgets/common_button.dart';
import '../widgets/common_loading.dart';
Expand Down
25 changes: 10 additions & 15 deletions lib/pages/begin/presentation/pages/nft_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:simple_animations/simple_animations.dart';

import '../../../../core/router/router.dart';
import '../../../../core/util/theme.dart';
import '../../data/models/nft_info.dart';
import '../../data/models/nft.dart';
import '../dialogs/transfer_nft_dialog.dart';
import '../widgets/common_button.dart';

Expand Down Expand Up @@ -149,31 +149,26 @@ class _NftDetailPageState extends State<NftDetailPage> {
CommonButton(
onPress: () => _showTransferNFTDialog(),
color: CustomTheme.secondColor,
child: SizedBox(
width: double.infinity,
child: Container(
padding: const EdgeInsets.all(20),
alignment: Alignment.center,
child: const Text(
'send',
style: CustomTheme.textWhite,
),
child: Container(
padding: const EdgeInsets.all(12),
alignment: Alignment.center,
child: const Text(
'Transfer',
style: CustomTheme.textWhite,
),
),
),
const SizedBox(height: 15),
CommonButton(
onPress: () {},
color: Colors.white,
child: Container(
width: double.infinity,
padding: const EdgeInsets.all(20),
alignment: Alignment.center,
child: Padding(
padding: const EdgeInsets.all(12),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset('assets/images/opensea.png', width: 24),
const SizedBox(width: 5),
const SizedBox(width: 8),
const Text('Sell on Opensea', style: CustomTheme.textBlack),
],
),
Expand Down
6 changes: 4 additions & 2 deletions lib/pages/begin/presentation/widgets/home/nft_tab.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'dart:math';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';

import '../../../../../core/util/theme.dart';
import '../../../data/models/nft_info.dart';
import '../../../data/models/nft.dart';
import '../../pages/nft_detail_page.dart';

class NFTTab extends StatelessWidget {
Expand Down Expand Up @@ -118,7 +120,7 @@ class _NFTItem extends StatelessWidget {
margin: const EdgeInsets.only(right: 8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: nftInfo.bgColor,
color: CustomTheme.nftBgColors[Random().nextInt(2) % 3],
image: DecorationImage(
image: CachedNetworkImageProvider(nftInfo.imgPath),
fit: BoxFit.cover,
Expand Down

0 comments on commit 341db32

Please sign in to comment.