diff --git a/lib/models/paynym/paynym_account.dart b/lib/models/paynym/paynym_account.dart index 4be59dc0c..12351e3a5 100644 --- a/lib/models/paynym/paynym_account.dart +++ b/lib/models/paynym/paynym_account.dart @@ -4,6 +4,7 @@ import 'package:stackwallet/models/paynym/paynym_code.dart'; class PaynymAccount { final String nymID; final String nymName; + final bool segwit; final List codes; @@ -16,6 +17,7 @@ class PaynymAccount { PaynymAccount( this.nymID, this.nymName, + this.segwit, this.codes, this.followers, this.following, @@ -24,6 +26,7 @@ class PaynymAccount { PaynymAccount.fromMap(Map map) : nymID = map["nymID"] as String, nymName = map["nymName"] as String, + segwit = map["segwit"] as bool, codes = (map["codes"] as List) .map((e) => PaynymCode.fromMap(Map.from(e as Map))) .toList(), @@ -39,6 +42,7 @@ class PaynymAccount { PaynymAccount copyWith({ String? nymID, String? nymName, + bool? segwit, List? codes, List? followers, List? following, @@ -46,6 +50,7 @@ class PaynymAccount { return PaynymAccount( nymID ?? this.nymID, nymName ?? this.nymName, + segwit ?? this.segwit, codes ?? this.codes, followers ?? this.followers, following ?? this.following, @@ -55,6 +60,7 @@ class PaynymAccount { Map toMap() => { "nymID": nymID, "nymName": nymName, + "segwit": segwit, "codes": codes.map((e) => e.toMap()), "followers": followers.map((e) => e.toMap()), "following": followers.map((e) => e.toMap()), diff --git a/lib/pages/paynym/paynym_claim_view.dart b/lib/pages/paynym/paynym_claim_view.dart index 8a66aa26d..a26d4828e 100644 --- a/lib/pages/paynym/paynym_claim_view.dart +++ b/lib/pages/paynym/paynym_claim_view.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/flutter_svg.dart'; +import 'package:stackwallet/models/paynym/paynym_account.dart'; import 'package:stackwallet/pages/paynym/dialogs/claiming_paynym_dialog.dart'; import 'package:stackwallet/pages/paynym/paynym_home_view.dart'; import 'package:stackwallet/pages/wallet_view/wallet_view.dart'; @@ -11,7 +12,6 @@ import 'package:stackwallet/providers/global/wallets_provider.dart'; import 'package:stackwallet/providers/wallet/my_paynym_account_state_provider.dart'; import 'package:stackwallet/services/mixins/paynym_wallet_interface.dart'; import 'package:stackwallet/utilities/assets.dart'; -import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/utilities/util.dart'; @@ -36,6 +36,28 @@ class PaynymClaimView extends ConsumerStatefulWidget { } class _PaynymClaimViewState extends ConsumerState { + Future _addSegwitCode(PaynymAccount myAccount) async { + final manager = + ref.read(walletsChangeNotifierProvider).getManager(widget.walletId); + + // get wallet to access paynym calls + final wallet = manager.wallet as PaynymWalletInterface; + + final token = + await ref.read(paynymAPIProvider).token(myAccount.codes.first.code); + final signature = await wallet.signStringWithNotificationKey(token.value!); + + final pCodeSegwit = await wallet.getPaymentCode(isSegwit: true); + final addResult = await ref.read(paynymAPIProvider).add( + token.value!, + signature, + myAccount.nymID, + pCodeSegwit.toString(), + ); + + return addResult.value ?? false; + } + @override Widget build(BuildContext context) { debugPrint("BUILD: $runtimeType"); @@ -169,8 +191,7 @@ class _PaynymClaimViewState extends ConsumerState { if (shouldCancel) return; // get payment code - final pCode = await wallet.getPaymentCode( - DerivePathTypeExt.primaryFor(manager.coin)); + final pCode = await wallet.getPaymentCode(isSegwit: false); if (shouldCancel) return; @@ -185,6 +206,18 @@ class _PaynymClaimViewState extends ConsumerState { if (created.value!.claimed) { // payment code already claimed debugPrint("pcode already claimed!!"); + + final account = + await ref.read(paynymAPIProvider).nym(pCode.toString()); + if (!account.value!.segwit) { + for (int i = 0; i < 100; i++) { + final result = await _addSegwitCode(account.value!); + if (result == true) { + break; + } + } + } + if (mounted) { if (isDesktop) { Navigator.of(context, rootNavigator: true).pop(); @@ -223,6 +256,14 @@ class _PaynymClaimViewState extends ConsumerState { if (claim.value?.claimed == pCode.toString()) { final account = await ref.read(paynymAPIProvider).nym(pCode.toString()); + if (!account.value!.segwit) { + for (int i = 0; i < 100; i++) { + final result = await _addSegwitCode(account.value!); + if (result == true) { + break; + } + } + } ref.read(myPaynymAccountStateProvider.state).state = account.value!; diff --git a/lib/pages/paynym/subwidgets/paynym_followers_list.dart b/lib/pages/paynym/subwidgets/paynym_followers_list.dart index d8583954d..1237b2c4a 100644 --- a/lib/pages/paynym/subwidgets/paynym_followers_list.dart +++ b/lib/pages/paynym/subwidgets/paynym_followers_list.dart @@ -8,7 +8,6 @@ import 'package:stackwallet/providers/global/wallets_provider.dart'; import 'package:stackwallet/providers/wallet/my_paynym_account_state_provider.dart'; import 'package:stackwallet/services/mixins/paynym_wallet_interface.dart'; import 'package:stackwallet/utilities/constants.dart'; -import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart'; import 'package:stackwallet/utilities/logger.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart'; @@ -75,7 +74,7 @@ class _PaynymFollowersListState extends ConsumerState { // get payment code final pCode = await wallet.getPaymentCode( - DerivePathTypeExt.primaryFor(manager.coin), + isSegwit: false, ); // get account from api diff --git a/lib/pages/paynym/subwidgets/paynym_following_list.dart b/lib/pages/paynym/subwidgets/paynym_following_list.dart index 4d9df16ac..f12d30cdf 100644 --- a/lib/pages/paynym/subwidgets/paynym_following_list.dart +++ b/lib/pages/paynym/subwidgets/paynym_following_list.dart @@ -8,7 +8,6 @@ import 'package:stackwallet/providers/global/wallets_provider.dart'; import 'package:stackwallet/providers/wallet/my_paynym_account_state_provider.dart'; import 'package:stackwallet/services/mixins/paynym_wallet_interface.dart'; import 'package:stackwallet/utilities/constants.dart'; -import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart'; import 'package:stackwallet/utilities/logger.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart'; @@ -75,7 +74,7 @@ class _PaynymFollowingListState extends ConsumerState { // get payment code final pCode = await wallet.getPaymentCode( - DerivePathTypeExt.primaryFor(manager.coin), + isSegwit: false, ); // get account from api diff --git a/lib/pages/send_view/send_view.dart b/lib/pages/send_view/send_view.dart index 83c40943f..4444aab75 100644 --- a/lib/pages/send_view/send_view.dart +++ b/lib/pages/send_view/send_view.dart @@ -453,7 +453,7 @@ class _SendViewState extends ConsumerState { final wallet = manager.wallet as PaynymWalletInterface; final paymentCode = PaymentCode.fromPaymentCode( widget.accountLite!.code, - wallet.networkType, + networkType: wallet.networkType, ); final feeRate = ref.read(feeRateTypeStateProvider); txDataFuture = wallet.preparePaymentCodeSend( diff --git a/lib/pages/wallet_view/wallet_view.dart b/lib/pages/wallet_view/wallet_view.dart index 6e39edd9b..90af5d02d 100644 --- a/lib/pages/wallet_view/wallet_view.dart +++ b/lib/pages/wallet_view/wallet_view.dart @@ -43,7 +43,6 @@ import 'package:stackwallet/utilities/clipboard_interface.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/enums/backup_frequency_type.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; -import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart'; import 'package:stackwallet/utilities/enums/wallet_balance_toggle_state.dart'; import 'package:stackwallet/utilities/logger.dart'; import 'package:stackwallet/utilities/show_loading.dart'; @@ -909,7 +908,8 @@ class _WalletViewState extends ConsumerState { manager.wallet as PaynymWalletInterface; final code = await paynymInterface.getPaymentCode( - DerivePathTypeExt.primaryFor(manager.coin)); + isSegwit: false, + ); final account = await ref .read(paynymAPIProvider) @@ -925,7 +925,8 @@ class _WalletViewState extends ConsumerState { // check if account exists and for matching code to see if claimed if (account.value != null && - account.value!.codes.first.claimed) { + account.value!.codes.first.claimed && + account.value!.segwit) { ref.read(myPaynymAccountStateProvider.state).state = account.value!; diff --git a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_wallet_features.dart b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_wallet_features.dart index 089c0e19f..7f230abf7 100644 --- a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_wallet_features.dart +++ b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_wallet_features.dart @@ -21,7 +21,6 @@ import 'package:stackwallet/utilities/amount/amount.dart'; import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; -import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart'; import 'package:stackwallet/utilities/logger.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart'; @@ -271,8 +270,7 @@ class _DesktopWalletFeaturesState extends ConsumerState { final wallet = manager.wallet as PaynymWalletInterface; - final code = - await wallet.getPaymentCode(DerivePathTypeExt.primaryFor(manager.coin)); + final code = await wallet.getPaymentCode(isSegwit: false); final account = await ref.read(paynymAPIProvider).nym(code.toString()); @@ -285,7 +283,9 @@ class _DesktopWalletFeaturesState extends ConsumerState { Navigator.of(context, rootNavigator: true).pop(); // check if account exists and for matching code to see if claimed - if (account.value != null && account.value!.codes.first.claimed) { + if (account.value != null && + account.value!.codes.first.claimed && + account.value!.segwit) { ref.read(myPaynymAccountStateProvider.state).state = account.value!; await Navigator.of(context).pushNamed( diff --git a/lib/services/coins/bitcoin/bitcoin_wallet.dart b/lib/services/coins/bitcoin/bitcoin_wallet.dart index 0625957f6..dd3301835 100644 --- a/lib/services/coins/bitcoin/bitcoin_wallet.dart +++ b/lib/services/coins/bitcoin/bitcoin_wallet.dart @@ -164,6 +164,7 @@ class BitcoinWallet extends CoinServiceAPI // _checkP2PKHChangeAddressForTransactions, dustLimitP2PKH: DUST_LIMIT_P2PKH.raw.toInt(), minConfirms: MINIMUM_CONFIRMATIONS, + dustLimit: DUST_LIMIT.raw.toInt(), ); } @@ -659,7 +660,8 @@ class BitcoinWallet extends CoinServiceAPI } // get own payment code - final myCode = await getPaymentCode(DerivePathType.bip44, root); + // isSegwit does not matter here at all + final myCode = await getPaymentCode(isSegwit: false); // refresh transactions to pick up any received notification transactions await _refreshTransactions(); @@ -915,7 +917,8 @@ class BitcoinWallet extends CoinServiceAPI GlobalEventBus.instance.fire(RefreshPercentChangedEvent(0.0, walletId)); GlobalEventBus.instance.fire(RefreshPercentChangedEvent(0.1, walletId)); - final myCode = await getPaymentCode(DerivePathType.bip44); + // isSegwit does not matter here at all + final myCode = await getPaymentCode(isSegwit: false); final Set codesToCheck = {}; final nym = await PaynymIsApi().nym(myCode.toString()); if (nym.value != null) { diff --git a/lib/utilities/paynym_is_api.dart b/lib/utilities/paynym_is_api.dart index 7d1fc79ed..45e6c07e0 100644 --- a/lib/utilities/paynym_is_api.dart +++ b/lib/utilities/paynym_is_api.dart @@ -543,24 +543,44 @@ class PaynymIsApi { // | 401 | Unauthorized token or signature or Unclaimed payment code | // // ------ + Future> add( + String token, + String signature, + String nym, + String code, + ) async { + final result = await _post( + "/nym/add", + { + "nym": nym, + "code": code, + "signature": signature, + }, + { + "auth-token": token, + }, + ); -// NOT USED - // Future> add( - // String token, - // String signature, - // String nym, - // String code, - // ) async { - // return _post( - // "/add", - // { - // "nym": nym, - // "code": code, - // "signature": signature, - // }, - // { - // "auth-token": token, - // }, - // ); - // } + String message; + bool value = false; + + switch (result.item2) { + case 200: + message = "Code added successfully"; + value = true; + break; + case 400: + message = "Bad request"; + break; + case 401: + message = "Unauthorized token or signature or Unclaimed payment code"; + break; + case 404: + message = "Nym not found"; + break; + default: + message = result.item1["message"] as String? ?? "Unknown error"; + } + return PaynymResponse(value, result.item2, message); + } } diff --git a/lib/widgets/custom_buttons/paynym_follow_toggle_button.dart b/lib/widgets/custom_buttons/paynym_follow_toggle_button.dart index e4235fef4..ba7bcf8ea 100644 --- a/lib/widgets/custom_buttons/paynym_follow_toggle_button.dart +++ b/lib/widgets/custom_buttons/paynym_follow_toggle_button.dart @@ -11,7 +11,6 @@ import 'package:stackwallet/providers/global/wallets_provider.dart'; import 'package:stackwallet/providers/wallet/my_paynym_account_state_provider.dart'; import 'package:stackwallet/services/mixins/paynym_wallet_interface.dart'; import 'package:stackwallet/utilities/assets.dart'; -import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/utilities/util.dart'; import 'package:stackwallet/widgets/desktop/primary_button.dart'; @@ -68,8 +67,7 @@ class _PaynymFollowToggleButtonState .read(paynymAPIProvider) .nym(widget.paymentCodeStringToFollow, true); - final myPCode = - await wallet.getPaymentCode(DerivePathTypeExt.primaryFor(manager.coin)); + final myPCode = await wallet.getPaymentCode(isSegwit: false); PaynymResponse token = await ref.read(paynymAPIProvider).token(myPCode.toString()); @@ -169,8 +167,7 @@ class _PaynymFollowToggleButtonState .read(paynymAPIProvider) .nym(widget.paymentCodeStringToFollow, true); - final myPCode = - await wallet.getPaymentCode(DerivePathTypeExt.primaryFor(manager.coin)); + final myPCode = await wallet.getPaymentCode(isSegwit: false); PaynymResponse token = await ref.read(paynymAPIProvider).token(myPCode.toString()); diff --git a/pubspec.lock b/pubspec.lock index a59162d95..e9aa6ec31 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -111,8 +111,8 @@ packages: dependency: "direct main" description: path: "." - ref: "3e27b910d92e2ab816d589d202161490c00f986b" - resolved-ref: "3e27b910d92e2ab816d589d202161490c00f986b" + ref: dfbbcba5355a9d98ad96ea350f6cff88fdac4adc + resolved-ref: dfbbcba5355a9d98ad96ea350f6cff88fdac4adc url: "https://github.com/cypherstack/bip47.git" source: git version: "2.0.0"