Skip to content

Commit

Permalink
receive - ln swap - bloc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mocodesmo committed Feb 12, 2024
1 parent 7065602 commit 929df9a
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 38 deletions.
14 changes: 8 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
"dart.lineLength": 100,
"files.exclude": {
"**/.metadata": true,
// "**/.packages": true,
// "**/pubspec.lock": true,
// "**/.flutter-plugins": true,
// "**/.dart_tool": true,
"**/.packages": true,
"**/pubspec.lock": true,
"**/.flutter-plugins": true,
"**/.dart_tool": true,
"**/.flutter-plugins-dependencies": true,
"**/generated_plugin_registrant.dart": true,
"**/CHANGELOG.md": true,
Expand All @@ -45,7 +45,7 @@
".idea": true,
".gitignore": true,
//
// "**/analysis_options.yaml": true,
"**/analysis_options.yaml": true,
"build.yaml": true,
"**/build": true,
"**/assets": true,
Expand All @@ -62,8 +62,10 @@
"ios": true,
//
//
// "**/pubspec.yaml": true,
"**/pubspec.yaml": true,
//
//
"**/test": true,
"integration_test": true,
},
}
2 changes: 1 addition & 1 deletion lib/_model/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Transaction with _$Transaction {
)
bdk.TransactionDetails? bdkTx,
Wallet? wallet,
@Default(false) isSwap,
@Default(false) bool isSwap,
int? swapIndex,
SwapTx? swapTx,
}) = _Transaction;
Expand Down
29 changes: 16 additions & 13 deletions lib/_model/transaction.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ mixin _$Transaction {
@JsonKey(includeFromJson: false, includeToJson: false)
bdk.TransactionDetails? get bdkTx => throw _privateConstructorUsedError;
Wallet? get wallet => throw _privateConstructorUsedError;
dynamic get isSwap => throw _privateConstructorUsedError;
bool get isSwap => throw _privateConstructorUsedError;
int? get swapIndex => throw _privateConstructorUsedError;
SwapTx? get swapTx => throw _privateConstructorUsedError;

Expand Down Expand Up @@ -70,7 +70,7 @@ abstract class $TransactionCopyWith<$Res> {
@JsonKey(includeFromJson: false, includeToJson: false)
bdk.TransactionDetails? bdkTx,
Wallet? wallet,
dynamic isSwap,
bool isSwap,
int? swapIndex,
SwapTx? swapTx});

Expand Down Expand Up @@ -106,7 +106,7 @@ class _$TransactionCopyWithImpl<$Res, $Val extends Transaction>
Object? outAddrs = null,
Object? bdkTx = freezed,
Object? wallet = freezed,
Object? isSwap = freezed,
Object? isSwap = null,
Object? swapIndex = freezed,
Object? swapTx = freezed,
}) {
Expand Down Expand Up @@ -171,10 +171,10 @@ class _$TransactionCopyWithImpl<$Res, $Val extends Transaction>
? _value.wallet
: wallet // ignore: cast_nullable_to_non_nullable
as Wallet?,
isSwap: freezed == isSwap
isSwap: null == isSwap
? _value.isSwap
: isSwap // ignore: cast_nullable_to_non_nullable
as dynamic,
as bool,
swapIndex: freezed == swapIndex
? _value.swapIndex
: swapIndex // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -236,7 +236,7 @@ abstract class _$$TransactionImplCopyWith<$Res>
@JsonKey(includeFromJson: false, includeToJson: false)
bdk.TransactionDetails? bdkTx,
Wallet? wallet,
dynamic isSwap,
bool isSwap,
int? swapIndex,
SwapTx? swapTx});

Expand Down Expand Up @@ -272,7 +272,7 @@ class __$$TransactionImplCopyWithImpl<$Res>
Object? outAddrs = null,
Object? bdkTx = freezed,
Object? wallet = freezed,
Object? isSwap = freezed,
Object? isSwap = null,
Object? swapIndex = freezed,
Object? swapTx = freezed,
}) {
Expand Down Expand Up @@ -337,7 +337,10 @@ class __$$TransactionImplCopyWithImpl<$Res>
? _value.wallet
: wallet // ignore: cast_nullable_to_non_nullable
as Wallet?,
isSwap: freezed == isSwap ? _value.isSwap! : isSwap,
isSwap: null == isSwap
? _value.isSwap
: isSwap // ignore: cast_nullable_to_non_nullable
as bool,
swapIndex: freezed == swapIndex
? _value.swapIndex
: swapIndex // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -422,7 +425,7 @@ class _$TransactionImpl extends _Transaction {
final Wallet? wallet;
@override
@JsonKey()
final dynamic isSwap;
final bool isSwap;
@override
final int? swapIndex;
@override
Expand Down Expand Up @@ -458,7 +461,7 @@ class _$TransactionImpl extends _Transaction {
const DeepCollectionEquality().equals(other._outAddrs, _outAddrs) &&
(identical(other.bdkTx, bdkTx) || other.bdkTx == bdkTx) &&
(identical(other.wallet, wallet) || other.wallet == wallet) &&
const DeepCollectionEquality().equals(other.isSwap, isSwap) &&
(identical(other.isSwap, isSwap) || other.isSwap == isSwap) &&
(identical(other.swapIndex, swapIndex) ||
other.swapIndex == swapIndex) &&
(identical(other.swapTx, swapTx) || other.swapTx == swapTx));
Expand All @@ -483,7 +486,7 @@ class _$TransactionImpl extends _Transaction {
const DeepCollectionEquality().hash(_outAddrs),
bdkTx,
wallet,
const DeepCollectionEquality().hash(isSwap),
isSwap,
swapIndex,
swapTx);

Expand Down Expand Up @@ -519,7 +522,7 @@ abstract class _Transaction extends Transaction {
@JsonKey(includeFromJson: false, includeToJson: false)
final bdk.TransactionDetails? bdkTx,
final Wallet? wallet,
final dynamic isSwap,
final bool isSwap,
final int? swapIndex,
final SwapTx? swapTx}) = _$TransactionImpl;
const _Transaction._() : super._();
Expand Down Expand Up @@ -559,7 +562,7 @@ abstract class _Transaction extends Transaction {
@override
Wallet? get wallet;
@override
dynamic get isSwap;
bool get isSwap;
@override
int? get swapIndex;
@override
Expand Down
2 changes: 1 addition & 1 deletion lib/_model/transaction.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 27 additions & 6 deletions lib/receive/bloc/receive_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class ReceiveCubit extends Cubit<ReceiveState> {
loadAddress();
}
final SettingsCubit settingsCubit;
// final WalletBloc walletBloc;
final WalletAddress walletAddress;
final HiveStorage hiveStorage;
final SecureStorage secureStorage;
Expand Down Expand Up @@ -99,7 +98,7 @@ class ReceiveCubit extends Cubit<ReceiveState> {

final (swap, errCreatingInv) = await swapBoltz.receive(
mnemonic: seed!.mnemonic,
index: 1,
index: state.walletBloc!.state.wallet!.swapTxCount,
outAmount: outAmount,
network: Chain.Testnet,
electrumUrl: networkCubit.state.getNetworkUrl(),
Expand Down Expand Up @@ -144,9 +143,11 @@ class ReceiveCubit extends Cubit<ReceiveState> {
return;
}

final swapTxCount = updatedWallet.swapTxCount + 1;

state.walletBloc!.add(
UpdateWallet(
updatedWallet,
updatedWallet.copyWith(swapTxCount: swapTxCount),
updateTypes: [UpdateWalletTypes.transactions],
),
);
Expand Down Expand Up @@ -181,6 +182,28 @@ class ReceiveCubit extends Cubit<ReceiveState> {
}
}

void resetToNewLnInvoice() async {
if (state.walletBloc == null) return;

emit(
state.copyWith(
errLoadingAddress: '',
savedInvoiceAmount: 0,
creatingInvoice: true,
errCreatingInvoice: '',
defaultAddress: null,
swapTx: null,
),
);
currencyCubit.reset();
}

void loadAllSwapTxs() {
if (state.walletBloc == null) return;
final swapTxs = state.walletBloc!.state.wallet!.transactions.where((tx) => tx.isSwap).toList();
emit(state.copyWith(swapTxs: swapTxs));
}

void loadAddress() async {
if (state.walletBloc == null) return;
emit(state.copyWith(loadingAddress: true, errLoadingAddress: ''));
Expand Down Expand Up @@ -208,11 +231,9 @@ class ReceiveCubit extends Cubit<ReceiveState> {
);
}

void generateNewLightningInvoice() async {}

void generateNewAddress() async {
if (state.walletType == ReceiveWalletType.lightning) {
generateNewLightningInvoice();
resetToNewLnInvoice();
return;
}

Expand Down
4 changes: 1 addition & 3 deletions lib/receive/bloc/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ class ReceiveState with _$ReceiveState {
@Default('') String errGeneratingInvoice,
@Default(false) bool generatingInvoice,
SwapTx? swapTx,
// BtcLnSwap? btcLnSwap,
// LbtcLnSwap? lbtcLnSwap,
// Address? newInvoiceAddress,
List<Transaction>? swapTxs,
}) = _ReceiveState;
const ReceiveState._();

Expand Down
45 changes: 37 additions & 8 deletions lib/receive/bloc/state.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ mixin _$ReceiveState {
String get errGeneratingInvoice => throw _privateConstructorUsedError;
bool get generatingInvoice => throw _privateConstructorUsedError;
SwapTx? get swapTx => throw _privateConstructorUsedError;
List<Transaction>? get swapTxs => throw _privateConstructorUsedError;

@JsonKey(ignore: true)
$ReceiveStateCopyWith<ReceiveState> get copyWith =>
Expand Down Expand Up @@ -62,7 +63,8 @@ abstract class $ReceiveStateCopyWith<$Res> {
ReceiveWalletType walletType,
String errGeneratingInvoice,
bool generatingInvoice,
SwapTx? swapTx});
SwapTx? swapTx,
List<Transaction>? swapTxs});

$AddressCopyWith<$Res>? get defaultAddress;
$SwapTxCopyWith<$Res>? get swapTx;
Expand Down Expand Up @@ -98,6 +100,7 @@ class _$ReceiveStateCopyWithImpl<$Res, $Val extends ReceiveState>
Object? errGeneratingInvoice = null,
Object? generatingInvoice = null,
Object? swapTx = freezed,
Object? swapTxs = freezed,
}) {
return _then(_value.copyWith(
loadingAddress: null == loadingAddress
Expand Down Expand Up @@ -168,6 +171,10 @@ class _$ReceiveStateCopyWithImpl<$Res, $Val extends ReceiveState>
? _value.swapTx
: swapTx // ignore: cast_nullable_to_non_nullable
as SwapTx?,
swapTxs: freezed == swapTxs
? _value.swapTxs
: swapTxs // ignore: cast_nullable_to_non_nullable
as List<Transaction>?,
) as $Val);
}

Expand Down Expand Up @@ -221,7 +228,8 @@ abstract class _$$ReceiveStateImplCopyWith<$Res>
ReceiveWalletType walletType,
String errGeneratingInvoice,
bool generatingInvoice,
SwapTx? swapTx});
SwapTx? swapTx,
List<Transaction>? swapTxs});

@override
$AddressCopyWith<$Res>? get defaultAddress;
Expand Down Expand Up @@ -257,6 +265,7 @@ class __$$ReceiveStateImplCopyWithImpl<$Res>
Object? errGeneratingInvoice = null,
Object? generatingInvoice = null,
Object? swapTx = freezed,
Object? swapTxs = freezed,
}) {
return _then(_$ReceiveStateImpl(
loadingAddress: null == loadingAddress
Expand Down Expand Up @@ -327,6 +336,10 @@ class __$$ReceiveStateImplCopyWithImpl<$Res>
? _value.swapTx
: swapTx // ignore: cast_nullable_to_non_nullable
as SwapTx?,
swapTxs: freezed == swapTxs
? _value._swapTxs
: swapTxs // ignore: cast_nullable_to_non_nullable
as List<Transaction>?,
));
}
}
Expand All @@ -351,8 +364,10 @@ class _$ReceiveStateImpl extends _ReceiveState {
this.walletType = ReceiveWalletType.secure,
this.errGeneratingInvoice = '',
this.generatingInvoice = false,
this.swapTx})
: super._();
this.swapTx,
final List<Transaction>? swapTxs})
: _swapTxs = swapTxs,
super._();

@override
@JsonKey()
Expand Down Expand Up @@ -402,10 +417,19 @@ class _$ReceiveStateImpl extends _ReceiveState {
final bool generatingInvoice;
@override
final SwapTx? swapTx;
final List<Transaction>? _swapTxs;
@override
List<Transaction>? get swapTxs {
final value = _swapTxs;
if (value == null) return null;
if (_swapTxs is EqualUnmodifiableListView) return _swapTxs;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(value);
}

@override
String toString() {
return 'ReceiveState(loadingAddress: $loadingAddress, errLoadingAddress: $errLoadingAddress, defaultAddress: $defaultAddress, privateLabel: $privateLabel, savingLabel: $savingLabel, errSavingLabel: $errSavingLabel, labelSaved: $labelSaved, savedInvoiceAmount: $savedInvoiceAmount, description: $description, savedDescription: $savedDescription, creatingInvoice: $creatingInvoice, errCreatingInvoice: $errCreatingInvoice, walletBloc: $walletBloc, walletType: $walletType, errGeneratingInvoice: $errGeneratingInvoice, generatingInvoice: $generatingInvoice, swapTx: $swapTx)';
return 'ReceiveState(loadingAddress: $loadingAddress, errLoadingAddress: $errLoadingAddress, defaultAddress: $defaultAddress, privateLabel: $privateLabel, savingLabel: $savingLabel, errSavingLabel: $errSavingLabel, labelSaved: $labelSaved, savedInvoiceAmount: $savedInvoiceAmount, description: $description, savedDescription: $savedDescription, creatingInvoice: $creatingInvoice, errCreatingInvoice: $errCreatingInvoice, walletBloc: $walletBloc, walletType: $walletType, errGeneratingInvoice: $errGeneratingInvoice, generatingInvoice: $generatingInvoice, swapTx: $swapTx, swapTxs: $swapTxs)';
}

@override
Expand Down Expand Up @@ -445,7 +469,8 @@ class _$ReceiveStateImpl extends _ReceiveState {
other.errGeneratingInvoice == errGeneratingInvoice) &&
(identical(other.generatingInvoice, generatingInvoice) ||
other.generatingInvoice == generatingInvoice) &&
(identical(other.swapTx, swapTx) || other.swapTx == swapTx));
(identical(other.swapTx, swapTx) || other.swapTx == swapTx) &&
const DeepCollectionEquality().equals(other._swapTxs, _swapTxs));
}

@override
Expand All @@ -467,7 +492,8 @@ class _$ReceiveStateImpl extends _ReceiveState {
walletType,
errGeneratingInvoice,
generatingInvoice,
swapTx);
swapTx,
const DeepCollectionEquality().hash(_swapTxs));

@JsonKey(ignore: true)
@override
Expand All @@ -494,7 +520,8 @@ abstract class _ReceiveState extends ReceiveState {
final ReceiveWalletType walletType,
final String errGeneratingInvoice,
final bool generatingInvoice,
final SwapTx? swapTx}) = _$ReceiveStateImpl;
final SwapTx? swapTx,
final List<Transaction>? swapTxs}) = _$ReceiveStateImpl;
const _ReceiveState._() : super._();

@override
Expand Down Expand Up @@ -532,6 +559,8 @@ abstract class _ReceiveState extends ReceiveState {
@override
SwapTx? get swapTx;
@override
List<Transaction>? get swapTxs;
@override
@JsonKey(ignore: true)
_$$ReceiveStateImplCopyWith<_$ReceiveStateImpl> get copyWith =>
throw _privateConstructorUsedError;
Expand Down

0 comments on commit 929df9a

Please sign in to comment.