Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unstoppable domains fix #1600

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,4 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.unstoppabledomains:resolution:5.0.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@
import android.os.PowerManager;
import android.provider.Settings;

import com.unstoppabledomains.resolution.DomainResolution;
import com.unstoppabledomains.resolution.Resolution;

import java.security.SecureRandom;

public class MainActivity extends FlutterFragmentActivity {
final String UTILS_CHANNEL = "com.cake_wallet/native_utils";
final int UNSTOPPABLE_DOMAIN_MIN_VERSION_SDK = 24;
boolean isAppSecure = false;

@Override
Expand All @@ -53,14 +49,6 @@ private void handle(@NonNull MethodCall call, @NonNull MethodChannel.Result resu
random.nextBytes(bytes);
handler.post(() -> result.success(bytes));
break;
case "getUnstoppableDomainAddress":
int version = Build.VERSION.SDK_INT;
if (version >= UNSTOPPABLE_DOMAIN_MIN_VERSION_SDK) {
getUnstoppableDomainAddress(call, result);
} else {
handler.post(() -> result.success(""));
}
break;
case "setIsAppSecure":
isAppSecure = call.argument("isAppSecure");
if (isAppSecure) {
Expand All @@ -85,23 +73,6 @@ private void handle(@NonNull MethodCall call, @NonNull MethodChannel.Result resu
}
}

private void getUnstoppableDomainAddress(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
DomainResolution resolution = new Resolution();
Handler handler = new Handler(Looper.getMainLooper());
String domain = call.argument("domain");
String ticker = call.argument("ticker");

AsyncTask.execute(() -> {
try {
String address = resolution.getAddress(domain, ticker);
handler.post(() -> result.success(address));
} catch (Exception e) {
System.out.println("Expected Address, but got " + e.getMessage());
handler.post(() -> result.success(""));
}
});
}

private void disableBatteryOptimization() {
String packageName = getPackageName();
PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
Expand Down
29 changes: 0 additions & 29 deletions android/app/src/main/java/com/cakewallet/haven/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@
import android.os.PowerManager;
import android.provider.Settings;

import com.unstoppabledomains.resolution.DomainResolution;
import com.unstoppabledomains.resolution.Resolution;

import java.security.SecureRandom;

public class MainActivity extends FlutterFragmentActivity {
final String UTILS_CHANNEL = "com.cake_wallet/native_utils";
final int UNSTOPPABLE_DOMAIN_MIN_VERSION_SDK = 24;

@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
Expand All @@ -51,14 +47,6 @@ private void handle(@NonNull MethodCall call, @NonNull MethodChannel.Result resu
random.nextBytes(bytes);
handler.post(() -> result.success(bytes));
break;
case "getUnstoppableDomainAddress":
int version = Build.VERSION.SDK_INT;
if (version >= UNSTOPPABLE_DOMAIN_MIN_VERSION_SDK) {
getUnstoppableDomainAddress(call, result);
} else {
handler.post(() -> result.success(""));
}
break;
case "disableBatteryOptimization":
disableBatteryOptimization();
handler.post(() -> result.success(null));
Expand All @@ -75,23 +63,6 @@ private void handle(@NonNull MethodCall call, @NonNull MethodChannel.Result resu
}
}

private void getUnstoppableDomainAddress(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
DomainResolution resolution = new Resolution();
Handler handler = new Handler(Looper.getMainLooper());
String domain = call.argument("domain");
String ticker = call.argument("ticker");

AsyncTask.execute(() -> {
try {
String address = resolution.getAddress(domain, ticker);
handler.post(() -> result.success(address));
} catch (Exception e) {
System.out.println("Expected Address, but got " + e.getMessage());
handler.post(() -> result.success(""));
}
});
}

private void disableBatteryOptimization() {
String packageName = getPackageName();
PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
Expand Down
29 changes: 0 additions & 29 deletions android/app/src/main/java/com/monero/app/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@
import android.os.PowerManager;
import android.provider.Settings;

import com.unstoppabledomains.resolution.DomainResolution;
import com.unstoppabledomains.resolution.Resolution;

import java.security.SecureRandom;

public class MainActivity extends FlutterFragmentActivity {
final String UTILS_CHANNEL = "com.cake_wallet/native_utils";
final int UNSTOPPABLE_DOMAIN_MIN_VERSION_SDK = 24;
boolean isAppSecure = false;

@Override
Expand All @@ -52,14 +48,6 @@ private void handle(@NonNull MethodCall call, @NonNull MethodChannel.Result resu
random.nextBytes(bytes);
handler.post(() -> result.success(bytes));
break;
case "getUnstoppableDomainAddress":
int version = Build.VERSION.SDK_INT;
if (version >= UNSTOPPABLE_DOMAIN_MIN_VERSION_SDK) {
getUnstoppableDomainAddress(call, result);
} else {
handler.post(() -> result.success(""));
}
break;
case "setIsAppSecure":
isAppSecure = call.argument("isAppSecure");
if (isAppSecure) {
Expand All @@ -84,23 +72,6 @@ private void handle(@NonNull MethodCall call, @NonNull MethodChannel.Result resu
}
}

private void getUnstoppableDomainAddress(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
DomainResolution resolution = new Resolution();
Handler handler = new Handler(Looper.getMainLooper());
String domain = call.argument("domain");
String ticker = call.argument("ticker");

AsyncTask.execute(() -> {
try {
String address = resolution.getAddress(domain, ticker);
handler.post(() -> result.success(address));
} catch (Exception e) {
System.out.println("Expected Address, but got " + e.getMessage());
handler.post(() -> result.success(""));
}
});
}

private void disableBatteryOptimization() {
String packageName = getPackageName();
PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
Expand Down
1 change: 0 additions & 1 deletion ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ target 'Runner' do

# Cake Wallet (Legacy)
pod 'CryptoSwift'
pod 'UnstoppableDomainsResolution', '~> 4.0.0'
end

post_install do |installer|
Expand Down
23 changes: 1 addition & 22 deletions ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import UIKit
import Flutter
import UnstoppableDomainsResolution
import workmanager

@UIApplicationMain
Expand Down Expand Up @@ -87,27 +86,7 @@ import workmanager
}

result(secRandom(count: count))
case "getUnstoppableDomainAddress":
guard let args = call.arguments as? Dictionary<String, String>,
let domain = args["domain"],
let ticker = args["ticker"],
let resolution = self?.resolution else {
result(nil)
return
}

resolution.addr(domain: domain, ticker: ticker) { addrResult in
var address : String = ""

switch addrResult {
case .success(let returnValue):
address = returnValue
case .failure(let error):
print("Expected Address, but got \(error)")
}

result(address)
}

case "setIsAppSecure":
guard let args = call.arguments as? Dictionary<String, Bool>,
let isAppSecure = args["isAppSecure"] else {
Expand Down
27 changes: 15 additions & 12 deletions lib/entities/unstoppable_domain_address.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import 'package:cake_wallet/utils/device_info.dart';
import 'dart:convert';

import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;

const channel = MethodChannel('com.cake_wallet/native_utils');

Future<String> fetchUnstoppableDomainAddress(String domain, String ticker) async {
var address = '';

try {
if (DeviceInfo.instance.isMobile) {
address = await channel.invokeMethod<String>(
'getUnstoppableDomainAddress',
<String, String> {
'domain' : domain,
'ticker' : ticker
}
) ?? '';
} else {
// TODO: Integrate with Unstoppable domains resolution API
return address;
final uri = Uri.parse("https://api.unstoppabledomains.com/profile/public/${Uri.encodeQueryComponent(domain)}?fields=records");
final jsonString = await http.read(uri);
final jsonParsed = json.decode(jsonString) as Map<String, dynamic>;
if (jsonParsed["records"] == null) {
throw Exception(".records response from $uri is empty");
};
final records = jsonParsed["records"] as Map<String, dynamic>;
final key = "crypto.${ticker.toUpperCase()}.address";
if (records[key] == null) {
throw Exception(".records.${key} response from $uri is empty");
}

return records[key] as String? ?? '';
} catch (e) {
print('Unstoppable domain error: ${e.toString()}');
address = '';
Expand Down
Loading