mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-17 05:41:29 +02:00
CW-1146-Enable-Zano-buy-sell-for-DFX (#2458)
* feat(CW-1148): Add Zano wallet support for message * refactor(CW-1148): Simplify `signMessage` logic in Zano wallet API * fix: remove unsupported wallet types from DFX Buy provider * fix: correct DFX Buy provider parameter name from `amount` to `amount-in`
This commit is contained in:
@@ -59,9 +59,8 @@ abstract class ZanoWalletBase
|
||||
String get password => _password;
|
||||
|
||||
@override
|
||||
Future<String> signMessage(String message, {String? address = null}) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
Future<String> signMessage(String message, {String? address = null}) =>
|
||||
super.signMessage(message, address: address);
|
||||
|
||||
@override
|
||||
Future<bool> verifyMessage(String message, String signature, {String? address = null}) {
|
||||
|
||||
@@ -401,6 +401,35 @@ mixin ZanoWalletApi {
|
||||
throw TransferException('Transfer error, empty result');
|
||||
}
|
||||
|
||||
Future<String> signMessage(String message, {String? address = null}) async {
|
||||
try {
|
||||
final messageBase64 = convert.base64.encode(convert.utf8.encode(message));
|
||||
final response = await invokeMethod('sign_message', {'buff': messageBase64});
|
||||
final responseData = convert.jsonDecode(response) as Map<String, dynamic>;
|
||||
|
||||
if (responseData['error'] != null) {
|
||||
printV('ZANO sign_message error: ${responseData['error']}');
|
||||
throw Exception('Zano sign_message failed: ${responseData['error']}');
|
||||
}
|
||||
|
||||
final result = responseData['result'] as Map<String, dynamic>?;
|
||||
if (result == null) {
|
||||
throw Exception('Invalid response from sign_message');
|
||||
}
|
||||
|
||||
final signature = result['sig'] as String?;
|
||||
|
||||
if (signature == null) {
|
||||
throw Exception('No signature in response');
|
||||
}
|
||||
|
||||
return signature;
|
||||
} catch (e) {
|
||||
printV('ZANO signMessage error: $e');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
void _checkForErrors(Map<String, dynamic>? map) {
|
||||
if (map == null) {
|
||||
throw ZanoWalletException('Empty response');
|
||||
@@ -510,4 +539,4 @@ Future<String> _closeWallet(int hWallet) async {
|
||||
return str;
|
||||
}
|
||||
|
||||
Map<String, List<int>> debugCallLength() => zano.debugCallLength;
|
||||
Map<String, List<int>> debugCallLength() => zano.debugCallLength;
|
||||
|
||||
@@ -62,9 +62,9 @@ class DFXBuyProvider extends BuyProvider {
|
||||
String get blockchain {
|
||||
switch (wallet.type) {
|
||||
case WalletType.bitcoin:
|
||||
case WalletType.bitcoinCash:
|
||||
case WalletType.litecoin:
|
||||
return 'Bitcoin';
|
||||
case WalletType.zano:
|
||||
return 'Zano';
|
||||
default:
|
||||
return walletTypeToString(wallet.type);
|
||||
}
|
||||
@@ -131,6 +131,7 @@ class DFXBuyProvider extends BuyProvider {
|
||||
case WalletType.litecoin:
|
||||
case WalletType.bitcoin:
|
||||
case WalletType.bitcoinCash:
|
||||
case WalletType.zano:
|
||||
return await wallet.signMessage(message, address: walletAddress);
|
||||
default:
|
||||
throw Exception("WalletType is not available for DFX ${wallet.type}");
|
||||
@@ -345,7 +346,7 @@ class DFXBuyProvider extends BuyProvider {
|
||||
'asset-out': isBuyAction ? quote.cryptoCurrency.toString() : quote.fiatCurrency.toString(),
|
||||
'blockchain': blockchain,
|
||||
'asset-in': isBuyAction ? quote.fiatCurrency.toString() : quote.cryptoCurrency.toString(),
|
||||
'amount': amount.toString() //TODO: Amount does not work
|
||||
'amount-in': amount.toString()
|
||||
});
|
||||
|
||||
if (await canLaunchUrl(uri)) {
|
||||
|
||||
Reference in New Issue
Block a user