-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate to Quicknode for ipfs upload #2337
Changes from 2 commits
2d4a202
93b5b07
6c735f6
a0c0ab0
5fda6a5
684f267
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import 'dart:async'; | ||
import 'dart:io'; | ||
|
||
import 'package:dartz/dartz.dart'; | ||
import 'package:easel_flutter/main.dart'; | ||
import 'package:easel_flutter/models/denom.dart'; | ||
import 'package:easel_flutter/models/nft.dart'; | ||
|
@@ -12,10 +13,12 @@ import 'package:easel_flutter/models/upload_progress.dart'; | |
import 'package:easel_flutter/repository/repository.dart'; | ||
import 'package:easel_flutter/screens/creator_hub/creator_hub_view_model.dart'; | ||
import 'package:easel_flutter/services/third_party_services/audio_player_helper.dart'; | ||
import 'package:easel_flutter/services/third_party_services/quick_node.dart'; | ||
import 'package:easel_flutter/services/third_party_services/video_player_helper.dart'; | ||
import 'package:easel_flutter/utils/constants.dart'; | ||
import 'package:easel_flutter/utils/enums.dart'; | ||
import 'package:easel_flutter/utils/extension_util.dart'; | ||
import 'package:easel_flutter/utils/failure/failure.dart'; | ||
import 'package:easel_flutter/utils/file_utils_helper.dart'; | ||
import 'package:easel_flutter/widgets/audio_widget.dart'; | ||
import 'package:easel_flutter/widgets/loading_with_progress.dart'; | ||
|
@@ -239,9 +242,7 @@ class EaselProvider extends ChangeNotifier { | |
royaltyController.text = royalties ?? ""; | ||
priceController.text = price ?? ""; | ||
noOfEditionController.text = edition ?? ""; | ||
_selectedDenom = denom != "" | ||
? Denom.availableDenoms.firstWhere((element) => element.symbol == denom) | ||
: Denom.availableDenoms.first; | ||
_selectedDenom = denom != "" ? Denom.availableDenoms.firstWhere((element) => element.symbol == denom) : Denom.availableDenoms.first; | ||
isFreeDrop = freeDrop!; | ||
notifyListeners(); | ||
} | ||
|
@@ -680,8 +681,7 @@ class EaselProvider extends ChangeNotifier { | |
currentUsername = sdkResponse.data!.username; | ||
stripeAccountExists = sdkResponse.data!.stripeExists; | ||
|
||
supportedDenomList = | ||
Denom.availableDenoms.where((Denom e) => sdkResponse.data!.supportedCoins.contains(e.symbol)).toList(); | ||
supportedDenomList = Denom.availableDenoms.where((Denom e) => sdkResponse.data!.supportedCoins.contains(e.symbol)).toList(); | ||
|
||
if (supportedDenomList.isNotEmpty && selectedDenom.symbol.isEmpty) { | ||
_selectedDenom = supportedDenomList.first; | ||
|
@@ -777,8 +777,7 @@ class EaselProvider extends ChangeNotifier { | |
} | ||
} | ||
|
||
bool isThumbnailPresent() => | ||
nftFormat.format == NFTTypes.audio || nftFormat.format == NFTTypes.video || nftFormat.format == NFTTypes.pdf; | ||
bool isThumbnailPresent() => nftFormat.format == NFTTypes.audio || nftFormat.format == NFTTypes.video || nftFormat.format == NFTTypes.pdf; | ||
|
||
Future<bool> saveNftLocally(UploadStep step) async { | ||
final scaffoldMessengerOptionalState = navigatorKey.getState(); | ||
|
@@ -814,12 +813,27 @@ class EaselProvider extends ChangeNotifier { | |
uploadThumbnailResponse = uploadResponse.getOrElse(() => StorageResponseModel.initial()); | ||
} | ||
|
||
final response = await repository.uploadFile( | ||
file: _file!, | ||
onUploadProgressCallback: (value) { | ||
_uploadProgressController.sink.add(value); | ||
}, | ||
); | ||
final whereToUpload = QuickNode.listOfQuickNodeAllowedExtension().contains(fileExtension.toLowerCase()); | ||
|
||
Either<Failure, StorageResponseModel> response; | ||
|
||
if (!whereToUpload) { | ||
response = await repository.uploadFile( | ||
file: _file!, | ||
onUploadProgressCallback: (value) { | ||
_uploadProgressController.sink.add(value); | ||
}, | ||
); | ||
} else { | ||
response = await repository.uploadFileUsingQuickNode( | ||
uploadIPFSInput: UploadIPFSInput( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does quick node doesn't provides any support for the upload progress? Kindly check line 824. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes it is supported working on it |
||
fileName: fileName, | ||
filePath: file?.path ?? '', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the file doesn't have a path then it shouldn't be uploaded. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
contentType: QuickNode.getContentType(fileExtension), | ||
), | ||
); | ||
} | ||
|
||
if (response.isLeft()) { | ||
loading.dismiss(); | ||
LocaleKeys.something_wrong_while_uploading.tr().show(); | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,3 +1,5 @@ | ||||||
import 'package:easel_flutter/services/third_party_services/quick_node.dart'; | ||||||
|
||||||
class StorageResponseModel { | ||||||
bool? ok; | ||||||
Value? value; | ||||||
|
@@ -21,6 +23,26 @@ class StorageResponseModel { | |||||
factory StorageResponseModel.initial() { | ||||||
return StorageResponseModel(); | ||||||
} | ||||||
|
||||||
factory StorageResponseModel.fromQuickNode({required UploadIPFSOutput uploadIPFSOutput}) { | ||||||
return StorageResponseModel( | ||||||
ok: true, | ||||||
value: Value( | ||||||
cid: uploadIPFSOutput.pin?.cid, | ||||||
created: uploadIPFSOutput.created, | ||||||
size: int.parse( | ||||||
uploadIPFSOutput.info?.size ?? '0', | ||||||
), | ||||||
pin: Pin( | ||||||
cid: uploadIPFSOutput.pin?.cid, | ||||||
created: uploadIPFSOutput.created, | ||||||
size: int.parse( | ||||||
uploadIPFSOutput.info?.size ?? '0', | ||||||
), | ||||||
status: uploadIPFSOutput.status, | ||||||
)), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||
); | ||||||
} | ||||||
} | ||||||
|
||||||
class Value { | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,9 @@ class _ChooseFormatScreenState extends State<ChooseFormatScreen> { | |
return; | ||
} | ||
|
||
|
||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can revert these spaces. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
if (!provider.nftFormat.extensions.contains(result.extension)) { | ||
final fileName = result.fileName.replaceAll(".${result.extension}", ""); | ||
errorText.value = LocaleKeys.could_not_uploaded.tr( | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5,6 +5,7 @@ import 'package:easel_flutter/easel_provider.dart'; | |||||||||||||||||
import 'package:easel_flutter/models/storage_response_model.dart'; | ||||||||||||||||||
import 'package:easel_flutter/models/upload_progress.dart'; | ||||||||||||||||||
import 'package:easel_flutter/services/third_party_services/analytics_helper.dart'; | ||||||||||||||||||
import 'package:easel_flutter/services/third_party_services/quick_node.dart'; | ||||||||||||||||||
import 'package:easy_localization/easy_localization.dart'; | ||||||||||||||||||
import 'package:pylons_sdk/low_level.dart'; | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -21,19 +22,33 @@ abstract class RemoteDataSource { | |||||||||||||||||
/// Output : [Future<List<Recipe>>] which will be a Future list of Recipes against the given [cookbookID] | ||||||||||||||||||
Future<List<Recipe>> getRecipesByCookbookID(String cookBookID); | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
/// This method is used to log user journey in the easel app. | ||||||||||||||||||
/// Input: [screenName] the screen name in the easel. | ||||||||||||||||||
/// Output: [bool] tells whether the user journey is recorded or not | ||||||||||||||||||
Future<bool> logUserJourney({required String screenName}); | ||||||||||||||||||
|
||||||||||||||||||
/// This method is used uploading provided file to the server using [QuickNode] | ||||||||||||||||||
/// Input : [UploadIPFSInput] which needs to be uploaded | ||||||||||||||||||
/// Output : [Future<ApiResponse<StorageResponseModel>>] the ApiResponse which can contain [success] or [error] response | ||||||||||||||||||
Future<StorageResponseModel> uploadFileUsingQuickNode({required UploadIPFSInput uploadIPFSInput}); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
class RemoteDataSourceImpl implements RemoteDataSource { | ||||||||||||||||||
final Dio httpClient; | ||||||||||||||||||
final AnalyticsHelper analyticsHelper; | ||||||||||||||||||
final QuickNode quickNode; | ||||||||||||||||||
|
||||||||||||||||||
RemoteDataSourceImpl({required this.httpClient, required this.analyticsHelper}); | ||||||||||||||||||
RemoteDataSourceImpl({ | ||||||||||||||||||
required this.httpClient, | ||||||||||||||||||
required this.analyticsHelper, | ||||||||||||||||||
required this.quickNode, | ||||||||||||||||||
}); | ||||||||||||||||||
|
||||||||||||||||||
@override | ||||||||||||||||||
Future<StorageResponseModel> uploadFileUsingQuickNode({required UploadIPFSInput uploadIPFSInput}) async { | ||||||||||||||||||
final response = await quickNode.uploadNewObjectToIPFS(uploadIPFSInput); | ||||||||||||||||||
return response; | ||||||||||||||||||
} | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
@override | ||||||||||||||||||
Future<StorageResponseModel> uploadFile({required OnUploadProgressCallback uploadProgressCallback, required File file}) async { | ||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name doesn't justifies what it is doing. Maybe you should use
shouldUploadToQuickNode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done