-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: integrate stellar wallet (#1497)
Co-authored-by: Kirill Bubochkin <[email protected]>
- Loading branch information
1 parent
b02b493
commit 88429d2
Showing
8 changed files
with
127 additions
and
9 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
1 change: 0 additions & 1 deletion
1
packages/espressocash_app/lib/features/sign_in/services/sign_in_bloc.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
28 changes: 28 additions & 0 deletions
28
packages/espressocash_app/lib/features/stellar/constants.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,28 @@ | ||
import 'package:stellar_flutter_sdk/stellar_flutter_sdk.dart'; | ||
|
||
const _isStellarProd = | ||
bool.fromEnvironment('STELLAR_PROD', defaultValue: false); | ||
|
||
final stellarNetwork = _isStellarProd ? Network.PUBLIC : Network.TESTNET; | ||
final stellarSdk = _isStellarProd ? StellarSDK.PUBLIC : StellarSDK.TESTNET; | ||
|
||
const _devBaseUrl = 'https://extstellar.moneygram.com/stellaradapterservice'; | ||
const _prodBaseUrl = 'https://stellar.moneygram.com/stellaradapterservice'; | ||
const moneygramBaseUrl = _isStellarProd ? _prodBaseUrl : _devBaseUrl; | ||
|
||
const _devSigningKey = | ||
'GCSESAP5ILVM6CWIEGK2SDOCQU7PHVFYYT7JNKRDAQNVQWKD5YEE5ZJ4'; | ||
const _prodSigningKey = | ||
'GD5NUMEX7LYHXGXCAD4PGW7JDMOUY2DKRGY5XZHJS5IONVHDKCJYGVCL'; | ||
const moneygramSigningKey = _isStellarProd ? _prodSigningKey : _devSigningKey; | ||
|
||
const _devAssetIssuer = | ||
'GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5'; | ||
const _prodAssetIssuer = | ||
'GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN'; | ||
const moneygramAssetIssuer = | ||
_isStellarProd ? _prodAssetIssuer : _devAssetIssuer; | ||
|
||
const _devAuthDomain = 'stellar-dev.espressocash.com'; | ||
const _prodAuthDomain = 'espressocash.com'; | ||
const espressoClientDomain = _isStellarProd ? _prodAuthDomain : _devAuthDomain; |
19 changes: 19 additions & 0 deletions
19
packages/espressocash_app/lib/features/stellar/models/stellar_wallet.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,19 @@ | ||
import 'dart:typed_data'; | ||
|
||
import 'package:stellar_flutter_sdk/stellar_flutter_sdk.dart'; | ||
|
||
Future<StellarWallet> createStellarWallet({required String mnemonic}) async { | ||
final wallet = await Wallet.from(mnemonic); | ||
|
||
return StellarWallet(await wallet.getKeyPair()); | ||
} | ||
|
||
class StellarWallet { | ||
const StellarWallet(this.keyPair); | ||
|
||
final KeyPair keyPair; | ||
|
||
String get address => keyPair.accountId; | ||
|
||
Uint8List sign(Uint8List payload) => keyPair.sign(payload); | ||
} |
24 changes: 24 additions & 0 deletions
24
packages/espressocash_app/lib/features/stellar/service/stellar_client.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,24 @@ | ||
import 'package:stellar_flutter_sdk/stellar_flutter_sdk.dart'; | ||
|
||
class StellarClient { | ||
const StellarClient(this._sdk); | ||
|
||
final StellarSDK _sdk; | ||
|
||
Future<double> getXlmBalance(String accountId) async { | ||
try { | ||
final account = await _sdk.accounts.account(accountId); | ||
final nativeAsset = AssetTypeNative(); | ||
|
||
for (final balance in account.balances) { | ||
if (balance.assetType == nativeAsset.type) { | ||
return double.parse(balance.balance); | ||
} | ||
} | ||
} on Exception { | ||
return 0.0; | ||
} | ||
|
||
return 0.0; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
packages/espressocash_app/lib/features/stellar/stellar_module.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,23 @@ | ||
import 'package:injectable/injectable.dart'; | ||
|
||
import '../accounts/auth_scope.dart'; | ||
import '../accounts/data/account_repository.dart'; | ||
import 'constants.dart'; | ||
import 'models/stellar_wallet.dart'; | ||
import 'service/stellar_client.dart'; | ||
|
||
@module | ||
abstract class StellarModule { | ||
const StellarModule(); | ||
|
||
@Singleton(scope: authScope) | ||
@preResolve | ||
Future<StellarWallet> wallet(AccountRepository repository) async { | ||
final mnemonic = await repository.loadMnemonic(); | ||
|
||
return createStellarWallet(mnemonic: mnemonic); | ||
} | ||
|
||
@LazySingleton(scope: authScope) | ||
StellarClient stellarClient() => StellarClient(stellarSdk); | ||
} |
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