mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-31 06:55:59 +00:00
CAKE-356 | applied yat record to parse_address_from_domain.dart and parse_address_from_domain_alert.dart; fixed yat_record.dart, yat_view_model.dart and yat_webview_page.dart
This commit is contained in:
parent
92aece5e31
commit
af356bd8f1
6 changed files with 108 additions and 29 deletions
|
@ -1,6 +1,7 @@
|
||||||
import 'package:cake_wallet/entities/openalias_record.dart';
|
import 'package:cake_wallet/entities/openalias_record.dart';
|
||||||
import 'package:cake_wallet/entities/parsed_address.dart';
|
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/yat/yat_record.dart';
|
||||||
|
|
||||||
const unstoppableDomains = [
|
const unstoppableDomains = [
|
||||||
'crypto',
|
'crypto',
|
||||||
|
@ -22,9 +23,22 @@ Future<ParsedAddress> parseAddressFromDomain(
|
||||||
final name = domainParts.last;
|
final name = domainParts.last;
|
||||||
|
|
||||||
if (domainParts.length <= 1 || domainParts.first.isEmpty || name.isEmpty) {
|
if (domainParts.length <= 1 || domainParts.first.isEmpty || name.isEmpty) {
|
||||||
|
try {
|
||||||
|
final address = await fetchYatAddress(domain);
|
||||||
|
|
||||||
|
if (address?.isEmpty ?? true) {
|
||||||
return ParsedAddress(address: domain);
|
return ParsedAddress(address: domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ParsedAddress(
|
||||||
|
address: address,
|
||||||
|
name: domain,
|
||||||
|
parseFrom: ParseFrom.yatRecord);
|
||||||
|
} catch (e) {
|
||||||
|
return ParsedAddress(address: domain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (unstoppableDomains.any((domain) => name.contains(domain))) {
|
if (unstoppableDomains.any((domain) => name.contains(domain))) {
|
||||||
final address =
|
final address =
|
||||||
await fetchUnstoppableDomainAddress(domain, ticker);
|
await fetchUnstoppableDomainAddress(domain, ticker);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
enum ParseFrom {unstoppableDomains, openAlias, notParsed}
|
enum ParseFrom {unstoppableDomains, openAlias, yatRecord, notParsed}
|
||||||
|
|
||||||
class ParsedAddress {
|
class ParsedAddress {
|
||||||
ParsedAddress({
|
ParsedAddress({
|
||||||
|
|
|
@ -17,6 +17,10 @@ void showAddressAlert(BuildContext context, ParsedAddress parsedAddress) async {
|
||||||
title = S.of(context).openalias_alert_title;
|
title = S.of(context).openalias_alert_title;
|
||||||
content = S.of(context).openalias_alert_content(parsedAddress.name);
|
content = S.of(context).openalias_alert_content(parsedAddress.name);
|
||||||
break;
|
break;
|
||||||
|
case ParseFrom.yatRecord:
|
||||||
|
title = 'Address detected';
|
||||||
|
content = 'This address is from ${parsedAddress.name} on Yat';
|
||||||
|
break;
|
||||||
case ParseFrom.notParsed:
|
case ParseFrom.notParsed:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'dart:async';
|
||||||
|
import 'dart:io';
|
||||||
import 'package:cake_wallet/palette.dart';
|
import 'package:cake_wallet/palette.dart';
|
||||||
import 'package:cake_wallet/src/screens/base_page.dart';
|
import 'package:cake_wallet/src/screens/base_page.dart';
|
||||||
import 'package:cake_wallet/view_model/yat_view_model.dart';
|
import 'package:cake_wallet/view_model/yat_view_model.dart';
|
||||||
|
@ -7,7 +9,37 @@ import 'package:webview_flutter/webview_flutter.dart';
|
||||||
enum YatMode {create, connect}
|
enum YatMode {create, connect}
|
||||||
|
|
||||||
class YatWebViewPage extends BasePage {
|
class YatWebViewPage extends BasePage {
|
||||||
YatWebViewPage({this.yatViewModel, this.mode}) {
|
YatWebViewPage({this.yatViewModel, this.mode});
|
||||||
|
|
||||||
|
final YatMode mode;
|
||||||
|
final YatViewModel yatViewModel;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get title => 'Yat';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Color get backgroundDarkColor => Colors.white;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Color get titleColor => Palette.darkBlueCraiola;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget body(BuildContext context) => YatWebViewPageBody(yatViewModel, mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
class YatWebViewPageBody extends StatefulWidget{
|
||||||
|
YatWebViewPageBody(this.yatViewModel, this.mode);
|
||||||
|
|
||||||
|
final YatMode mode;
|
||||||
|
final YatViewModel yatViewModel;
|
||||||
|
|
||||||
|
@override
|
||||||
|
YatWebViewPageBodyState createState() =>
|
||||||
|
YatWebViewPageBodyState(yatViewModel, mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
class YatWebViewPageBodyState extends State<YatWebViewPageBody> {
|
||||||
|
YatWebViewPageBodyState(this.yatViewModel, this.mode) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case YatMode.create:
|
case YatMode.create:
|
||||||
url = _baseUrl + _createSuffix;
|
url = _baseUrl + _createSuffix;
|
||||||
|
@ -20,7 +52,7 @@ class YatWebViewPage extends BasePage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const _baseUrl = 'https://y.at';
|
static const _baseUrl = 'https://yat.fyi';
|
||||||
static const _signInSuffix = '/sign-in';
|
static const _signInSuffix = '/sign-in';
|
||||||
static const _createSuffix = '/create';
|
static const _createSuffix = '/create';
|
||||||
|
|
||||||
|
@ -28,18 +60,53 @@ class YatWebViewPage extends BasePage {
|
||||||
final YatViewModel yatViewModel;
|
final YatViewModel yatViewModel;
|
||||||
|
|
||||||
String url;
|
String url;
|
||||||
|
WebViewController _webViewController;
|
||||||
|
GlobalKey _webViewkey;
|
||||||
|
Timer _timer;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get title => 'Yat';
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_webViewkey = GlobalKey();
|
||||||
|
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
|
||||||
|
_fetchYatInfo();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Color get backgroundDarkColor => Colors.white;
|
void dispose() {
|
||||||
|
super.dispose();
|
||||||
|
_timer?.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Color get titleColor => Palette.darkBlueCraiola;
|
Widget build(BuildContext context) {
|
||||||
|
return WebView(
|
||||||
@override
|
key: _webViewkey,
|
||||||
Widget body(BuildContext context) => WebView(
|
|
||||||
initialUrl: url,
|
initialUrl: url,
|
||||||
javascriptMode: JavascriptMode.unrestricted);
|
javascriptMode: JavascriptMode.unrestricted,
|
||||||
|
onWebViewCreated: (WebViewController controller) =>
|
||||||
|
setState(() => _webViewController = controller));
|
||||||
|
}
|
||||||
|
|
||||||
|
void _fetchYatInfo() {
|
||||||
|
final keyword = 'dashboard';
|
||||||
|
_timer?.cancel();
|
||||||
|
_timer = Timer.periodic(Duration(seconds: 1), (timer) async {
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (_webViewController == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final url = await _webViewController.currentUrl();
|
||||||
|
print('URL = $url');
|
||||||
|
if (url.contains(keyword)) {
|
||||||
|
timer.cancel();
|
||||||
|
await yatViewModel.fetchCartInfo();
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
print(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -4,6 +4,7 @@ import 'package:mobx/mobx.dart';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:cake_wallet/yat/yat_exception.dart';
|
import 'package:cake_wallet/yat/yat_exception.dart';
|
||||||
import 'package:http/http.dart';
|
import 'package:http/http.dart';
|
||||||
|
import 'package:cake_wallet/.secrets.g.dart' as secrets;
|
||||||
|
|
||||||
part 'yat_view_model.g.dart';
|
part 'yat_view_model.g.dart';
|
||||||
|
|
||||||
|
@ -15,23 +16,24 @@ abstract class YatViewModelBase with Store {
|
||||||
final YatStore yatStore;
|
final YatStore yatStore;
|
||||||
|
|
||||||
Future<void> fetchCartInfo() async {
|
Future<void> fetchCartInfo() async {
|
||||||
const _apiKey = ''; // FIXME
|
final url = 'https://a.y.at/cart';
|
||||||
|
final _apiKey = secrets.yatApiToken;
|
||||||
final url = 'https://api.y.at/cart';
|
|
||||||
|
|
||||||
final response = await get(
|
final response = await get(
|
||||||
url,
|
url,
|
||||||
headers: {
|
headers: {
|
||||||
'Accept': '*/*',
|
'Accept':'*/*',
|
||||||
'Authorization,X-Api-Key': _apiKey
|
'X-Api-Key': _apiKey
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.statusCode != 200) {
|
print('RESPONSE = ${response.body.toString()}');
|
||||||
|
|
||||||
|
/*if (response.statusCode != 200) {
|
||||||
throw YatException(text: response.body.toString());
|
throw YatException(text: response.body.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
||||||
yatStore.yatAddress = responseJSON[''] as String; // FIXME
|
yatStore.yatAddress = responseJSON[''] as String;*/ // FIXME
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,24 +3,16 @@ import 'package:cake_wallet/yat/yat_exception.dart';
|
||||||
import 'package:http/http.dart';
|
import 'package:http/http.dart';
|
||||||
|
|
||||||
Future<String> fetchYatAddress(String emojiId) async {
|
Future<String> fetchYatAddress(String emojiId) async {
|
||||||
const _apiKey = ''; // FIXME
|
const _requestURL = 'https://a.y.at/emoji_id/';
|
||||||
const _requestURL = 'https://api.y.at/emoji_id/';
|
|
||||||
|
|
||||||
final url = _requestURL + emojiId;
|
final url = _requestURL + emojiId;
|
||||||
|
final response = await get(url);
|
||||||
final response = await get(
|
|
||||||
url,
|
|
||||||
headers: {
|
|
||||||
'Accept': '*/*',
|
|
||||||
'Authorization': 'Bearer $_apiKey'
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (response.statusCode != 200) {
|
if (response.statusCode != 200) {
|
||||||
throw YatException(text: response.body.toString());
|
throw YatException(text: response.body.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
||||||
final yatAddress = responseJSON[''] as String; // FIXME
|
final yatAddress = responseJSON['result'][2]['data'] as String;
|
||||||
return yatAddress;
|
return yatAddress;
|
||||||
}
|
}
|
Loading…
Reference in a new issue