Merge pull request #333 from cypherstack/paynyms

Paynyms
This commit is contained in:
Diego Salazar 2023-02-01 11:42:56 -07:00 committed by GitHub
commit f966656ac4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 285 additions and 41 deletions

View file

@ -69,6 +69,7 @@ class Address extends CryptoCurrencyAddress {
"}";
}
// do not modify
enum AddressType {
p2pkh,
p2sh,
@ -79,6 +80,7 @@ enum AddressType {
nonWallet,
}
// do not modify
enum AddressSubType {
receiving,
change,

View file

@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart';
import 'package:share_plus/share_plus.dart';
import 'package:stackwallet/notifications/show_flush_bar.dart';
import 'package:stackwallet/pages/paynym/add_new_paynym_follow_view.dart';
import 'package:stackwallet/pages/paynym/dialogs/paynym_qr_popup.dart';
@ -358,8 +359,25 @@ class _PaynymHomeViewState extends ConsumerState<PaynymHomeView> {
.extension<StackColors>()!
.textDark,
),
onPressed: () {
// copy to clipboard
onPressed: () async {
Rect? sharePositionOrigin;
if (await Util.isIPad) {
final box =
context.findRenderObject() as RenderBox?;
if (box != null) {
sharePositionOrigin =
box.localToGlobal(Offset.zero) & box.size;
}
}
await Share.share(
ref
.read(myPaynymAccountStateProvider.state)
.state!
.codes
.first
.code,
sharePositionOrigin: sharePositionOrigin);
},
),
),

View file

@ -7,10 +7,12 @@ import 'package:flutter_svg/flutter_svg.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:stackwallet/notifications/show_flush_bar.dart';
import 'package:stackwallet/pages/receive_view/generate_receiving_uri_qr_code_view.dart';
import 'package:stackwallet/pages/receive_view/receiving_addresses_view.dart';
import 'package:stackwallet/providers/providers.dart';
import 'package:stackwallet/route_generator.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/clipboard_interface.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
@ -19,6 +21,7 @@ import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart';
import 'package:stackwallet/widgets/custom_loading_overlay.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart';
import 'package:tuple/tuple.dart';
class ReceiveView extends ConsumerStatefulWidget {
const ReceiveView({
@ -128,6 +131,84 @@ class _ReceiveViewState extends ConsumerState<ReceiveView> {
"Receive ${coin.ticker}",
style: STextStyles.navBarTitle(context),
),
actions: [
Padding(
padding: const EdgeInsets.only(
top: 10,
bottom: 10,
right: 10,
),
child: AspectRatio(
aspectRatio: 1,
child: AppBarIconButton(
key: const Key("walletNetworkSettingsAddNewNodeViewButton"),
size: 36,
shadows: const [],
color: Theme.of(context).extension<StackColors>()!.background,
icon: SvgPicture.asset(
Assets.svg.verticalEllipsis,
color: Theme.of(context)
.extension<StackColors>()!
.accentColorDark,
width: 20,
height: 20,
),
onPressed: () {
showDialog<dynamic>(
barrierColor: Colors.transparent,
barrierDismissible: true,
context: context,
builder: (_) {
return Stack(
children: [
Positioned(
top: 9,
right: 10,
child: Container(
decoration: BoxDecoration(
color: Theme.of(context)
.extension<StackColors>()!
.popupBG,
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
),
// boxShadow: [CFColors.standardBoxShadow],
boxShadow: const [],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
GestureDetector(
onTap: () {
Navigator.of(context).pop();
Navigator.of(context).pushNamed(
ReceivingAddressesView.routeName,
arguments: Tuple2(walletId, false),
);
},
child: RoundedWhiteContainer(
child: Material(
color: Colors.transparent,
child: Text(
"Address list",
style: STextStyles.baseXS(context),
),
),
),
),
],
),
),
),
],
);
},
);
},
),
),
),
],
),
body: Padding(
padding: const EdgeInsets.all(12),

View file

@ -0,0 +1,114 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:isar/isar.dart';
import 'package:stackwallet/db/main_db.dart';
import 'package:stackwallet/models/isar/models/isar_models.dart';
import 'package:stackwallet/utilities/clipboard_interface.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/background.dart';
import 'package:stackwallet/widgets/conditional_parent.dart';
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackwallet/widgets/loading_indicator.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart';
class ReceivingAddressesView extends ConsumerWidget {
const ReceivingAddressesView({
Key? key,
required this.walletId,
required this.isDesktop,
this.clipboard = const ClipboardWrapper(),
}) : super(key: key);
static const String routeName = "/receivingAddressesView";
final String walletId;
final bool isDesktop;
final ClipboardInterface clipboard;
@override
Widget build(BuildContext context, WidgetRef ref) {
return ConditionalParent(
condition: !isDesktop,
builder: (child) => Background(
child: Scaffold(
backgroundColor:
Theme.of(context).extension<StackColors>()!.background,
appBar: AppBar(
backgroundColor:
Theme.of(context).extension<StackColors>()!.backgroundAppBar,
leading: AppBarBackButton(
onPressed: () {
Navigator.of(context).pop();
},
),
title: Text(
"Receiving addresses",
style: STextStyles.navBarTitle(context),
),
),
body: Padding(
padding: const EdgeInsets.all(16),
child: child,
),
),
),
child: FutureBuilder(
future: MainDB.instance
.getAddresses(walletId)
.filter()
.subTypeEqualTo(AddressSubType.receiving)
.and()
.not()
.typeEqualTo(AddressType.nonWallet)
.sortByDerivationIndexDesc()
.findAll(),
builder: (context, AsyncSnapshot<List<Address>> snapshot) {
if (snapshot.connectionState == ConnectionState.done &&
snapshot.data != null) {
// listview
return ListView.separated(
itemCount: snapshot.data!.length,
separatorBuilder: (_, __) => Container(
height: 10,
),
itemBuilder: (_, index) => AddressCard(
address: snapshot.data![index],
),
);
} else {
return const Center(
child: LoadingIndicator(
height: 200,
width: 200,
),
);
}
},
),
);
}
}
class AddressCard extends StatelessWidget {
const AddressCard({
Key? key,
required this.address,
}) : super(key: key);
final Address address;
@override
Widget build(BuildContext context) {
return RoundedWhiteContainer(
child: Row(
children: [
Text(
address.value,
style: STextStyles.itemSubtitle12(context),
)
],
),
);
}
}

View file

@ -46,6 +46,7 @@ import 'package:stackwallet/pages/paynym/paynym_home_view.dart';
import 'package:stackwallet/pages/pinpad_views/create_pin_view.dart';
import 'package:stackwallet/pages/receive_view/generate_receiving_uri_qr_code_view.dart';
import 'package:stackwallet/pages/receive_view/receive_view.dart';
import 'package:stackwallet/pages/receive_view/receiving_addresses_view.dart';
import 'package:stackwallet/pages/send_view/confirm_transaction_view.dart';
import 'package:stackwallet/pages/send_view/send_view.dart';
import 'package:stackwallet/pages/settings_views/global_settings_view/about_view.dart';
@ -820,6 +821,21 @@ class RouteGenerator {
}
return _routeError("${settings.name} invalid args: ${args.toString()}");
case ReceivingAddressesView.routeName:
if (args is Tuple2<String, bool>) {
return getRoute(
shouldUseMaterialRoute: useMaterialPageRoute,
builder: (_) => ReceivingAddressesView(
walletId: args.item1,
isDesktop: args.item2,
),
settings: RouteSettings(
name: settings.name,
),
);
}
return _routeError("${settings.name} invalid args: ${args.toString()}");
case SendView.routeName:
if (args is Tuple2<String, Coin>) {
return getRoute(

View file

@ -2601,13 +2601,12 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
final n = output["n"];
if (n != null && n == utxosToUse[i].vout) {
String address = output["scriptPubKey"]["addresses"][0] as String;
if (bitbox.Address.detectFormat(address) ==
if (bitbox.Address.detectFormat(address) !=
bitbox.Address.formatCashAddr) {
if (validateCashAddr(address)) {
address = bitbox.Address.toLegacyAddress(address);
} else {
throw Exception(
"Unsupported address found during fetchBuildTxData(): $address");
try {
address = bitbox.Address.toCashAddress(address);
} catch (_) {
rethrow;
}
}
if (!addressTxid.containsKey(address)) {

View file

@ -162,7 +162,21 @@ mixin PaynymWalletInterface {
if (address == null) {
final generatedAddress = await _generatePaynymReceivingAddress(sender, 0);
final existing = await _db
.getAddresses(_walletId)
.filter()
.valueEqualTo(generatedAddress.value)
.findFirst();
if (existing == null) {
// Add that new address
await _db.putAddress(generatedAddress);
} else {
// we need to update the address
await _db.updateAddress(existing, generatedAddress);
}
return currentReceivingPaynymAddress(sender);
} else {
return address;
@ -203,7 +217,22 @@ mixin PaynymWalletInterface {
sender,
address.derivationIndex + 1,
);
final existing = await _db
.getAddresses(_walletId)
.filter()
.valueEqualTo(nextAddress.value)
.findFirst();
if (existing == null) {
// Add that new address
await _db.putAddress(nextAddress);
} else {
// we need to update the address
await _db.updateAddress(existing, nextAddress);
}
// keep checking until address with no tx history is set as current
await checkCurrentPaynymReceivingAddressForTransactions(sender);
}
}

View file

@ -1,5 +1,6 @@
import 'dart:io';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/material.dart';
abstract class Util {
@ -22,6 +23,14 @@ abstract class Util {
return Platform.isLinux || Platform.isMacOS || Platform.isWindows;
}
static Future<bool> get isIPad async {
final deviceInfo = (await DeviceInfoPlugin().deviceInfo);
if (deviceInfo is IosDeviceInfo) {
return (deviceInfo).name?.toLowerCase().contains("ipad") == true;
}
return false;
}
static MaterialColor createMaterialColor(Color color) {
List<double> strengths = <double>[.05];
final swatch = <int, Color>{};

View file

@ -14,7 +14,7 @@ import flutter_secure_storage_macos
import isar_flutter_libs
import package_info_plus_macos
import path_provider_macos
import share_plus_macos
import share_plus
import shared_preferences_macos
import stack_wallet_backup
import url_launcher_macos

View file

@ -1237,21 +1237,7 @@ packages:
name: share_plus
url: "https://pub.dartlang.org"
source: hosted
version: "4.5.3"
share_plus_linux:
dependency: transitive
description:
name: share_plus_linux
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
share_plus_macos:
dependency: transitive
description:
name: share_plus_macos
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
version: "6.3.0"
share_plus_platform_interface:
dependency: transitive
description:
@ -1259,20 +1245,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.0"
share_plus_web:
dependency: transitive
description:
name: share_plus_web
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.0"
share_plus_windows:
dependency: transitive
description:
name: share_plus_windows
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
shared_preferences:
dependency: transitive
description:

View file

@ -126,7 +126,7 @@ dependencies:
tuple: ^2.0.0
flutter_riverpod: ^1.0.3
qr_flutter: ^4.0.0
share_plus: ^4.0.10
share_plus: ^6.3.0
emojis: ^0.9.9
pointycastle: ^3.6.0
package_info_plus: ^1.4.2

View file

@ -11,6 +11,7 @@
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
#include <isar_flutter_libs/isar_flutter_libs_plugin.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <share_plus/share_plus_windows_plugin_c_api.h>
#include <stack_wallet_backup/stack_wallet_backup_plugin_c_api.h>
#include <url_launcher_windows/url_launcher_windows.h>
#include <window_size/window_size_plugin.h>
@ -26,6 +27,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("IsarFlutterLibsPlugin"));
PermissionHandlerWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
SharePlusWindowsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("SharePlusWindowsPluginCApi"));
StackWalletBackupPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("StackWalletBackupPluginCApi"));
UrlLauncherWindowsRegisterWithRegistrar(

View file

@ -8,6 +8,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
flutter_secure_storage_windows
isar_flutter_libs
permission_handler_windows
share_plus
stack_wallet_backup
url_launcher_windows
window_size