segwit paynym.is updates and fixes

This commit is contained in:
julian 2023-04-25 15:06:12 -06:00
parent f5b39eadc5
commit 8c3fffde9d
11 changed files with 109 additions and 43 deletions

View file

@ -4,6 +4,7 @@ import 'package:stackwallet/models/paynym/paynym_code.dart';
class PaynymAccount { class PaynymAccount {
final String nymID; final String nymID;
final String nymName; final String nymName;
final bool segwit;
final List<PaynymCode> codes; final List<PaynymCode> codes;
@ -16,6 +17,7 @@ class PaynymAccount {
PaynymAccount( PaynymAccount(
this.nymID, this.nymID,
this.nymName, this.nymName,
this.segwit,
this.codes, this.codes,
this.followers, this.followers,
this.following, this.following,
@ -24,6 +26,7 @@ class PaynymAccount {
PaynymAccount.fromMap(Map<String, dynamic> map) PaynymAccount.fromMap(Map<String, dynamic> map)
: nymID = map["nymID"] as String, : nymID = map["nymID"] as String,
nymName = map["nymName"] as String, nymName = map["nymName"] as String,
segwit = map["segwit"] as bool,
codes = (map["codes"] as List<dynamic>) codes = (map["codes"] as List<dynamic>)
.map((e) => PaynymCode.fromMap(Map<String, dynamic>.from(e as Map))) .map((e) => PaynymCode.fromMap(Map<String, dynamic>.from(e as Map)))
.toList(), .toList(),
@ -39,6 +42,7 @@ class PaynymAccount {
PaynymAccount copyWith({ PaynymAccount copyWith({
String? nymID, String? nymID,
String? nymName, String? nymName,
bool? segwit,
List<PaynymCode>? codes, List<PaynymCode>? codes,
List<PaynymAccountLite>? followers, List<PaynymAccountLite>? followers,
List<PaynymAccountLite>? following, List<PaynymAccountLite>? following,
@ -46,6 +50,7 @@ class PaynymAccount {
return PaynymAccount( return PaynymAccount(
nymID ?? this.nymID, nymID ?? this.nymID,
nymName ?? this.nymName, nymName ?? this.nymName,
segwit ?? this.segwit,
codes ?? this.codes, codes ?? this.codes,
followers ?? this.followers, followers ?? this.followers,
following ?? this.following, following ?? this.following,
@ -55,6 +60,7 @@ class PaynymAccount {
Map<String, dynamic> toMap() => { Map<String, dynamic> toMap() => {
"nymID": nymID, "nymID": nymID,
"nymName": nymName, "nymName": nymName,
"segwit": segwit,
"codes": codes.map((e) => e.toMap()), "codes": codes.map((e) => e.toMap()),
"followers": followers.map((e) => e.toMap()), "followers": followers.map((e) => e.toMap()),
"following": followers.map((e) => e.toMap()), "following": followers.map((e) => e.toMap()),

View file

@ -3,6 +3,7 @@ import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/flutter_svg.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/dialogs/claiming_paynym_dialog.dart';
import 'package:stackwallet/pages/paynym/paynym_home_view.dart'; import 'package:stackwallet/pages/paynym/paynym_home_view.dart';
import 'package:stackwallet/pages/wallet_view/wallet_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/providers/wallet/my_paynym_account_state_provider.dart';
import 'package:stackwallet/services/mixins/paynym_wallet_interface.dart'; import 'package:stackwallet/services/mixins/paynym_wallet_interface.dart';
import 'package:stackwallet/utilities/assets.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/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/utilities/util.dart'; import 'package:stackwallet/utilities/util.dart';
@ -36,6 +36,28 @@ class PaynymClaimView extends ConsumerStatefulWidget {
} }
class _PaynymClaimViewState extends ConsumerState<PaynymClaimView> { class _PaynymClaimViewState extends ConsumerState<PaynymClaimView> {
Future<bool> _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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
debugPrint("BUILD: $runtimeType"); debugPrint("BUILD: $runtimeType");
@ -169,8 +191,7 @@ class _PaynymClaimViewState extends ConsumerState<PaynymClaimView> {
if (shouldCancel) return; if (shouldCancel) return;
// get payment code // get payment code
final pCode = await wallet.getPaymentCode( final pCode = await wallet.getPaymentCode(isSegwit: false);
DerivePathTypeExt.primaryFor(manager.coin));
if (shouldCancel) return; if (shouldCancel) return;
@ -185,6 +206,18 @@ class _PaynymClaimViewState extends ConsumerState<PaynymClaimView> {
if (created.value!.claimed) { if (created.value!.claimed) {
// payment code already claimed // payment code already claimed
debugPrint("pcode 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 (mounted) {
if (isDesktop) { if (isDesktop) {
Navigator.of(context, rootNavigator: true).pop(); Navigator.of(context, rootNavigator: true).pop();
@ -223,6 +256,14 @@ class _PaynymClaimViewState extends ConsumerState<PaynymClaimView> {
if (claim.value?.claimed == pCode.toString()) { if (claim.value?.claimed == pCode.toString()) {
final account = final account =
await ref.read(paynymAPIProvider).nym(pCode.toString()); 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 = ref.read(myPaynymAccountStateProvider.state).state =
account.value!; account.value!;

View file

@ -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/providers/wallet/my_paynym_account_state_provider.dart';
import 'package:stackwallet/services/mixins/paynym_wallet_interface.dart'; import 'package:stackwallet/services/mixins/paynym_wallet_interface.dart';
import 'package:stackwallet/utilities/constants.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/logger.dart';
import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart';
@ -75,7 +74,7 @@ class _PaynymFollowersListState extends ConsumerState<PaynymFollowersList> {
// get payment code // get payment code
final pCode = await wallet.getPaymentCode( final pCode = await wallet.getPaymentCode(
DerivePathTypeExt.primaryFor(manager.coin), isSegwit: false,
); );
// get account from api // get account from api

View file

@ -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/providers/wallet/my_paynym_account_state_provider.dart';
import 'package:stackwallet/services/mixins/paynym_wallet_interface.dart'; import 'package:stackwallet/services/mixins/paynym_wallet_interface.dart';
import 'package:stackwallet/utilities/constants.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/logger.dart';
import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart';
@ -75,7 +74,7 @@ class _PaynymFollowingListState extends ConsumerState<PaynymFollowingList> {
// get payment code // get payment code
final pCode = await wallet.getPaymentCode( final pCode = await wallet.getPaymentCode(
DerivePathTypeExt.primaryFor(manager.coin), isSegwit: false,
); );
// get account from api // get account from api

View file

@ -453,7 +453,7 @@ class _SendViewState extends ConsumerState<SendView> {
final wallet = manager.wallet as PaynymWalletInterface; final wallet = manager.wallet as PaynymWalletInterface;
final paymentCode = PaymentCode.fromPaymentCode( final paymentCode = PaymentCode.fromPaymentCode(
widget.accountLite!.code, widget.accountLite!.code,
wallet.networkType, networkType: wallet.networkType,
); );
final feeRate = ref.read(feeRateTypeStateProvider); final feeRate = ref.read(feeRateTypeStateProvider);
txDataFuture = wallet.preparePaymentCodeSend( txDataFuture = wallet.preparePaymentCodeSend(

View file

@ -43,7 +43,6 @@ import 'package:stackwallet/utilities/clipboard_interface.dart';
import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/enums/backup_frequency_type.dart'; import 'package:stackwallet/utilities/enums/backup_frequency_type.dart';
import 'package:stackwallet/utilities/enums/coin_enum.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/enums/wallet_balance_toggle_state.dart';
import 'package:stackwallet/utilities/logger.dart'; import 'package:stackwallet/utilities/logger.dart';
import 'package:stackwallet/utilities/show_loading.dart'; import 'package:stackwallet/utilities/show_loading.dart';
@ -909,7 +908,8 @@ class _WalletViewState extends ConsumerState<WalletView> {
manager.wallet as PaynymWalletInterface; manager.wallet as PaynymWalletInterface;
final code = await paynymInterface.getPaymentCode( final code = await paynymInterface.getPaymentCode(
DerivePathTypeExt.primaryFor(manager.coin)); isSegwit: false,
);
final account = await ref final account = await ref
.read(paynymAPIProvider) .read(paynymAPIProvider)
@ -925,7 +925,8 @@ class _WalletViewState extends ConsumerState<WalletView> {
// check if account exists and for matching code to see if claimed // check if account exists and for matching code to see if claimed
if (account.value != null && if (account.value != null &&
account.value!.codes.first.claimed) { account.value!.codes.first.claimed &&
account.value!.segwit) {
ref.read(myPaynymAccountStateProvider.state).state = ref.read(myPaynymAccountStateProvider.state).state =
account.value!; account.value!;

View file

@ -21,7 +21,6 @@ import 'package:stackwallet/utilities/amount/amount.dart';
import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/enums/coin_enum.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/logger.dart';
import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart';
@ -271,8 +270,7 @@ class _DesktopWalletFeaturesState extends ConsumerState<DesktopWalletFeatures> {
final wallet = manager.wallet as PaynymWalletInterface; final wallet = manager.wallet as PaynymWalletInterface;
final code = final code = await wallet.getPaymentCode(isSegwit: false);
await wallet.getPaymentCode(DerivePathTypeExt.primaryFor(manager.coin));
final account = await ref.read(paynymAPIProvider).nym(code.toString()); final account = await ref.read(paynymAPIProvider).nym(code.toString());
@ -285,7 +283,9 @@ class _DesktopWalletFeaturesState extends ConsumerState<DesktopWalletFeatures> {
Navigator.of(context, rootNavigator: true).pop(); Navigator.of(context, rootNavigator: true).pop();
// check if account exists and for matching code to see if claimed // 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!; ref.read(myPaynymAccountStateProvider.state).state = account.value!;
await Navigator.of(context).pushNamed( await Navigator.of(context).pushNamed(

View file

@ -164,6 +164,7 @@ class BitcoinWallet extends CoinServiceAPI
// _checkP2PKHChangeAddressForTransactions, // _checkP2PKHChangeAddressForTransactions,
dustLimitP2PKH: DUST_LIMIT_P2PKH.raw.toInt(), dustLimitP2PKH: DUST_LIMIT_P2PKH.raw.toInt(),
minConfirms: MINIMUM_CONFIRMATIONS, minConfirms: MINIMUM_CONFIRMATIONS,
dustLimit: DUST_LIMIT.raw.toInt(),
); );
} }
@ -659,7 +660,8 @@ class BitcoinWallet extends CoinServiceAPI
} }
// get own payment code // 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 // refresh transactions to pick up any received notification transactions
await _refreshTransactions(); await _refreshTransactions();
@ -915,7 +917,8 @@ class BitcoinWallet extends CoinServiceAPI
GlobalEventBus.instance.fire(RefreshPercentChangedEvent(0.0, walletId)); GlobalEventBus.instance.fire(RefreshPercentChangedEvent(0.0, walletId));
GlobalEventBus.instance.fire(RefreshPercentChangedEvent(0.1, 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<String> codesToCheck = {}; final Set<String> codesToCheck = {};
final nym = await PaynymIsApi().nym(myCode.toString()); final nym = await PaynymIsApi().nym(myCode.toString());
if (nym.value != null) { if (nym.value != null) {

View file

@ -543,24 +543,44 @@ class PaynymIsApi {
// | 401 | Unauthorized token or signature or Unclaimed payment code | // | 401 | Unauthorized token or signature or Unclaimed payment code |
// //
// ------ // ------
Future<PaynymResponse<bool>> 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 String message;
// Future<Map<String, dynamic>> add( bool value = false;
// String token,
// String signature, switch (result.item2) {
// String nym, case 200:
// String code, message = "Code added successfully";
// ) async { value = true;
// return _post( break;
// "/add", case 400:
// { message = "Bad request";
// "nym": nym, break;
// "code": code, case 401:
// "signature": signature, message = "Unauthorized token or signature or Unclaimed payment code";
// }, break;
// { case 404:
// "auth-token": token, message = "Nym not found";
// }, break;
// ); default:
// } message = result.item1["message"] as String? ?? "Unknown error";
}
return PaynymResponse(value, result.item2, message);
}
} }

View file

@ -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/providers/wallet/my_paynym_account_state_provider.dart';
import 'package:stackwallet/services/mixins/paynym_wallet_interface.dart'; import 'package:stackwallet/services/mixins/paynym_wallet_interface.dart';
import 'package:stackwallet/utilities/assets.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/theme/stack_colors.dart';
import 'package:stackwallet/utilities/util.dart'; import 'package:stackwallet/utilities/util.dart';
import 'package:stackwallet/widgets/desktop/primary_button.dart'; import 'package:stackwallet/widgets/desktop/primary_button.dart';
@ -68,8 +67,7 @@ class _PaynymFollowToggleButtonState
.read(paynymAPIProvider) .read(paynymAPIProvider)
.nym(widget.paymentCodeStringToFollow, true); .nym(widget.paymentCodeStringToFollow, true);
final myPCode = final myPCode = await wallet.getPaymentCode(isSegwit: false);
await wallet.getPaymentCode(DerivePathTypeExt.primaryFor(manager.coin));
PaynymResponse<String> token = PaynymResponse<String> token =
await ref.read(paynymAPIProvider).token(myPCode.toString()); await ref.read(paynymAPIProvider).token(myPCode.toString());
@ -169,8 +167,7 @@ class _PaynymFollowToggleButtonState
.read(paynymAPIProvider) .read(paynymAPIProvider)
.nym(widget.paymentCodeStringToFollow, true); .nym(widget.paymentCodeStringToFollow, true);
final myPCode = final myPCode = await wallet.getPaymentCode(isSegwit: false);
await wallet.getPaymentCode(DerivePathTypeExt.primaryFor(manager.coin));
PaynymResponse<String> token = PaynymResponse<String> token =
await ref.read(paynymAPIProvider).token(myPCode.toString()); await ref.read(paynymAPIProvider).token(myPCode.toString());

View file

@ -111,8 +111,8 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
path: "." path: "."
ref: "3e27b910d92e2ab816d589d202161490c00f986b" ref: dfbbcba5355a9d98ad96ea350f6cff88fdac4adc
resolved-ref: "3e27b910d92e2ab816d589d202161490c00f986b" resolved-ref: dfbbcba5355a9d98ad96ea350f6cff88fdac4adc
url: "https://github.com/cypherstack/bip47.git" url: "https://github.com/cypherstack/bip47.git"
source: git source: git
version: "2.0.0" version: "2.0.0"