-
Notifications
You must be signed in to change notification settings - Fork 3
feat: realu buy integration #20
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
38decac
feat: getBuyPrice and getShares endpoint.
xlamn 426e718
feat: add payment information.
xlamn 47e81eb
refactoring: moving button into PaymentInformation.
xlamn 19ba458
feat: add allowlist check.
xlamn 0c20c69
chore: currency and asset display.
xlamn 5c15baf
refactor: improvements.
xlamn 97b2a41
refactor: more cleaning.
xlamn c350020
chore: naming.
xlamn a7ac7a8
chore: colors for asset in converter.
xlamn a73de15
test: BuyPage.
xlamn 4b57949
chore: minor.
xlamn 93c8118
chore: minor.
xlamn 07324ad
chore: improvements.
xlamn 08e99f0
refactor: comments.
xlamn e061ca1
chore: translations.
xlamn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,22 @@ | ||
| import 'dart:convert'; | ||
|
|
||
| import 'package:realunit_wallet/packages/service/app_store.dart'; | ||
| import 'package:realunit_wallet/packages/service/dfx/models/dfx_allowlist_status.dart'; | ||
|
|
||
| class DfxAllowlistService { | ||
| static const _baseUrl = "https://dev.api.dfx.swiss/v1/realunit"; | ||
| final AppStore _appStore; | ||
|
|
||
| DfxAllowlistService(this._appStore); | ||
|
|
||
| Future<DfxAllowlistStatus> checkAllowlist() async { | ||
| final url = Uri.parse("$_baseUrl/allowlist/${_appStore.primaryAddress}"); | ||
| final response = await _appStore.httpClient.get(url); | ||
|
|
||
| if (response.statusCode != 200) { | ||
| throw Exception("Allowlist request failed: ${response.body}"); | ||
| } | ||
|
|
||
| return DfxAllowlistStatus.fromJson(jsonDecode(response.body)); | ||
| } | ||
| } |
This file contains hidden or 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,23 @@ | ||
| import 'dart:convert'; | ||
|
|
||
| import 'package:realunit_wallet/packages/service/app_store.dart'; | ||
| import 'package:realunit_wallet/packages/service/dfx/models/dfx_bank_details.dart'; | ||
|
|
||
| class DfxBankDetailsService { | ||
| static const _baseUrl = "https://dev.api.dfx.swiss/v1/realunit"; | ||
| final AppStore _appStore; | ||
|
|
||
| DfxBankDetailsService(this._appStore); | ||
|
|
||
| Future<BankDetails> getBankDetails() async { | ||
| final url = Uri.parse("$_baseUrl/bank"); | ||
| final response = await _appStore.httpClient.get(url); | ||
|
|
||
| if (response.statusCode != 200) { | ||
| throw Exception("Bank details request failed: ${response.body}"); | ||
| } | ||
|
|
||
| final json = jsonDecode(response.body); | ||
| return BankDetails.fromJson(json); | ||
| } | ||
| } |
This file contains hidden or 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,36 @@ | ||
| import 'dart:convert'; | ||
|
|
||
| import 'package:realunit_wallet/packages/service/app_store.dart'; | ||
| import 'package:realunit_wallet/packages/service/dfx/models/brokerbot/dfx_buy_price_dto.dart'; | ||
| import 'package:realunit_wallet/packages/service/dfx/models/brokerbot/dfx_shares_dto.dart'; | ||
|
|
||
| class DfxBrokerbotService { | ||
| static const _baseUrl = "https://dev.api.dfx.swiss/v1/realunit/brokerbot"; | ||
| final AppStore _appStore; | ||
|
|
||
| DfxBrokerbotService(this._appStore); | ||
|
|
||
| /// Convert REALU shares → CHF | ||
| Future<BrokerbotBuyPriceDto> getBuyPrice(int shares) async { | ||
| final url = Uri.parse("$_baseUrl/buyPrice?shares=$shares"); | ||
| final res = await _appStore.httpClient.get(url); | ||
|
|
||
| if (res.statusCode != 200) { | ||
| throw Exception("BuyPrice request failed: ${res.body}"); | ||
| } | ||
|
|
||
| return BrokerbotBuyPriceDto.fromJson(jsonDecode(res.body)); | ||
| } | ||
|
|
||
| /// Convert CHF → REALU shares | ||
| Future<BrokerbotSharesDto> getShares(double amount) async { | ||
| final url = Uri.parse("$_baseUrl/shares?amount=$amount"); | ||
| final res = await _appStore.httpClient.get(url); | ||
|
|
||
| if (res.statusCode != 200) { | ||
| throw Exception("Shares request failed: ${res.body}"); | ||
| } | ||
|
|
||
| return BrokerbotSharesDto.fromJson(jsonDecode(res.body)); | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
lib/packages/service/dfx/models/brokerbot/dfx_buy_price_dto.dart
This file contains hidden or 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,22 @@ | ||
| class BrokerbotBuyPriceDto { | ||
| final double totalCost; | ||
| final double pricePerShare; | ||
|
|
||
| BrokerbotBuyPriceDto({ | ||
| required this.totalCost, | ||
| required this.pricePerShare, | ||
| }); | ||
|
|
||
| factory BrokerbotBuyPriceDto.fromJson(Map<String, dynamic> json) { | ||
| double parseDouble(dynamic value) { | ||
| if (value == null) return 0.0; | ||
| final s = value.toString().replaceAll(',', '.').trim(); | ||
| return double.tryParse(s) ?? 0.0; | ||
| } | ||
|
|
||
| return BrokerbotBuyPriceDto( | ||
| totalCost: parseDouble(json['totalPrice']), | ||
| pricePerShare: parseDouble(json['pricePerShare']), | ||
| ); | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
lib/packages/service/dfx/models/brokerbot/dfx_shares_dto.dart
This file contains hidden or 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,16 @@ | ||
| class BrokerbotSharesDto { | ||
| final int shares; | ||
| final double pricePerShare; | ||
|
|
||
| BrokerbotSharesDto({ | ||
| required this.shares, | ||
| required this.pricePerShare, | ||
| }); | ||
|
|
||
| factory BrokerbotSharesDto.fromJson(Map<String, dynamic> json) { | ||
| return BrokerbotSharesDto( | ||
| shares: int.parse(json['shares'].toString()), | ||
| pricePerShare: double.parse(json['pricePerShare'].toString()), | ||
| ); | ||
| } | ||
| } |
This file contains hidden or 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,28 @@ | ||
| class DfxAllowlistStatus { | ||
| final String address; | ||
|
|
||
| /// Address needs to be registered as RealUnit customer to be able to receive. | ||
| final bool canReceive; | ||
|
|
||
| /// Address is suspended, buying is not possible. | ||
| final bool isForbidden; | ||
|
|
||
| /// Privileged address. | ||
| final bool isPowerlisted; | ||
|
|
||
| DfxAllowlistStatus({ | ||
| required this.address, | ||
| required this.canReceive, | ||
| required this.isForbidden, | ||
| required this.isPowerlisted, | ||
| }); | ||
|
|
||
| factory DfxAllowlistStatus.fromJson(Map<String, dynamic> json) { | ||
| return DfxAllowlistStatus( | ||
| address: json['address'] as String, | ||
| canReceive: json['canReceive'] as bool, | ||
| isForbidden: json['isForbidden'] as bool, | ||
| isPowerlisted: json['isPowerlisted'] as bool, | ||
| ); | ||
| } | ||
| } |
This file contains hidden or 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,26 @@ | ||
| class BankDetails { | ||
| final String recipient; | ||
| final String address; | ||
| final String iban; | ||
| final String bic; | ||
| final String bankName; | ||
| final String currency; | ||
|
|
||
| const BankDetails({ | ||
| required this.recipient, | ||
| required this.address, | ||
| required this.iban, | ||
| required this.bic, | ||
| required this.bankName, | ||
| required this.currency, | ||
| }); | ||
|
|
||
| factory BankDetails.fromJson(Map<String, dynamic> json) => BankDetails( | ||
| recipient: json['recipient'], | ||
| address: json['address'], | ||
| iban: json['iban'], | ||
| bic: json['bic'], | ||
| bankName: json['bankName'], | ||
| currency: json['currency'], | ||
| ); | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Where does this change come from?
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.
I changed the name from
RealUnit AktientokentoRealUnit Token