Skip to content

Commit

Permalink
Merge pull request #4 from peercoin/v.0.1-1
Browse files Browse the repository at this point in the history
V.0.1.1
  • Loading branch information
Willy authored Mar 20, 2021
2 parents 6a4452e + 628671a commit ad513e4
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 15 deletions.
6 changes: 4 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:peercoin/providers/activewallets.dart';
import 'package:peercoin/providers/electrumconnection.dart';
import 'package:peercoin/screens/new_wallet.dart';
import 'package:peercoin/screens/qrcodescanner.dart';
import 'package:peercoin/screens/transaction_details.dart';
import 'package:peercoin/screens/wallet_home.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
Expand Down Expand Up @@ -61,7 +62,7 @@ class MyApp extends StatelessWidget {
)
],
child: MaterialApp(
title: 'Peercoin Testnet Wallet',
title: 'Peercoin',
theme: ThemeData(
primaryColor: Color.fromRGBO(60, 176, 84, 1),
accentColor: Colors.grey,
Expand All @@ -76,7 +77,8 @@ class MyApp extends StatelessWidget {
WalletListScreen.routeName: (ctx) => WalletListScreen(),
WalletHomeScreen.routeName: (ctx) => WalletHomeScreen(),
NewWalletScreen.routeName: (ctx) => NewWalletScreen(),
QRScanner.routeName: (ctx) => QRScanner()
QRScanner.routeName: (ctx) => QRScanner(),
TransactionDetails.routeName: (ctx) => TransactionDetails()
},
),
);
Expand Down
6 changes: 4 additions & 2 deletions lib/models/availablecoins.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class AvailableCoins {
wif: 0xb7),
fractions: 6,
minimumTxValue: 10000,
feePerKb: 0.01),
feePerKb: 0.01,
explorerTxDetailUrl: "https://blockbook.peercoin.net/tx/"),
"peercoinTestnet": Coin(
name: "peercoinTestnet",
displayName: "Peercoin Testnet",
Expand All @@ -36,7 +37,8 @@ class AvailableCoins {
wif: 0xef),
fractions: 6,
minimumTxValue: 10000,
feePerKb: 0.01)
feePerKb: 0.01,
explorerTxDetailUrl: "https://tblockbook.peercoin.net/tx/"),
};

Map<String, Coin> get availableCoins {
Expand Down
2 changes: 2 additions & 0 deletions lib/models/coin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Coin {
final int fractions;
final int minimumTxValue;
final double feePerKb;
final String explorerTxDetailUrl;

Coin({
@required this.name,
Expand All @@ -24,5 +25,6 @@ class Coin {
@required this.fractions,
@required this.minimumTxValue,
@required this.feePerKb,
@required this.explorerTxDetailUrl,
});
}
8 changes: 5 additions & 3 deletions lib/providers/activewallets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,7 @@ class ActiveWallets with ChangeNotifier {

final intermediate = tx.build();
var number = ((intermediate.txSize) / 1000 * coin.feePerKb)
.toStringAsFixed(
coin.fractions - 1); //yep -1 is a bit of a magic number here...
.toStringAsFixed(coin.fractions);
var asDouble = double.parse(number) * 1000000;
int requiredFeeInSatoshis = asDouble.toInt();
print("fee $requiredFeeInSatoshis, size: ${intermediate.txSize}");
Expand All @@ -376,7 +375,10 @@ class ActiveWallets with ChangeNotifier {
//generate new wallet addr
await generateUnusedAddress(identifier);
return {
"fee": requiredFeeInSatoshis,
"fee": dryRun == false
? requiredFeeInSatoshis
: requiredFeeInSatoshis +
10, //TODO 10 satoshis added here because tx virtualsize out of bitcoin_flutter varies by 1 byte
"hex": _hex,
"id": intermediate.getId(),
"destroyedChange": _destroyedChange
Expand Down
115 changes: 115 additions & 0 deletions lib/screens/transaction_details.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:peercoin/models/availablecoins.dart';
import 'package:peercoin/models/coinwallet.dart';
import 'package:peercoin/models/wallettransaction.dart';
import 'package:url_launcher/url_launcher.dart';

class TransactionDetails extends StatelessWidget {
static const routeName = "/tx-detail";

void _launchURL(_url) async {
print(_url);
await canLaunch(_url) ? await launch(_url) : throw 'Could not launch $_url';
}

@override
Widget build(BuildContext context) {
final args = ModalRoute.of(context).settings.arguments as List;
final WalletTransaction _tx = args[0];
final CoinWallet _coinWallet = args[1];
final String baseUrl =
AvailableCoins().getSpecificCoin(_coinWallet.name).explorerTxDetailUrl;

return Scaffold(
appBar: AppBar(
title: const Text(
"Transaction details",
)),
body: ListView(
padding: EdgeInsets.all(20),
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text("Id", style: TextStyle(fontWeight: FontWeight.bold)),
SelectableText(_tx.txid)
],
),
Divider(),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text("Time", style: TextStyle(fontWeight: FontWeight.bold)),
SelectableText(_tx.timestamp != null
? DateFormat().format(
DateTime.fromMillisecondsSinceEpoch(_tx.timestamp * 1000))
: "unconfirmed")
],
),
Divider(),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
"Value",
style: TextStyle(fontWeight: FontWeight.bold),
),
SelectableText((_tx.value / 1000000).toString() +
" " +
_coinWallet.letterCode)
],
),
Divider(),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text("Fee", style: TextStyle(fontWeight: FontWeight.bold)),
SelectableText(
(_tx.fee / 1000000).toString() + " " + _coinWallet.letterCode)
],
),
Divider(),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text("Address",
style: TextStyle(fontWeight: FontWeight.bold)),
SelectableText(_tx.address)
],
),
Divider(),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text("Direction",
style: TextStyle(fontWeight: FontWeight.bold)),
SelectableText(_tx.direction)
],
),
Divider(),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text("Confirmations",
style: TextStyle(fontWeight: FontWeight.bold)),
SelectableText(_tx.confirmations.toString())
],
),
Center(
child: TextButton.icon(
onPressed: () => _launchURL(baseUrl + "${_tx.txid}"),
icon: Icon(
Icons.search,
color: Theme.of(context).primaryColor,
),
label: Text(
"View in explorer",
style: TextStyle(color: Theme.of(context).primaryColor),
)),
)
],
),
);
}
}
2 changes: 1 addition & 1 deletion lib/widgets/receive_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class _ReceiveTabState extends State<ReceiveTab> {
color: Theme.of(context).accentColor,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
child: SelectableText(
widget._unusedAddress,
style: TextStyle(color: Colors.white),
),
Expand Down
8 changes: 4 additions & 4 deletions lib/widgets/send_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,17 +256,17 @@ class _SendTabState extends State<SendTab> {
"outFees":
_txFee + _destroyedChange
});
//pop message
Navigator.of(context).pop();
//navigate back to tx list
widget.changeIndex(1);
//broadcast
Provider.of<ElectrumConnection>(
context,
listen: false)
.broadcastTransaction(
_buildResult["hex"],
_buildResult["id"]);
//pop message
Navigator.of(context).pop();
//navigate back to tx list
widget.changeIndex(1);
} catch (e) {
print("error $e");
ScaffoldMessenger.of(context)
Expand Down
6 changes: 6 additions & 0 deletions lib/widgets/transactions_list.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "package:flutter/material.dart";
import 'package:peercoin/models/wallettransaction.dart';
import 'package:intl/intl.dart';
import 'package:peercoin/screens/transaction_details.dart';
import 'package:step_progress_indicator/step_progress_indicator.dart';

class TransactionList extends StatelessWidget {
Expand All @@ -23,6 +24,11 @@ class TransactionList extends StatelessWidget {

return Card(
child: ListTile(
onTap: () => Navigator.of(context)
.pushNamed(TransactionDetails.routeName, arguments: [
_flippedTx[i],
ModalRoute.of(context).settings.arguments
]),
leading: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expand Down
48 changes: 45 additions & 3 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ packages:
name: bip32
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.7"
version: "1.0.5"
bip39:
dependency: "direct main"
description:
Expand Down Expand Up @@ -721,6 +721,48 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
url_launcher:
dependency: "direct main"
description:
name: url_launcher
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.2"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
url_launcher_platform_interface:
dependency: transitive
description:
name: url_launcher_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
vector_math:
dependency: transitive
description:
Expand Down Expand Up @@ -771,5 +813,5 @@ packages:
source: hosted
version: "2.2.1"
sdks:
dart: ">=2.12.0-0.0 <3.0.0"
flutter: ">=1.20.0"
dart: ">=2.12.0-259.9.beta <3.0.0"
flutter: ">=1.22.0"
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies:
intl: ^0.17.0
step_progress_indicator: ^0.2.5+8
qr_code_scanner: ^0.3.5
url_launcher: ^6.0.2
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.0
Expand Down

0 comments on commit ad513e4

Please sign in to comment.