Skip to content

Commit

Permalink
fix: reintroduce the tot amount of off chain sats
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
  • Loading branch information
vincenzopalazzo committed Aug 13, 2022
1 parent e4a0e81 commit caa6fc5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
15 changes: 9 additions & 6 deletions lib/api/cln/cln_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,27 @@ class CLNApi extends AppApi {

@override
Future<AppGetInfo> getInfo() async {
dynamic params;
dynamic getInfoParams;
switch (mode) {
case ClientMode.grpc:
params = CLNGetInfoRequest(grpcRequest: GetinfoRequest());
getInfoParams = CLNGetInfoRequest(grpcRequest: GetinfoRequest());
break;
case ClientMode.unixSocket:
params = CLNGetInfoRequest(unixRequest: <String, dynamic>{});
getInfoParams = CLNGetInfoRequest(unixRequest: <String, dynamic>{});
break;
case ClientMode.lnlambda:
params = CLNGetInfoRequest(unixRequest: <String, dynamic>{});
getInfoParams = CLNGetInfoRequest(unixRequest: <String, dynamic>{});
break;
}
return await client.call<CLNGetInfoRequest, AppGetInfo>(
var appInfo = await client.call<CLNGetInfoRequest, AppGetInfo>(
method: "getinfo",
params: params,
params: getInfoParams,
onDecode: (jsonResponse) => AppGetInfo.fromJSON(
jsonResponse as Map<String, dynamic>,
snackCase: !mode.withCamelCase()));
var listFunds = await this.listFunds();
appInfo.totOffChainMsat = listFunds?.totOffChainMsat ?? 0;
return appInfo;
}

@override
Expand Down
2 changes: 2 additions & 0 deletions lib/model/app_model/get_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class AppGetInfo {
/// Alias of the node
final String alias;

int totOffChainMsat = 0;

AppGetInfo({required this.nodeId, required this.alias});

factory AppGetInfo.fromJSON(Map<String, dynamic> json,
Expand Down
11 changes: 6 additions & 5 deletions lib/model/app_model/list_funds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ class AppListFunds {

List<AppFundChannel> fundChannels;

int channelSats;
int totOffChainMsat;

AppListFunds(
{this.fund = const [],
this.fundChannels = const [],
this.channelSats = 0});
this.totOffChainMsat = 0});

factory AppListFunds.fromJSON(Map<String, dynamic> json,
{bool snackCase = false, bool isObject = false}) {
LogManager.getInstance.debug("Full listfunds json received: $json");
var funds = json.withKey("outputs", snackCase: snackCase) as List;
LogManager.getInstance.debug("$funds");
LogManager.getInstance.debug("Funds: $funds");
var fundChannels = json.withKey("channels", snackCase: snackCase) as List;
LogManager.getInstance.debug("Channels: $fundChannels");
double totalChannelsAmount = 0;
for (var rawChannel in fundChannels) {
var channel = Map<String, dynamic>.from(rawChannel);
Expand All @@ -32,7 +33,7 @@ class AppListFunds {
/// converting Msat to sat
totalChannelsAmount /= 1000;

if (funds.isNotEmpty) {
if (funds.isNotEmpty || fundChannels.isNotEmpty) {
var appFunds = funds
.map((fund) =>
AppFund.fromJSON(fund, snackCase: snackCase, isObject: isObject))
Expand All @@ -44,7 +45,7 @@ class AppListFunds {
return AppListFunds(
fund: appFunds,
fundChannels: appFundChannels,
channelSats: totalChannelsAmount.toInt());
totOffChainMsat: totalChannelsAmount.toInt());
} else {
return AppListFunds();
}
Expand Down
7 changes: 2 additions & 5 deletions lib/views/home/home_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ class HomeView extends StatefulAppView {
class _HomeViewState extends State<HomeView> {
int _currentIndex = 0;

// FIXME: add an amount calculation for the channels!
int amountSat = 0;

late final pages = [
_buildMainView(context: context),
SettingView(provider: widget.provider),
Expand Down Expand Up @@ -57,7 +54,7 @@ class _HomeViewState extends State<HomeView> {
height: 18,
),
Text(
"${amountSat.toString()} sats",
"${getInfo.totOffChainMsat} sats",
style: const TextStyle(fontSize: 45, fontWeight: FontWeight.bold),
),
Row(
Expand Down Expand Up @@ -193,7 +190,7 @@ class _HomeViewState extends State<HomeView> {
fontSize: 15,
fontWeight: FontWeight.w500,
),
),
),
),
),
],
Expand Down
2 changes: 1 addition & 1 deletion test/unix_client_appapi_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void main() async {
final fundsList = await provider.get<AppApi>().listFunds();
expect(fundsList, isNotNull);
expect(fundsList!.fund, isNotNull);
expect(fundsList.channelSats, isNotNull);
expect(fundsList.totOffChainMsat, isNotNull);
expect(fundsList.fundChannels, isNotNull);
});

Expand Down

0 comments on commit caa6fc5

Please sign in to comment.