Skip to content

Commit

Permalink
Update Branch to null safety
Browse files Browse the repository at this point in the history
Add deep linking to iOS
  • Loading branch information
OmarHatem28 committed Nov 8, 2022
1 parent 7c7de65 commit f078457
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 36 deletions.
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifestBase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
android:scheme="cakewallet"
android:host="y.at" />
</intent-filter>
<!-- bitcoin qr code scheme -->
<!-- currencies qr code scheme -->
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
Expand Down
54 changes: 42 additions & 12 deletions ios/Runner/InfoBase.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,48 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>y.at</string>
<key>CFBundleURLSchemes</key>
<array>
<string>cakewallet</string>
</array>
</dict>
</array>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>y.at</string>
<key>CFBundleURLSchemes</key>
<array>
<string>cakewallet</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>bitcoin</string>
<key>CFBundleURLSchemes</key>
<array>
<string>bitcoin</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>monero</string>
<key>CFBundleURLSchemes</key>
<array>
<string>monero</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>litecoin</string>
<key>CFBundleURLSchemes</key>
<array>
<string>litecoin</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSRequiresIPhoneOS</key>
Expand Down
4 changes: 2 additions & 2 deletions lib/di.dart
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ Future setup(
getIt.get<BalanceViewModel>(),
_transactionDescriptionBox));

getIt.registerFactoryParam<SendPage, PaymentRequest, void>(
(PaymentRequest initialPaymentRequest, _) => SendPage(
getIt.registerFactoryParam<SendPage, PaymentRequest?, void>(
(PaymentRequest? initialPaymentRequest, _) => SendPage(
sendViewModel: getIt.get<SendViewModel>(),
settingsViewModel: getIt.get<SettingsViewModel>(),
initialPaymentRequest: initialPaymentRequest,
Expand Down
29 changes: 19 additions & 10 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import 'package:cw_core/unspent_coins_info.dart';
import 'package:cake_wallet/monero/monero.dart';
import 'package:cake_wallet/wallet_type_utils.dart';

import 'src/screens/auth/auth_page.dart';

final navigatorKey = GlobalKey<NavigatorState>();
final rootKey = GlobalKey<RootState>();

Expand Down Expand Up @@ -213,30 +215,37 @@ class AppState extends State<App> with SingleTickerProviderStateMixin {
super.dispose();
}

/// handle app links while the app is already started - be it in
/// the foreground or in the background.
/// handle app links while the app is already started
/// whether its in the foreground or in the background.
Future<void> initUniLinks() async {
try {
stream = getUriLinksStream().listen((Uri uri) {
stream = uriLinkStream.listen((Uri? uri) {
handleDeepLinking(uri);
});

final Uri initialUri = await getInitialUri();
final Uri? initialUri = await getInitialUri();

handleDeepLinking(initialUri);
} catch (e) {
print(e);
}
}

void handleDeepLinking(Uri uri) {
void handleDeepLinking(Uri? uri) {
if (uri == null || !mounted) return;

Navigator.pushNamed(
navigatorKey.currentContext,
Routes.send,
arguments: PaymentRequest.fromUri(uri),
);
Navigator.of(navigatorKey.currentContext!).pushNamed(Routes.auth,
arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) {
if (isAuthenticatedSuccessfully) {
auth.close(route: Routes.send, arguments: PaymentRequest.fromUri(uri));
}
});

// Navigator.pushNamed(
// navigatorKey.currentContext!,
// Routes.send,
// arguments: PaymentRequest.fromUri(uri),
// );
}

Future<void> _handleInitialUri() async {
Expand Down
2 changes: 1 addition & 1 deletion lib/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ Route<dynamic> createRoute(RouteSettings settings) {
builder: (_) => getIt.get<DashboardPage>());

case Routes.send:
final initialPaymentRequest = settings.arguments as PaymentRequest;
final initialPaymentRequest = settings.arguments as PaymentRequest?;

return CupertinoPageRoute<void>(
fullscreenDialog: true, builder: (_) => getIt.get<SendPage>(
Expand Down
9 changes: 4 additions & 5 deletions lib/src/screens/send/widgets/send_card.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'dart:ui';
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
import 'package:cake_wallet/utils/payment_request.dart';
import 'package:cw_core/transaction_priority.dart';
Expand Down Expand Up @@ -44,7 +43,7 @@ class SendCardState extends State<SendCard>
required this.output,
required this.sendViewModel,
this.initialPaymentRequest})
: addressController = TextEditingController(text: initialPaymentRequest?.address?.toLowerCase()),
: addressController = TextEditingController(text: initialPaymentRequest?.address.toLowerCase()),
cryptoAmountController = TextEditingController(text: initialPaymentRequest?.amount),
fiatAmountController = TextEditingController(),
noteController = TextEditingController(),
Expand Down Expand Up @@ -77,8 +76,8 @@ class SendCardState extends State<SendCard>

/// if the current wallet doesn't match the one in the qr code
if (initialPaymentRequest != null &&
sendViewModel.walletCurrencyName != initialPaymentRequest.scheme?.toLowerCase()) {
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
sendViewModel.walletCurrencyName != initialPaymentRequest!.scheme.toLowerCase()) {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
showPopUp<void>(
context: context,
builder: (BuildContext context) {
Expand Down Expand Up @@ -544,7 +543,7 @@ class SendCardState extends State<SendCard>
addressController.text = output.address;
}
if (output.cryptoAmount.isNotEmpty ||
sendViewModel.walletCurrencyName != initialPaymentRequest?.scheme?.toLowerCase()) {
sendViewModel.walletCurrencyName != initialPaymentRequest?.scheme.toLowerCase()) {
cryptoAmountController.text = output.cryptoAmount;
}
fiatAmountController.text = output.fiatAmount;
Expand Down
6 changes: 3 additions & 3 deletions lib/utils/payment_request.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class PaymentRequest {
PaymentRequest(this.address, this.amount, this.note, {this.scheme});
PaymentRequest(this.address, this.amount, this.note, this.scheme);

factory PaymentRequest.fromUri(Uri uri) {
factory PaymentRequest.fromUri(Uri? uri) {
var address = "";
var amount = "";
var note = "";
Expand All @@ -15,7 +15,7 @@ class PaymentRequest {
scheme = uri.scheme;
}

return PaymentRequest(address, amount, note, scheme: scheme);
return PaymentRequest(address, amount, note, scheme);
}

final String address;
Expand Down
4 changes: 2 additions & 2 deletions lib/view_model/send/send_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ abstract class SendViewModelBase with Store {
PendingTransaction? pendingTransaction;

@computed
String get balance => balanceViewModel.availableBalance ?? '0.0';
String get balance => balanceViewModel.availableBalance;

@computed
bool get isReadyForSend => _wallet.syncStatus is SyncedSyncStatus;
Expand All @@ -164,7 +164,7 @@ abstract class SendViewModelBase with Store {

WalletType get walletType => _wallet.type;

String get walletCurrencyName => _wallet.currency.name.toLowerCase();
String? get walletCurrencyName => _wallet.currency.name?.toLowerCase();

bool get hasCurrecyChanger => walletType == WalletType.haven;

Expand Down

0 comments on commit f078457

Please sign in to comment.