-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TASK-3_1: Refactor blockchain related repositories codes to make them…
… easier to read and maintain (#11)
- Loading branch information
Showing
8 changed files
with
70 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
lib/infrastructure/blockchain/base_blockchain_repository.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import 'dart:async'; | ||
import 'dart:convert'; | ||
import 'package:http/http.dart'; | ||
import 'package:http/http.dart' as http; | ||
|
||
import 'package:hnotes/domain/secret/secret_model.dart'; | ||
import 'package:hnotes/infrastructure/local_storage/secrets/secrets_repository.dart'; | ||
|
||
|
||
class BaseBlockchainRepository { | ||
final client = http.Client(); | ||
|
||
List _defaultParameter = []; | ||
final _requestHeaders = {'Content-type': 'application/json'}; | ||
final SecretRepository _secretRepository = new SecretRepository(); | ||
|
||
Future<SecretModel> _readSecrets() async { | ||
SecretModel _secretModel = await _secretRepository.getApiSecret(); | ||
return _secretModel; | ||
} | ||
|
||
String formPostRequestBody(String method, [var parameter]) { | ||
parameter ??= _defaultParameter; | ||
|
||
return jsonEncode({ | ||
"jsonrpc":"2.0", | ||
"method": method, | ||
"params": parameter, | ||
"id": DateTime.now().millisecondsSinceEpoch | ||
}); | ||
} | ||
|
||
Future<Response> makePostRequest(String requestBody) async { | ||
SecretModel secret = await _readSecrets(); | ||
return await client.post( | ||
Uri.parse(secret.urlWithKey), | ||
headers: _requestHeaders, | ||
body: requestBody, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:hnotes/domain/blockchain/dto_collections.dart'; | ||
import 'package:hnotes/infrastructure/blockchain/base_blockchain_repository.dart'; | ||
|
||
|
||
class NftRepository extends BaseBlockchainRepository { | ||
|
||
} |
50 changes: 0 additions & 50 deletions
50
lib/infrastructure/blockchain/services/request_helper.dart
This file was deleted.
Oops, something went wrong.