Skip to content

Commit

Permalink
Added AddressPage
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanCheatham committed Sep 11, 2024
1 parent 5976a82 commit a8f9b89
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 19 deletions.
5 changes: 5 additions & 0 deletions dart/wallet/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:io';

import 'package:giraffe_wallet/widgets/pages/address_page.dart';
import 'package:giraffe_wallet/widgets/pages/social_page.dart';
import 'package:giraffe_wallet/widgets/pages/stake_page.dart';
import 'package:giraffe_wallet/widgets/pages/wallet_page.dart';
Expand Down Expand Up @@ -69,6 +70,10 @@ initRouter() {
handler: Handler(
handlerFunc: (context, params) => UnloadedTransactionPage(
id: decodeTransactionId(params["id"]![0]))));
FluroRouter.appRouter.define("/addresses/:address",
handler: Handler(
handlerFunc: (context, params) => UnloadedAddressPage(
address: decodeLockAddress(params["address"]![0]))));
FluroRouter.appRouter.define("/wallet",
handler: Handler(
handlerFunc: (context, params) => const StreamedTransactView()));
Expand Down
1 change: 1 addition & 0 deletions dart/wallet/lib/widgets/bitmap_render.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:math';
import 'dart:typed_data';

import 'package:bit_array/bit_array.dart';
import 'package:fluro/fluro.dart';
import 'package:giraffe_sdk/sdk.dart';
import 'package:flutter/material.dart';

Expand Down
143 changes: 143 additions & 0 deletions dart/wallet/lib/widgets/pages/address_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import 'package:giraffe_wallet/providers/canonical_head.dart';
import 'package:giraffe_wallet/utils.dart';
import 'package:giraffe_wallet/widgets/giraffe_card.dart';
import 'package:giraffe_wallet/widgets/giraffe_scaffold.dart';
import 'package:giraffe_wallet/widgets/over_under.dart';

import '../../providers/blockchain_client.dart';
import '../../widgets/bitmap_render.dart';
import 'package:giraffe_sdk/sdk.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class UnloadedAddressPage extends ConsumerWidget {
final LockAddress address;

const UnloadedAddressPage({super.key, required this.address});

@override
Widget build(BuildContext context, WidgetRef ref) {
ref.watch(podCanonicalHeadProvider);
return FutureBuilder(
future: fetch(ref),
builder: (context, snapshot) {
if (snapshot.hasData) {
if (snapshot.data != null) {
return AddressPage(
address: address, outputs: snapshot.requireData);
} else {
return GiraffeScaffold(title: "Address View", body: notFound);
}
} else {
return GiraffeScaffold(title: "Address View", body: loading);
}
});
}

Future<List<(TransactionOutputReference, TransactionOutput)>> fetch(
WidgetRef ref) async {
final client = ref.watch(podBlockchainClientProvider)!;
final refs = await client.getLockAddressState(address);
return Future.wait(refs.map(
((r) => client.getTransactionOutputOrRaise(r).then((o) => (r, o)))));
}

static final notFound = Container(
alignment: Alignment.center,
child: const Text("Address not found."),
);

static final loading = Container(
alignment: Alignment.center,
child: const CircularProgressIndicator(),
);
}

class AddressPage extends StatelessWidget {
final LockAddress address;
final List<(TransactionOutputReference reference, TransactionOutput output)>
outputs;

const AddressPage({super.key, required this.address, required this.outputs});

@override
Widget build(BuildContext context) => GiraffeScaffold(
title: "Address View",
body: _body(context),
);

_body(BuildContext context) => GiraffeCard(
child: ListView(
children: [
_addressCard().pad16,
_outputsCard().pad16,
],
),
);

Widget _addressCard() {
return Wrap(
children: [
SizedBox.square(
dimension: 64, child: BitMapViewer.forLockAddress(address)),
OverUnder(
over: const Text("Address",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
)),
under: Text(
address.show,
style: const TextStyle(
fontSize: 16,
color: Colors.blueGrey,
),
),
),
],
);
}

Widget _outputsCard() {
return _overUnderWidgets(
const Text(
"Outputs",
style: TextStyle(fontWeight: FontWeight.bold),
),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: DataTable(
columns: const [
DataColumn(label: Text("Quantity")),
DataColumn(label: Text("Graph Entry")),
DataColumn(label: Text("Registration")),
],
rows: outputs.map((rec) {
final t = rec.$2;
return DataRow(cells: [
DataCell(Text(t.value.quantity.toString())),
DataCell(t.value.hasGraphEntry()
? (t.value.graphEntry.hasVertex()
? const Icon(Icons.circle)
: const Icon(Icons.compare_arrows_outlined))
: Container()),
DataCell(t.value.hasAccountRegistration()
? const Icon(Icons.account_box)
: Container()),
]);
}).toList(),
),
));
}

Widget _overUnder(String overText, String underText) => _overUnderWidgets(
Text(
overText,
style: const TextStyle(fontWeight: FontWeight.bold),
),
Text(underText, style: const TextStyle(color: Colors.blueGrey)),
);

Widget _overUnderWidgets(Widget over, Widget under) =>
OverUnder(over: over, under: under);
}
15 changes: 6 additions & 9 deletions dart/wallet/lib/widgets/pages/block_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:giraffe_wallet/utils.dart';
import 'package:giraffe_wallet/widgets/giraffe_card.dart';
import 'package:giraffe_wallet/widgets/giraffe_scaffold.dart';
import 'package:giraffe_wallet/widgets/over_under.dart';
import 'package:giraffe_wallet/widgets/tappable_link.dart';

import '../../providers/blockchain_client.dart';
import '../bitmap_render.dart';
Expand Down Expand Up @@ -118,15 +119,11 @@ class BlockPage extends StatelessWidget {
}

_parentLink(BuildContext context) {
return MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: () => FluroRouter.appRouter
.navigateTo(context, "/blocks/${block.header.parentHeaderId.show}"),
child: SizedBox.square(
dimension: 32,
child: BitMapViewer.forBlock(block.header.parentHeaderId),
),
return TappableLink(
route: "/blocks/${block.header.parentHeaderId.show}",
child: SizedBox.square(
dimension: 32,
child: BitMapViewer.forBlock(block.header.parentHeaderId),
),
);
}
Expand Down
22 changes: 15 additions & 7 deletions dart/wallet/lib/widgets/pages/transaction_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:giraffe_wallet/utils.dart';
import 'package:giraffe_wallet/widgets/giraffe_card.dart';
import 'package:giraffe_wallet/widgets/giraffe_scaffold.dart';
import 'package:giraffe_wallet/widgets/over_under.dart';
import 'package:giraffe_wallet/widgets/tappable_link.dart';

import '../../providers/blockchain_client.dart';
import '../../widgets/bitmap_render.dart';
Expand Down Expand Up @@ -111,10 +112,14 @@ class TransactionPage extends StatelessWidget {
rows: transaction.inputs
.map((t) => DataRow(cells: [
DataCell(Row(children: [
SizedBox.square(
dimension: 32,
child: BitMapViewer.forTransaction(
t.reference.transactionId)),
TappableLink(
route:
"/transactions/${t.reference.transactionId.show}",
child: SizedBox.square(
dimension: 32,
child: BitMapViewer.forTransaction(
t.reference.transactionId)),
),
Text("#${t.reference.index}"),
])),
DataCell(Text(t.value.quantity.toString())),
Expand Down Expand Up @@ -145,9 +150,12 @@ class TransactionPage extends StatelessWidget {
rows: transaction.outputs
.map((t) => DataRow(cells: [
DataCell(Text(t.value.quantity.toString())),
DataCell(SizedBox.square(
dimension: 32,
child: BitMapViewer.forLockAddress(t.lockAddress))),
DataCell(TappableLink(
route: "/addresses/${t.lockAddress.show}",
child: SizedBox.square(
dimension: 32,
child: BitMapViewer.forLockAddress(t.lockAddress)),
)),
DataCell(t.value.hasGraphEntry()
? (t.value.graphEntry.hasVertex()
? const Icon(Icons.circle)
Expand Down
21 changes: 18 additions & 3 deletions dart/wallet/lib/widgets/pages/wallet_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import 'package:giraffe_sdk/sdk.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../bitmap_render.dart';
import '../tappable_link.dart';

class StreamedTransactView extends ConsumerWidget {
const StreamedTransactView({super.key});

Expand Down Expand Up @@ -61,9 +64,21 @@ class TransactView extends ConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
return ListView(
children: [
const Text("Address",
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold))
.pad8,
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
TappableLink(
route: "/addresses/${wallet.defaultLockAddress.show}",
child: SizedBox.square(
dimension: 32,
child:
BitMapViewer.forLockAddress(wallet.defaultLockAddress)),
).pad8,
const Text("Address",
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold))
.pad8,
],
),
const ClipboardAddressButton().pad8,
const WalletBalances().pad8,
const Divider(),
Expand Down
20 changes: 20 additions & 0 deletions dart/wallet/lib/widgets/tappable_link.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';

class TappableLink extends StatelessWidget {
final Widget child;
final String route;

const TappableLink({super.key, required this.child, required this.route});

@override
Widget build(BuildContext context) {
return MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: () => FluroRouter.appRouter.navigateTo(context, route),
child: child,
),
);
}
}

0 comments on commit a8f9b89

Please sign in to comment.