diff --git a/cw_bitcoin/lib/electrum_wallet_addresses.dart b/cw_bitcoin/lib/electrum_wallet_addresses.dart index ab99a875c..c9e4f8200 100644 --- a/cw_bitcoin/lib/electrum_wallet_addresses.dart +++ b/cw_bitcoin/lib/electrum_wallet_addresses.dart @@ -62,6 +62,9 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store { return walletInfo.type == WalletType.bitcoinCash ? toCashAddr(receiveAddress) : receiveAddress; } + @override + String get primaryAddress => getAddress(index: 0, hd: mainHd); + @override set address(String addr) => null; diff --git a/cw_core/lib/wallet_addresses.dart b/cw_core/lib/wallet_addresses.dart index 632eb1332..d8c84c80c 100644 --- a/cw_core/lib/wallet_addresses.dart +++ b/cw_core/lib/wallet_addresses.dart @@ -10,6 +10,8 @@ abstract class WalletAddresses { String get address; + String? get primaryAddress => null; + set address(String address); Map addressesMap; diff --git a/lib/buy/dfx/dfx_buy_provider.dart b/lib/buy/dfx/dfx_buy_provider.dart index 384b7d504..78a5277ce 100644 --- a/lib/buy/dfx/dfx_buy_provider.dart +++ b/lib/buy/dfx/dfx_buy_provider.dart @@ -66,8 +66,10 @@ class DFXBuyProvider extends BuyProvider { } } + String get walletAddress => + wallet.walletAddresses.primaryAddress ?? wallet.walletAddresses.address; + Future getSignMessage() async { - final walletAddress = wallet.walletAddresses.address; final uri = Uri.https(_baseUrl, _authPath, {'address': walletAddress}); var response = await http.get(uri, headers: {'accept': 'application/json'}); @@ -83,7 +85,6 @@ class DFXBuyProvider extends BuyProvider { Future signUp() async { final signMessage = getSignature(await getSignMessage()); - final walletAddress = wallet.walletAddresses.address; final requestBody = jsonEncode({ 'wallet': walletName, @@ -92,8 +93,11 @@ class DFXBuyProvider extends BuyProvider { }); final uri = Uri.https(_baseUrl, _signUpPath); - var response = await http.post(uri, - headers: {'Content-Type': 'application/json'}, body: requestBody); + var response = await http.post( + uri, + headers: {'Content-Type': 'application/json'}, + body: requestBody, + ); if (response.statusCode == 201) { final responseBody = jsonDecode(response.body); @@ -103,14 +107,12 @@ class DFXBuyProvider extends BuyProvider { final message = responseBody['message'] ?? 'Service unavailable in your country'; throw Exception(message); } else { - throw Exception( - 'Failed to sign up. Status: ${response.statusCode} ${response.body}'); + throw Exception('Failed to sign up. Status: ${response.statusCode} ${response.body}'); } } Future signIn() async { final signMessage = getSignature(await getSignMessage()); - final walletAddress = wallet.walletAddresses.address; final requestBody = jsonEncode({ 'address': walletAddress, @@ -118,8 +120,11 @@ class DFXBuyProvider extends BuyProvider { }); final uri = Uri.https(_baseUrl, _signInPath); - var response = await http.post(uri, - headers: {'Content-Type': 'application/json'}, body: requestBody); + var response = await http.post( + uri, + headers: {'Content-Type': 'application/json'}, + body: requestBody, + ); if (response.statusCode == 201) { final responseBody = jsonDecode(response.body); @@ -129,8 +134,7 @@ class DFXBuyProvider extends BuyProvider { final message = responseBody['message'] ?? 'Service unavailable in your country'; throw Exception(message); } else { - throw Exception( - 'Failed to sign in. Status: ${response.statusCode} ${response.body}'); + throw Exception('Failed to sign in. Status: ${response.statusCode} ${response.body}'); } } @@ -142,8 +146,7 @@ class DFXBuyProvider extends BuyProvider { case WalletType.litecoin: case WalletType.bitcoin: case WalletType.bitcoinCash: - return wallet.signMessage(message, - address: wallet.walletAddresses.address); + return wallet.signMessage(message, address: walletAddress); default: throw Exception("WalletType is not available for DFX ${wallet.type}"); } @@ -178,8 +181,7 @@ class DFXBuyProvider extends BuyProvider { if (await canLaunchUrl(uri)) { if (DeviceInfo.instance.isMobile) { - Navigator.of(context) - .pushNamed(Routes.webViewPage, arguments: [title, uri]); + Navigator.of(context).pushNamed(Routes.webViewPage, arguments: [title, uri]); } else { await launchUrl(uri, mode: LaunchMode.externalApplication); }