mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-03 17:40:43 +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/parsed_address.dart';
|
||||
import 'package:cake_wallet/entities/unstoppable_domain_address.dart';
|
||||
import 'package:cake_wallet/yat/yat_record.dart';
|
||||
|
||||
const unstoppableDomains = [
|
||||
'crypto',
|
||||
|
@ -22,7 +23,20 @@ Future<ParsedAddress> parseAddressFromDomain(
|
|||
final name = domainParts.last;
|
||||
|
||||
if (domainParts.length <= 1 || domainParts.first.isEmpty || name.isEmpty) {
|
||||
return ParsedAddress(address: domain);
|
||||
try {
|
||||
final address = await fetchYatAddress(domain);
|
||||
|
||||
if (address?.isEmpty ?? true) {
|
||||
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))) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
enum ParseFrom {unstoppableDomains, openAlias, notParsed}
|
||||
enum ParseFrom {unstoppableDomains, openAlias, yatRecord, notParsed}
|
||||
|
||||
class ParsedAddress {
|
||||
ParsedAddress({
|
||||
|
|
|
@ -17,6 +17,10 @@ void showAddressAlert(BuildContext context, ParsedAddress parsedAddress) async {
|
|||
title = S.of(context).openalias_alert_title;
|
||||
content = S.of(context).openalias_alert_content(parsedAddress.name);
|
||||
break;
|
||||
case ParseFrom.yatRecord:
|
||||
title = 'Address detected';
|
||||
content = 'This address is from ${parsedAddress.name} on Yat';
|
||||
break;
|
||||
case ParseFrom.notParsed:
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:cake_wallet/palette.dart';
|
||||
import 'package:cake_wallet/src/screens/base_page.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}
|
||||
|
||||
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) {
|
||||
case YatMode.create:
|
||||
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 _createSuffix = '/create';
|
||||
|
||||
|
@ -28,18 +60,53 @@ class YatWebViewPage extends BasePage {
|
|||
final YatViewModel yatViewModel;
|
||||
|
||||
String url;
|
||||
WebViewController _webViewController;
|
||||
GlobalKey _webViewkey;
|
||||
Timer _timer;
|
||||
|
||||
@override
|
||||
String get title => 'Yat';
|
||||
void initState() {
|
||||
super.initState();
|
||||
_webViewkey = GlobalKey();
|
||||
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
|
||||
_fetchYatInfo();
|
||||
}
|
||||
|
||||
@override
|
||||
Color get backgroundDarkColor => Colors.white;
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
_timer?.cancel();
|
||||
}
|
||||
|
||||
@override
|
||||
Color get titleColor => Palette.darkBlueCraiola;
|
||||
Widget build(BuildContext context) {
|
||||
return WebView(
|
||||
key: _webViewkey,
|
||||
initialUrl: url,
|
||||
javascriptMode: JavascriptMode.unrestricted,
|
||||
onWebViewCreated: (WebViewController controller) =>
|
||||
setState(() => _webViewController = controller));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget body(BuildContext context) => WebView(
|
||||
initialUrl: url,
|
||||
javascriptMode: JavascriptMode.unrestricted);
|
||||
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 'package:cake_wallet/yat/yat_exception.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:cake_wallet/.secrets.g.dart' as secrets;
|
||||
|
||||
part 'yat_view_model.g.dart';
|
||||
|
||||
|
@ -15,23 +16,24 @@ abstract class YatViewModelBase with Store {
|
|||
final YatStore yatStore;
|
||||
|
||||
Future<void> fetchCartInfo() async {
|
||||
const _apiKey = ''; // FIXME
|
||||
|
||||
final url = 'https://api.y.at/cart';
|
||||
final url = 'https://a.y.at/cart';
|
||||
final _apiKey = secrets.yatApiToken;
|
||||
|
||||
final response = await get(
|
||||
url,
|
||||
headers: {
|
||||
'Accept': '*/*',
|
||||
'Authorization,X-Api-Key': _apiKey
|
||||
'Accept':'*/*',
|
||||
'X-Api-Key': _apiKey
|
||||
}
|
||||
);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
print('RESPONSE = ${response.body.toString()}');
|
||||
|
||||
/*if (response.statusCode != 200) {
|
||||
throw YatException(text: response.body.toString());
|
||||
}
|
||||
|
||||
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';
|
||||
|
||||
Future<String> fetchYatAddress(String emojiId) async {
|
||||
const _apiKey = ''; // FIXME
|
||||
const _requestURL = 'https://api.y.at/emoji_id/';
|
||||
const _requestURL = 'https://a.y.at/emoji_id/';
|
||||
|
||||
final url = _requestURL + emojiId;
|
||||
|
||||
final response = await get(
|
||||
url,
|
||||
headers: {
|
||||
'Accept': '*/*',
|
||||
'Authorization': 'Bearer $_apiKey'
|
||||
}
|
||||
);
|
||||
final response = await get(url);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw YatException(text: response.body.toString());
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
Loading…
Reference in a new issue