Skip to content

Commit

Permalink
update: return object
Browse files Browse the repository at this point in the history
  • Loading branch information
19Nazar committed Oct 15, 2024
1 parent 722e8f0 commit c2c2ab8
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ class NearBlockChainService
return responseBid;
}

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

return true;
return nearSignRequest;
}

Future<dynamic> addDeleteMinters({
Future<BlockchainResponse> addDeleteMinters({
required String accountId,
required String publicKey,
required String privateKey,
Expand Down Expand Up @@ -1007,11 +1007,12 @@ class NearBlockChainService

if (nearSignRequest.data["error"] != null) {
throw Exception(nearSignRequest.data["error"]);
} else if (nearSignRequest.data["success"] != null) {
return true;
} else {
return false;
}
if (nearSignRequest.data["success"] == null) {
throw Exception("Operation invalid, try again");
}

return nearSignRequest;
}

Future<List<dynamic>> getMinters({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/cupertino.dart';
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 @@ -17,7 +18,7 @@ class _AddRemoveMintersState extends State<AddRemoveMinters> {
final nftCollectionController = TextEditingController();
final nameController = TextEditingController();
Future<List<dynamic>>? nameMinters;
Future<bool>? response;
Future<BlockchainResponse>? response;
bool? _isAdd;

Future<List<dynamic>> getMinters() async {
Expand All @@ -33,7 +34,7 @@ class _AddRemoveMintersState extends State<AddRemoveMinters> {
nftCollectionContract: nftCollectionController.text);
}

Future<bool> addDeleteMinters({
Future<BlockchainResponse> addDeleteMinters({
required String nftCollectionContract,
required String name,
required bool isAdd,
Expand Down Expand Up @@ -114,10 +115,10 @@ class _AddRemoveMintersState extends State<AddRemoveMinters> {
response == null
? const Text("There was no interaction")
: Flexible(
child: FutureBuilder<bool>(
child: FutureBuilder<BlockchainResponse>(
future: response,
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 Expand Up @@ -185,8 +186,7 @@ class _AddRemoveMintersState extends State<AddRemoveMinters> {
maxLines: null,
'${minters}',
style: const TextStyle(
color:
Color.fromARGB(255, 0, 0, 0),
color: Color.fromARGB(255, 0, 0, 0),
fontSize: 16),
);
}).toList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';

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 @@ -22,9 +23,9 @@ class _TransferCollectionDialogState extends State<TransferCollectionDialog> {

bool keep_old_minters = true;

Future<bool>? responseTransfer;
Future<BlockchainResponse>? responseTransfer;

Future<bool> transferNFTCollection(
Future<BlockchainResponse> transferNFTCollection(
{required String nftCollectionContract,
required String new_owner,
required bool keep_old_minters}) async {
Expand Down Expand Up @@ -108,10 +109,10 @@ class _TransferCollectionDialogState extends State<TransferCollectionDialog> {
responseTransfer == null
? const Text("There were no transfers")
: Flexible(
child: FutureBuilder<bool>(
child: FutureBuilder<BlockchainResponse>(
future: responseTransfer,
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
10 changes: 6 additions & 4 deletions test/unit/services/mintbase_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void main() {

test("Add or delete minters", () async {
final nearService = MockNearBlockChainService();
final response = BlockchainResponse(data: {}, status: "success");

when(nearService.addDeleteMinters(
accountId: "Your account id",
Expand All @@ -52,7 +53,7 @@ void main() {
nftCollectionContract: "Full id collection",
name: "Name collection",
isAdd: true))
.thenAnswer((_) async => true);
.thenAnswer((_) async => response);

final res = await nearService.addDeleteMinters(
accountId: "Your account id",
Expand All @@ -61,11 +62,12 @@ void main() {
nftCollectionContract: "Full id collection",
name: "Name collection",
isAdd: true);
expect(res, true);
expect(res, response);
});

test("Transfer NFT collection", () async {
final nearService = MockNearBlockChainService();
final response = BlockchainResponse(data: {}, status: "success");

when(nearService.transferNFTCollection(
accountId: "Your account id",
Expand All @@ -74,7 +76,7 @@ void main() {
nftCollectionContract: "Full id collection",
new_owner: "new owner id",
keep_old_minters: true))
.thenAnswer((_) async => true);
.thenAnswer((_) async => response);

final res = await nearService.transferNFTCollection(
accountId: "Your account id",
Expand All @@ -83,7 +85,7 @@ void main() {
nftCollectionContract: "Full id collection",
new_owner: "new owner id",
keep_old_minters: true);
expect(res, true);
expect(res, response);
});

test("Get minters by NFT collection", () async {
Expand Down
42 changes: 36 additions & 6 deletions test/unit/services/near_blockchain_service_test.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ class MockNearBlockChainService extends _i1.Mock
) as _i10.Future<Map<String, String>>);

@override
_i10.Future<dynamic> transferNFTCollection({
_i10.Future<_i4.BlockchainResponse> transferNFTCollection({
required String? accountId,
required String? publicKey,
required String? privateKey,
Expand All @@ -944,11 +944,26 @@ class MockNearBlockChainService extends _i1.Mock
#keep_old_minters: keep_old_minters,
},
),
returnValue: _i10.Future<dynamic>.value(),
) as _i10.Future<dynamic>);
returnValue:
_i10.Future<_i4.BlockchainResponse>.value(_FakeBlockchainResponse_2(
this,
Invocation.method(
#transferNFTCollection,
[],
{
#accountId: accountId,
#publicKey: publicKey,
#privateKey: privateKey,
#nftCollectionContract: nftCollectionContract,
#new_owner: new_owner,
#keep_old_minters: keep_old_minters,
},
),
)),
) as _i10.Future<_i4.BlockchainResponse>);

@override
_i10.Future<dynamic> addDeleteMinters({
_i10.Future<_i4.BlockchainResponse> addDeleteMinters({
required String? accountId,
required String? publicKey,
required String? privateKey,
Expand All @@ -969,8 +984,23 @@ class MockNearBlockChainService extends _i1.Mock
#isAdd: isAdd,
},
),
returnValue: _i10.Future<dynamic>.value(),
) as _i10.Future<dynamic>);
returnValue:
_i10.Future<_i4.BlockchainResponse>.value(_FakeBlockchainResponse_2(
this,
Invocation.method(
#addDeleteMinters,
[],
{
#accountId: accountId,
#publicKey: publicKey,
#privateKey: privateKey,
#nftCollectionContract: nftCollectionContract,
#name: name,
#isAdd: isAdd,
},
),
)),
) as _i10.Future<_i4.BlockchainResponse>);

@override
_i10.Future<List<dynamic>> getMinters({
Expand Down

0 comments on commit c2c2ab8

Please sign in to comment.