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 {
final String nymID;
final String nymName;
final bool segwit;
final List<PaynymCode> 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<String, dynamic> map)
: nymID = map["nymID"] as String,
nymName = map["nymName"] as String,
segwit = map["segwit"] as bool,
codes = (map["codes"] as List<dynamic>)
.map((e) => PaynymCode.fromMap(Map<String, dynamic>.from(e as Map)))
.toList(),
@ -39,6 +42,7 @@ class PaynymAccount {
PaynymAccount copyWith({
String? nymID,
String? nymName,
bool? segwit,
List<PaynymCode>? codes,
List<PaynymAccountLite>? followers,
List<PaynymAccountLite>? 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<String, dynamic> 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()),

View file

@ -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<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
Widget build(BuildContext context) {
debugPrint("BUILD: $runtimeType");
@ -169,8 +191,7 @@ class _PaynymClaimViewState extends ConsumerState<PaynymClaimView> {
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<PaynymClaimView> {
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<PaynymClaimView> {
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!;

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/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<PaynymFollowersList> {
// get payment code
final pCode = await wallet.getPaymentCode(
DerivePathTypeExt.primaryFor(manager.coin),
isSegwit: false,
);
// 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/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<PaynymFollowingList> {
// get payment code
final pCode = await wallet.getPaymentCode(
DerivePathTypeExt.primaryFor(manager.coin),
isSegwit: false,
);
// get account from api

View file

@ -453,7 +453,7 @@ class _SendViewState extends ConsumerState<SendView> {
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(

View file

@ -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<WalletView> {
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<WalletView> {
// 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!;

View file

@ -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<DesktopWalletFeatures> {
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<DesktopWalletFeatures> {
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(

View file

@ -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<String> codesToCheck = {};
final nym = await PaynymIsApi().nym(myCode.toString());
if (nym.value != null) {

View file

@ -543,24 +543,44 @@ class PaynymIsApi {
// | 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
// Future<Map<String, dynamic>> 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);
}
}

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/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<String> 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<String> token =
await ref.read(paynymAPIProvider).token(myPCode.toString());

View file

@ -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"