Skip to content

Commit

Permalink
update: response call, mint nft func
Browse files Browse the repository at this point in the history
  • Loading branch information
19Nazar committed Oct 14, 2024
1 parent 6fff613 commit f0fd0ee
Show file tree
Hide file tree
Showing 16 changed files with 502 additions and 270 deletions.
67 changes: 6 additions & 61 deletions lib/flutterchain_lib/network/chains/near_rpc_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import 'package:flutterchain/flutterchain_lib/models/core/blockchain_response.da
import 'package:flutterchain/flutterchain_lib/network/core/network_core.dart';
import 'dart:async';
import 'package:hex/hex.dart';
import 'package:http_parser/http_parser.dart';

class NearRpcClient {
final NearNetworkClient networkClient;
Expand Down Expand Up @@ -237,62 +236,18 @@ class NearRpcClient {
}
}

Future<BlockchainResponse> uploadFileToArweave({required File file}) async {
Future<BlockchainResponse> uploadFileToArweave(
{required Uint8List fileBytes}) async {
int maxSize = 31457280;
FormData formData;
if (await file.length() > maxSize) {
if (await fileBytes.length > maxSize) {
throw Exception("The file size should be up to 30MB");
}

String uri = 'https://ar.mintbase.xyz';

Map<String, dynamic> heders = {"mb-api-key": "anon"};

String fileFormat = checkFileFormat(filePath: file.path);

switch (fileFormat) {
case "pdf":
formData = await createFormData(
filePath: file.path, mediaType: "application/pdf");
case "png":
formData =
await createFormData(filePath: file.path, mediaType: "image/png");
case "jpg":
formData =
await createFormData(filePath: file.path, mediaType: "image/jpg");
case "jpeg":
formData =
await createFormData(filePath: file.path, mediaType: "image/jpeg");
case "gif":
formData =
await createFormData(filePath: file.path, mediaType: "image/gif");
case "zip":
formData = await createFormData(
filePath: file.path, mediaType: "application/zip");
case "ogg":
formData =
await createFormData(filePath: file.path, mediaType: "audio/ogg");
case "mp3":
formData =
await createFormData(filePath: file.path, mediaType: "audio/mp3");
case "mpeg":
formData =
await createFormData(filePath: file.path, mediaType: "audio/mpeg");
case "webm":
formData =
await createFormData(filePath: file.path, mediaType: "video/webm");
case "mp4":
formData =
await createFormData(filePath: file.path, mediaType: "video/mp4");
case "gltf-binar":
formData = await createFormData(
filePath: file.path, mediaType: "model/gltf-binar");
case "octet-stream":
formData = await createFormData(
filePath: file.path, mediaType: "application/octet-stream");
default:
throw Exception("This is format file doesn`t supported");
}
final formData = await createFormData(fileBytes: fileBytes);

final res = await networkClient.postHTTP(uri, formData, heders);

Expand All @@ -307,22 +262,12 @@ class NearRpcClient {
}
}

Future<FormData> createFormData(
{required String filePath, required String mediaType}) async {
Future<FormData> createFormData({required Uint8List fileBytes}) async {
return FormData.fromMap({
'file': await MultipartFile.fromFile(filePath,
contentType: MediaType.parse(mediaType), filename: "file"),
'file': await MultipartFile.fromBytes(fileBytes, filename: "file"),
});
}

String checkFileFormat({required String filePath}) {
List<String> pathList =
filePath.split("/").map((tag) => tag.trim()).toList();
List<String> nameFormatFile =
pathList.last.split(".").map((toch) => toch.trim()).toList();
return nameFormatFile.last;
}

Future<BlockchainResponse> uploadReferenceToArweave(
{required Map<String, dynamic> reference}) async {
Map<String, dynamic> finalRefetence = {};
Expand Down
69 changes: 34 additions & 35 deletions lib/flutterchain_lib/services/chains/near_blockchain_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ class NearBlockChainService
return signedTransaction;
}

Future<bool> deployNFTCollection({
Future<BlockchainResponse> deployNFTCollection({
required String accountId,
required String publicKey,
required String privateKey,
Expand Down Expand Up @@ -809,7 +809,7 @@ class NearBlockChainService
throw Exception("Operation invalid, try again");
}

return true;
return nearSignRequest;
}

Future<List<dynamic>> checkOwnerCollection({required String owner_id}) async {
Expand Down Expand Up @@ -1044,24 +1044,24 @@ class NearBlockChainService
return jsonDecode(names);
}

Future<bool> mintNFT({
Future<BlockchainResponse> mintNFT({
required String accountId,
required String publicKey,
required String privateKey,
required String nftCollectionContract,
required String owner_id,
required String description,
required String title,
required String media,
required Uint8List media,
String? media_type,
String? animation,
Uint8List? animation,
int num_to_mint = 1,
Map<String, int>? split_between,
Map<String, int>? split_owners,
List<String>? tags,
List<dynamic>? extra,
CategoryNFT? category,
String? document,
Uint8List? document,
String? baseURL = "https://arweave.net/",
}) async {
int? splitBetweenSum;
Expand Down Expand Up @@ -1093,22 +1093,20 @@ class NearBlockChainService
"percentage": splitBetweenSum * 100
};
}
final mediaFile = File(media);
if (!mediaFile.existsSync()) {
throw Exception("Media file does not exist");

if (media.length == 0) {
throw Exception("Media is required");
}
String mediaUpload = await uploadFileToArweave(file: mediaFile);
String mediaUpload = await uploadFileToArweave(fileBytes: media);
mediaUploadURL = baseURL! + mediaUpload;

if (animation != null && animation.length > 0) {
final animationFile = File(animation);
animationUpload = await uploadFileToArweave(file: animationFile);
animationUpload = await uploadFileToArweave(fileBytes: animation);
animationUpload = baseURL + animationUpload;
}

if (document != null && document.length > 0) {
final documentFile = File(document);
documentUpload = await uploadFileToArweave(file: documentFile);
documentUpload = await uploadFileToArweave(fileBytes: document);
documentUpload = baseURL + documentUpload;
}

Expand Down Expand Up @@ -1170,7 +1168,7 @@ class NearBlockChainService
throw Exception("Operation invalid, try again");
}

return true;
return nearSignRequest;
}

String mintingDeposit({
Expand Down Expand Up @@ -1199,8 +1197,9 @@ class NearBlockChainService
return "${(totalBytes).ceil()}${'0' * STORAGE_PRICE_PER_BYTE_EXPONENT}";
}

Future<String> uploadFileToArweave({required File file}) async {
final response = await nearRpcClient.uploadFileToArweave(file: file);
Future<String> uploadFileToArweave({required Uint8List fileBytes}) async {
final response =
await nearRpcClient.uploadFileToArweave(fileBytes: fileBytes);
if (response.status == "error") {
throw Exception("${response.data}");
}
Expand All @@ -1226,7 +1225,7 @@ class NearBlockChainService
return updatedRoyalty;
}

Future<bool> transferNFT(
Future<BlockchainResponse> transferNFT(
{required String accountId,
required String publicKey,
required String privateKey,
Expand Down Expand Up @@ -1266,7 +1265,7 @@ class NearBlockChainService
throw Exception("Operation invalid, try again");
}

return true;
return nearSignRequest;
}

Future<BlockchainResponse> NFTInteractionPermission(
Expand All @@ -1285,7 +1284,7 @@ class NearBlockChainService
return await nearRpcClient.mintBaseRPCInteractions(query: query);
}

Future<bool> multiplyNFT({
Future<BlockchainResponse> multiplyNFT({
required String nameNFTCollection,
required String nameNFT,
required String accountId,
Expand Down Expand Up @@ -1359,7 +1358,7 @@ class NearBlockChainService
throw Exception("Operation invalid, try again");
}

return true;
return nearSignRequest;
}

Future<BlockchainResponse> getInfoForMultiply(
Expand All @@ -1383,7 +1382,7 @@ class NearBlockChainService
return await nearRpcClient.mintBaseRPCInteractions(query: query);
}

Future<bool> simpleListNFT({
Future<BlockchainResponse> simpleListNFT({
required String nameNFTCollection,
required String tokenId,
required String price,
Expand Down Expand Up @@ -1436,10 +1435,10 @@ class NearBlockChainService
throw Exception("Operation invalid, try again");
}

return true;
return nearSignRequest;
}

Future<bool> listingActivate({
Future<BlockchainResponse> listingActivate({
required String accountId,
required String publicKey,
required String privateKey,
Expand Down Expand Up @@ -1477,10 +1476,10 @@ class NearBlockChainService
throw Exception("Operation invalid, try again");
}

return true;
return nearSignRequest;
}

Future<bool> unlistNFT(
Future<BlockchainResponse> unlistNFT(
{required String accountId,
required String publicKey,
required String nameNFTCollection,
Expand Down Expand Up @@ -1522,10 +1521,10 @@ class NearBlockChainService
throw Exception("Operation invalid, try again");
}

return true;
return nearSignRequest;
}

Future<bool> delistNFT(
Future<BlockchainResponse> delistNFT(
{required String accountId,
required String publicKey,
required String nameNFTCollection,
Expand Down Expand Up @@ -1567,10 +1566,10 @@ class NearBlockChainService
throw Exception("Operation invalid, try again");
}

return true;
return nearSignRequest;
}

Future<bool> buySimpleListNFT({
Future<BlockchainResponse> buySimpleListNFT({
required String accountId,
required String publicKey,
required String nameNFTCollection,
Expand Down Expand Up @@ -1620,7 +1619,7 @@ class NearBlockChainService
throw Exception("Operation invalid, try again");
}

return true;
return nearSignRequest;
}

Future<String> getPriceForBuySimpleListNFT(
Expand All @@ -1646,7 +1645,7 @@ class NearBlockChainService
return price.toString();
}

Future<bool> rollingAuctionNft(
Future<BlockchainResponse> rollingAuctionNft(
{required String accountId,
required String publicKey,
required String nameNFTCollection,
Expand Down Expand Up @@ -1695,10 +1694,10 @@ class NearBlockChainService
throw Exception("Operation invalid, try again");
}

return true;
return nearSignRequest;
}

Future<bool> offersToRollingAuction({
Future<BlockchainResponse> offersToRollingAuction({
required String accountId,
required String publicKey,
required String nameNFTCollection,
Expand Down Expand Up @@ -1752,6 +1751,6 @@ class NearBlockChainService
throw Exception("Operation invalid, try again");
}

return true;
return nearSignRequest;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:flutterchain/flutterchain_lib/models/core/blockchain_response.dart';
import 'package:flutterchain/flutterchain_lib/services/chains/near_blockchain_service.dart';
import 'package:mintbase_example/thems/thems.dart';
import 'package:mintbase_example/modules/controllers/auth_controller.dart';
Expand All @@ -18,10 +19,10 @@ class _BuySimpleListNftState extends State<BuySimpleListNft> {
final tokenIdController = TextEditingController();
final referrerIdController = TextEditingController();

Future<bool>? isBuy;
Future<BlockchainResponse>? isBuy;
Future<String>? price;

Future<bool> buySimpleListNft(
Future<BlockchainResponse> buySimpleListNft(
{required String nameNFTCollection,
required int tokenId,
String? referrer_id}) async {
Expand Down Expand Up @@ -85,10 +86,10 @@ class _BuySimpleListNftState extends State<BuySimpleListNft> {
),
isBuy == null
? const Text("There were no interactions")
: FutureBuilder<bool>(
: FutureBuilder<BlockchainResponse>(
future: isBuy,
builder:
(BuildContext context, AsyncSnapshot<bool> snapshot) {
builder: (BuildContext context,
AsyncSnapshot<BlockchainResponse> snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
} else if (snapshot.hasError) {
Expand Down
Loading

0 comments on commit f0fd0ee

Please sign in to comment.