Add trocador provider and password to transaction details

This commit is contained in:
Godwin Asuquo 2023-02-07 19:39:39 +02:00
parent f770e095a1
commit f1b0a5adb6
3 changed files with 67 additions and 43 deletions

View file

@ -8,21 +8,25 @@ part 'trade.g.dart';
@HiveType(typeId: Trade.typeId) @HiveType(typeId: Trade.typeId)
class Trade extends HiveObject { class Trade extends HiveObject {
Trade( Trade({
{required this.id, required this.id,
required this.amount, required this.amount,
ExchangeProviderDescription? provider, ExchangeProviderDescription? provider,
CryptoCurrency? from, CryptoCurrency? from,
CryptoCurrency? to, CryptoCurrency? to,
TradeState? state, TradeState? state,
this.createdAt, this.createdAt,
this.expiredAt, this.expiredAt,
this.inputAddress, this.inputAddress,
this.extraId, this.extraId,
this.outputTransaction, this.outputTransaction,
this.refundAddress, this.refundAddress,
this.walletId, this.walletId,
this.payoutAddress}) { this.payoutAddress,
this.password,
this.providerId,
this.providerName,
}) {
if (provider != null) { if (provider != null) {
providerRaw = provider.raw; providerRaw = provider.raw;
} }
@ -92,16 +96,23 @@ class Trade extends HiveObject {
@HiveField(13) @HiveField(13)
String? payoutAddress; String? payoutAddress;
@HiveField(14)
String? password;
@HiveField(15)
String? providerId;
@HiveField(16)
String? providerName;
static Trade fromMap(Map<String, Object?> map) { static Trade fromMap(Map<String, Object?> map) {
return Trade( return Trade(
id: map['id'] as String, id: map['id'] as String,
provider: ExchangeProviderDescription.deserialize( provider: ExchangeProviderDescription.deserialize(raw: map['provider'] as int),
raw: map['provider'] as int),
from: CryptoCurrency.deserialize(raw: map['input'] as int), from: CryptoCurrency.deserialize(raw: map['input'] as int),
to: CryptoCurrency.deserialize(raw: map['output'] as int), to: CryptoCurrency.deserialize(raw: map['output'] as int),
createdAt: map['date'] != null createdAt:
? DateTime.fromMillisecondsSinceEpoch(map['date'] as int) map['date'] != null ? DateTime.fromMillisecondsSinceEpoch(map['date'] as int) : null,
: null,
amount: map['amount'] as String, amount: map['amount'] as String,
walletId: map['wallet_id'] as String); walletId: map['wallet_id'] as String);
} }

View file

@ -113,6 +113,9 @@ class TrocadorExchangeProvider extends ExchangeProvider {
final state = TradeState.deserialize(raw: status); final state = TradeState.deserialize(raw: status);
final payoutAddress = responseJSON['address_user'] as String; final payoutAddress = responseJSON['address_user'] as String;
final date = responseJSON['date'] as String; final date = responseJSON['date'] as String;
final password = responseJSON['password'] as String;
final providerId = responseJSON['id_provider'] as String;
final providerName = responseJSON['provider'] as String;
return Trade( return Trade(
id: id, id: id,
@ -122,6 +125,9 @@ class TrocadorExchangeProvider extends ExchangeProvider {
inputAddress: inputAddress, inputAddress: inputAddress,
refundAddress: refundAddress, refundAddress: refundAddress,
state: state, state: state,
password: password,
providerId: providerId,
providerName: providerName,
createdAt: DateTime.tryParse(date)?.toLocal(), createdAt: DateTime.tryParse(date)?.toLocal(),
amount: responseJSON['amount_from']?.toString() ?? request.fromAmount, amount: responseJSON['amount_from']?.toString() ?? request.fromAmount,
payoutAddress: payoutAddress); payoutAddress: payoutAddress);
@ -208,6 +214,9 @@ class TrocadorExchangeProvider extends ExchangeProvider {
final to = CryptoCurrency.fromString(responseJSON['ticker_to'] as String); final to = CryptoCurrency.fromString(responseJSON['ticker_to'] as String);
final state = TradeState.deserialize(raw: responseJSON['status'] as String); final state = TradeState.deserialize(raw: responseJSON['status'] as String);
final date = DateTime.parse(responseJSON['date'] as String); final date = DateTime.parse(responseJSON['date'] as String);
final password = responseJSON['password'] as String;
final providerId = responseJSON['id_provider'] as String;
final providerName = responseJSON['provider'] as String;
return Trade( return Trade(
id: id, id: id,
@ -220,6 +229,9 @@ class TrocadorExchangeProvider extends ExchangeProvider {
amount: fromAmount, amount: fromAmount,
state: state, state: state,
payoutAddress: payoutAddress, payoutAddress: payoutAddress,
password: password,
providerId: providerId,
providerName: providerName,
); );
}); });
} }

View file

@ -23,16 +23,15 @@ import 'package:cake_wallet/src/screens/trade_details/trade_details_status_item.
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
part 'trade_details_view_model.g.dart'; part 'trade_details_view_model.g.dart';
class TradeDetailsViewModel = TradeDetailsViewModelBase class TradeDetailsViewModel = TradeDetailsViewModelBase with _$TradeDetailsViewModel;
with _$TradeDetailsViewModel;
abstract class TradeDetailsViewModelBase with Store { abstract class TradeDetailsViewModelBase with Store {
TradeDetailsViewModelBase({ TradeDetailsViewModelBase({
required Trade tradeForDetails, required Trade tradeForDetails,
required this.trades, required this.trades,
required this.settingsStore}) required this.settingsStore,
: items = ObservableList<StandartListItem>(), }) : items = ObservableList<StandartListItem>(),
trade = tradeForDetails { trade = tradeForDetails {
switch (trade.provider) { switch (trade.provider) {
case ExchangeProviderDescription.xmrto: case ExchangeProviderDescription.xmrto:
_provider = XMRTOExchangeProvider(); _provider = XMRTOExchangeProvider();
@ -46,7 +45,7 @@ abstract class TradeDetailsViewModelBase with Store {
case ExchangeProviderDescription.sideShift: case ExchangeProviderDescription.sideShift:
_provider = SideShiftExchangeProvider(); _provider = SideShiftExchangeProvider();
break; break;
case ExchangeProviderDescription.simpleSwap: case ExchangeProviderDescription.simpleSwap:
_provider = SimpleSwapExchangeProvider(); _provider = SimpleSwapExchangeProvider();
break; break;
case ExchangeProviderDescription.trocador: case ExchangeProviderDescription.trocador:
@ -100,12 +99,7 @@ abstract class TradeDetailsViewModelBase with Store {
items.clear(); items.clear();
items.add( items.add(
DetailsListStatusItem( DetailsListStatusItem(title: S.current.trade_details_state, value: trade.state.toString()));
title: S.current.trade_details_state,
value: trade.state != null
? trade.state.toString()
: S.current.trade_details_fetching)
);
items.add(TradeDetailsListCardItem.tradeDetails( items.add(TradeDetailsListCardItem.tradeDetails(
id: trade.id, id: trade.id,
@ -118,15 +112,11 @@ abstract class TradeDetailsViewModelBase with Store {
}, },
)); ));
if (trade.provider != null) { items.add(StandartListItem(
items.add(StandartListItem( title: S.current.trade_details_provider, value: trade.provider.toString()));
title: S.current.trade_details_provider,
value: trade.provider.toString()));
}
if (trade.provider == ExchangeProviderDescription.changeNow) { if (trade.provider == ExchangeProviderDescription.changeNow) {
final buildURL = final buildURL = 'https://changenow.io/exchange/txs/${trade.id.toString()}';
'https://changenow.io/exchange/txs/${trade.id.toString()}';
items.add(TrackTradeListItem( items.add(TrackTradeListItem(
title: 'Track', title: 'Track',
value: buildURL, value: buildURL,
@ -137,14 +127,25 @@ abstract class TradeDetailsViewModelBase with Store {
if (trade.provider == ExchangeProviderDescription.sideShift) { if (trade.provider == ExchangeProviderDescription.sideShift) {
final buildURL = 'https://sideshift.ai/orders/${trade.id.toString()}'; final buildURL = 'https://sideshift.ai/orders/${trade.id.toString()}';
items.add(TrackTradeListItem( items.add(TrackTradeListItem(title: 'Track', value: buildURL, onTap: () => launch(buildURL)));
title: 'Track', value: buildURL, onTap: () => launch(buildURL)));
} }
if (trade.provider == ExchangeProviderDescription.simpleSwap) { if (trade.provider == ExchangeProviderDescription.simpleSwap) {
final buildURL = 'https://simpleswap.io/exchange?id=${trade.id.toString()}'; final buildURL = 'https://simpleswap.io/exchange?id=${trade.id.toString()}';
items.add(TrackTradeListItem( items.add(TrackTradeListItem(title: 'Track', value: buildURL, onTap: () => launch(buildURL)));
title: 'Track', value: buildURL, onTap: () => launch(buildURL))); }
if (trade.provider == ExchangeProviderDescription.trocador) {
final buildURL = 'https://trocador.app/en/checkout/${trade.id.toString()}';
items.add(TrackTradeListItem(title: 'Track', value: buildURL, onTap: () => launch(buildURL)));
items.add(StandartListItem(
title: '${trade.providerName} ${S.current.id.toUpperCase()}',
value: trade.providerId ?? ''));
if (trade.password != null && trade.password!.isNotEmpty)
items.add(StandartListItem(
title: '${trade.providerName} ${S.current.password}', value: trade.password ?? ''));
} }
} }
} }