mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-09 12:29:31 +00:00
Added ability sending to FIO address (#370)
* Added ability sending to FIO address * remove apiKey property * fix conditions for FIO address checking
This commit is contained in:
parent
427efb44fa
commit
fc58972bf9
4 changed files with 81 additions and 1 deletions
57
lib/entities/fio_address_provider.dart
Normal file
57
lib/entities/fio_address_provider.dart
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
class FioAddressProvider {
|
||||||
|
static const apiAuthority = 'fio.blockpane.com';
|
||||||
|
static const availCheck = '/v1/chain/avail_check';
|
||||||
|
static const getAddress = '/v1/chain/get_pub_address';
|
||||||
|
|
||||||
|
static Future<bool> checkAvail(String fioAddress) async {
|
||||||
|
bool isFioRegistered = false;
|
||||||
|
final headers = {'Content-Type': 'application/json'};
|
||||||
|
final body = <String, String>{"fio_name": fioAddress};
|
||||||
|
|
||||||
|
final uri = Uri.https(apiAuthority, availCheck);
|
||||||
|
final response =
|
||||||
|
await http.post(uri, headers: headers, body: json.encode(body));
|
||||||
|
|
||||||
|
if (response.statusCode != 200) {
|
||||||
|
return isFioRegistered;
|
||||||
|
}
|
||||||
|
|
||||||
|
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
||||||
|
isFioRegistered = responseJSON['is_registered'] as int == 1;
|
||||||
|
|
||||||
|
return isFioRegistered;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<String> getPubAddress(String fioAddress, String token) async {
|
||||||
|
final headers = {'Content-Type': 'application/json'};
|
||||||
|
final body = <String, String>{
|
||||||
|
"fio_address": fioAddress,
|
||||||
|
"chain_code": token.toUpperCase(),
|
||||||
|
"token_code": token.toUpperCase(),
|
||||||
|
};
|
||||||
|
|
||||||
|
final uri = Uri.https(apiAuthority, getAddress);
|
||||||
|
final response =
|
||||||
|
await http.post(uri, headers: headers, body: json.encode(body));
|
||||||
|
|
||||||
|
if (response.statusCode == 400) {
|
||||||
|
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
||||||
|
final error = responseJSON['error'] as String;
|
||||||
|
final message = responseJSON['message'] as String;
|
||||||
|
throw Exception('${error}\n$message');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.statusCode != 200) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
||||||
|
final String pubAddress = responseJSON['public_address'] as String;
|
||||||
|
|
||||||
|
return pubAddress;
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ import 'package:cake_wallet/entities/parsed_address.dart';
|
||||||
import 'package:cake_wallet/entities/unstoppable_domain_address.dart';
|
import 'package:cake_wallet/entities/unstoppable_domain_address.dart';
|
||||||
import 'package:cake_wallet/entities/emoji_string_extension.dart';
|
import 'package:cake_wallet/entities/emoji_string_extension.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:cake_wallet/entities/fio_address_provider.dart';
|
||||||
|
|
||||||
class AddressResolver {
|
class AddressResolver {
|
||||||
|
|
||||||
|
@ -26,6 +27,14 @@ class AddressResolver {
|
||||||
|
|
||||||
Future<ParsedAddress> resolve(String text, String ticker) async {
|
Future<ParsedAddress> resolve(String text, String ticker) async {
|
||||||
try {
|
try {
|
||||||
|
if (text.contains('@') && !text.contains('.')) {
|
||||||
|
final bool isFioRegistered = await FioAddressProvider.checkAvail(text);
|
||||||
|
if (isFioRegistered) {
|
||||||
|
final address = await FioAddressProvider.getPubAddress(text, ticker);
|
||||||
|
return ParsedAddress.fetchFioAddress(address: address, name: text);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
if (text.hasOnlyEmojis) {
|
if (text.hasOnlyEmojis) {
|
||||||
final addresses = await yatService.fetchYatAddress(text, ticker);
|
final addresses = await yatService.fetchYatAddress(text, ticker);
|
||||||
return ParsedAddress.fetchEmojiAddress(addresses: addresses, name: text);
|
return ParsedAddress.fetchEmojiAddress(addresses: addresses, name: text);
|
||||||
|
|
|
@ -2,7 +2,7 @@ import 'package:cake_wallet/entities/openalias_record.dart';
|
||||||
import 'package:cake_wallet/entities/yat_record.dart';
|
import 'package:cake_wallet/entities/yat_record.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
enum ParseFrom { unstoppableDomains, openAlias, yatRecord, notParsed }
|
enum ParseFrom { unstoppableDomains, openAlias, yatRecord, fio, notParsed }
|
||||||
|
|
||||||
class ParsedAddress {
|
class ParsedAddress {
|
||||||
ParsedAddress({
|
ParsedAddress({
|
||||||
|
@ -58,4 +58,13 @@ class ParsedAddress {
|
||||||
parseFrom: ParseFrom.openAlias,
|
parseFrom: ParseFrom.openAlias,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
factory ParsedAddress.fetchFioAddress({@required String address, @required String name}){
|
||||||
|
|
||||||
|
return ParsedAddress(
|
||||||
|
addresses: [address],
|
||||||
|
name: name,
|
||||||
|
parseFrom: ParseFrom.fio,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,11 @@ Future<String> extractAddressFromParsed(
|
||||||
content = S.of(context).openalias_alert_content(parsedAddress.name);
|
content = S.of(context).openalias_alert_content(parsedAddress.name);
|
||||||
address = parsedAddress.addresses.first;
|
address = parsedAddress.addresses.first;
|
||||||
break;
|
break;
|
||||||
|
case ParseFrom.fio:
|
||||||
|
title = S.of(context).address_detected;
|
||||||
|
content = S.of(context).openalias_alert_content(parsedAddress.name);
|
||||||
|
address = parsedAddress.addresses.first;
|
||||||
|
break;
|
||||||
case ParseFrom.yatRecord:
|
case ParseFrom.yatRecord:
|
||||||
if (parsedAddress.name.isEmpty) {
|
if (parsedAddress.name.isEmpty) {
|
||||||
title = S.of(context).yat_error;
|
title = S.of(context).yat_error;
|
||||||
|
|
Loading…
Reference in a new issue