Skip to content

Commit

Permalink
Merge branch 'master' into feat/store-token-list-localdb
Browse files Browse the repository at this point in the history
  • Loading branch information
justinenerio committed Sep 12, 2024
2 parents f351ecc + 1da19d7 commit dc4c0b6
Show file tree
Hide file tree
Showing 16 changed files with 207 additions and 154 deletions.
5 changes: 5 additions & 0 deletions packages/espressocash_app/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.126.1

- **FIX**: moneygram ramp fixes (#1562).
- **FIX**: stellar recovery service init (#1561).

## 1.126.0

- **FIX**: Solana v.2 tests (#1554).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,79 +111,51 @@ class _HomeScrollableRegion extends StatelessWidget {

@override
Widget build(BuildContext context) => ClipRRect(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(31),
topRight: Radius.circular(31),
),
borderRadius: _borderRadius,
child: SingleChildScrollView(
physics: const BouncingScrollPhysics(),
padding: EdgeInsets.only(
bottom: MediaQuery.paddingOf(context).bottom,
),
child: Stack(
child: Column(
children: [
Positioned(
top: 200,
child: Container(
height: 300,
width: MediaQuery.sizeOf(context).width,
const InvestmentHeader(),
DecoratedBox(
decoration: const BoxDecoration(
color: CpColors.dashboardBackgroundColor,
borderRadius: _borderRadius,
boxShadow: _dashboardBoxShadow,
),
child: _Buttons(
onSendMoneyPressed: onSendMoneyPressed,
),
),
Column(
children: [
const InvestmentHeader(),
DecoratedBox(
decoration: const BoxDecoration(
color: CpColors.dashboardBackgroundColor,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(31),
topRight: Radius.circular(31),
),
),
child: _Buttons(
onSendMoneyPressed: onSendMoneyPressed,
),
),
Container(
padding: const EdgeInsets.only(
top: 28,
bottom: 18,
),
color: CpColors.dashboardBackgroundColor,
child: const Divider(
color: CpColors.homeDividerColor,
thickness: 1.0,
height: 1.0,
),
const _HomeDivider(),
ValueStreamBuilder<IList<CryptoAmount>>(
create: () => (
sl<TokenBalancesRepository>().watchTokenBalances(
ignoreTokens: [Token.usdc],
),
ValueStreamBuilder<IList<CryptoAmount>>(
create: () => (
sl<TokenBalancesRepository>().watchTokenBalances(
ignoreTokens: [Token.usdc],
const IListConst([])
),
builder: (context, tokens) => tokens.isNotEmpty
? const SizedBox.shrink()
: HomeCarouselWidget(
onSendMoneyPressed: onSendMoneyPressed,
),
const IListConst([])
),
builder: (context, tokens) => tokens.isNotEmpty
? const SizedBox.shrink()
: HomeCarouselWidget(
onSendMoneyPressed: onSendMoneyPressed,
),
),
const PortfolioWidget(),
RecentActivityWidget(
onSendMoneyPressed: onSendMoneyPressed,
onTransactionsPressed: onTransactionsPressed,
),
SizedBox(
height: max(
0,
MediaQuery.paddingOf(context).bottom -
cpNavigationBarheight +
16,
),
),
],
),
const PortfolioWidget(),
RecentActivityWidget(
onSendMoneyPressed: onSendMoneyPressed,
onTransactionsPressed: onTransactionsPressed,
),
SizedBox(
height: max(
0,
MediaQuery.paddingOf(context).bottom -
cpNavigationBarheight +
16,
),
),
],
),
Expand Down Expand Up @@ -241,3 +213,32 @@ class _Buttons extends StatelessWidget {
),
);
}

class _HomeDivider extends StatelessWidget {
const _HomeDivider();

@override
Widget build(BuildContext context) => Container(
padding: const EdgeInsets.only(
top: 28,
bottom: 18,
),
decoration: const BoxDecoration(
color: CpColors.dashboardBackgroundColor,
boxShadow: _dashboardBoxShadow,
),
child: const Divider(
color: CpColors.homeDividerColor,
thickness: 1.0,
height: 1.0,
),
);
}

const _borderRadius = BorderRadius.vertical(top: Radius.circular(31));
const _dashboardBoxShadow = [
BoxShadow(
color: CpColors.dashboardBackgroundColor,
offset: Offset(0, 2),
),
];
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class _RefreshBalancesWrapperState extends State<RefreshBalancesWrapper> {
AsyncResult<void> _updateConversionRates() async {
final tokens = await sl<TokenBalancesRepository>().readUserTokens();

if (tokens.isEmpty) return const Either.right(null);

return sl<ConversionRatesRepository>()
.refresh(defaultFiatCurrency, tokens)
.doOnLeftAsync((_) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

import 'package:dfunc/dfunc.dart';
import 'package:dio/dio.dart';
import 'package:espressocash_api/espressocash_api.dart';
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
import 'package:get_it/get_it.dart';
Expand All @@ -9,6 +10,7 @@ import 'package:solana/base58.dart';
import 'package:solana/solana.dart';
import 'package:uuid/uuid.dart';

import '../../../utils/errors.dart';
import '../../accounts/auth_scope.dart';
import '../../accounts/models/ec_wallet.dart';
import '../../analytics/analytics_manager.dart';
Expand Down Expand Up @@ -221,10 +223,16 @@ class OLPService implements Disposable {
signature: signature,
),
);
} on Exception {
} on Exception catch (error) {
TxFailureReason reason = TxFailureReason.creatingFailure;

if (error is DioException &&
error.toEspressoCashError() == EspressoCashError.insufficientFunds) {
reason = TxFailureReason.insufficientFunds;
}

return payment.copyWith(
status:
const OLPStatus.txFailure(reason: TxFailureReason.creatingFailure),
status: OLPStatus.txFailure(reason: reason),
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class MoneygramOffRampOrderService implements Disposable {
transaction: '',
depositAddress: '',
slot: BigInt.zero,
bridgeAmount: 0,
bridgeAmount: null,
);

await _db.into(_db.offRampOrderRows).insert(order);
Expand Down Expand Up @@ -492,7 +492,7 @@ class MoneygramOffRampOrderService implements Disposable {

final receiveAmount = Amount.fromDecimal(
value: Decimal.parse(transaction.amountOut ?? '0'),
currency: Currency.usd,
currency: currencyFromString(transaction.amountOutAsset ?? 'USD'),
) as FiatAmount;

final fee = Amount.fromDecimal(
Expand Down Expand Up @@ -649,17 +649,23 @@ class MoneygramOffRampOrderService implements Disposable {
cryptoCurrency: Currency.usdc,
);

final transactionSucceed = await _stellarClient.sendUsdc(
destinationAddress: order.withdrawAnchorAccount ?? '',
memo: order.withdrawMemo ?? '',
amount: amount.decimal.toString(),
);
try {
final transactionSucceed = await _stellarClient.sendUsdc(
destinationAddress: order.withdrawAnchorAccount ?? '',
memo: order.withdrawMemo ?? '',
amount: amount.decimal.toString(),
);

return transactionSucceed
? const OffRampOrderRowsCompanion(
status: Value(OffRampOrderStatus.waitingForPartner),
)
: null;
return transactionSucceed
? const OffRampOrderRowsCompanion(
status: Value(OffRampOrderStatus.waitingForPartner),
)
: null;
} on Exception catch (error, stackTrace) {
reportError(error, stackTrace);

return null;
}
}

Future<OffRampOrderRowsCompanion?> _processRefund(
Expand All @@ -673,28 +679,16 @@ class MoneygramOffRampOrderService implements Disposable {
);
}

final response = await _allbridgeApiClient
.fetchStatus(
chain: Chain.solana,
hash: order.solanaBridgeTx ?? '',
)
.then((e) => e?.receive);

if (response == null) {
return const OffRampOrderRowsCompanion(
status: Value(OffRampOrderStatus.processingRefund),
);
}

final amount = int.parse(response.amount) ~/ 10;

final solanaAddress = _ecWallet.address;
final amount = CryptoAmount(
value: order.bridgeAmount ?? 0,
cryptoCurrency: Currency.usdc,
);

final refundAmount = await _ecClient
.calculateMoneygramFee(
MoneygramFeeRequestDto(
type: RampTypeDto.onRamp,
amount: (int.parse(response.amount) / 10000000).toString(),
amount: amount.decimal.toString(),
),
)
.then(
Expand All @@ -707,9 +701,9 @@ class MoneygramOffRampOrderService implements Disposable {
final bridgeTx = await _ecClient
.swapToSolana(
SwapToSolanaRequestDto(
amount: amount.toStringAsFixed(0),
amount: amount.value.toString(),
stellarSenderAddress: _stellarWallet.address,
solanaReceiverAddress: solanaAddress,
solanaReceiverAddress: _ecWallet.address,
),
)
.then((e) => e.encodedTx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class MoneygramOnRampOrderService implements Disposable {

final feeAmount = Amount.fromDecimal(
value: Decimal.parse(transaction.amountFee ?? '0'),
currency: currencyFromString(transaction.amountInAsset ?? 'USD'),
currency: currencyFromString(transaction.amountFeeAsset ?? 'USD'),
) as FiatAmount;

return OnRampOrderRowsCompanion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import '../../../../../ui/theme.dart';
import '../../../../../ui/web_view_screen.dart';
import '../../../services/off_ramp_order_service.dart';
import '../service/moneygram_off_ramp_service.dart';
import 'style.dart';

extension BuildContextExt on BuildContext {
Future<void> openMoneygramWithdrawUrl(OffRampOrder order) async {
Expand All @@ -29,6 +30,8 @@ extension BuildContextExt on BuildContext {

bool orderWasCreated = false;
Future<void> handleLoaded(InAppWebViewController controller) async {
await controller.evaluateJavascript(source: await loadMoneygramStyle());

controller.addJavaScriptHandler(
handlerName: 'moneygram',
callback: (args) async {
Expand Down Expand Up @@ -72,6 +75,11 @@ window.addEventListener("message", (event) => {
url: Uri.parse(order.moreInfoUrl ?? ''),
title: l10n.offRampWithdrawTitle.toUpperCase(),
theme: const CpThemeData.light(),
onLoaded: (controller) async {
await controller.evaluateJavascript(
source: await loadMoneygramStyle(),
);
},
);

await sl<MoneygramOffRampOrderService>().processRefund(order.id);
Expand Down
Loading

0 comments on commit dc4c0b6

Please sign in to comment.