Skip to content

Commit

Permalink
Merge pull request #37 from Topl/DAPP-427
Browse files Browse the repository at this point in the history
feat(DAPP-427): adds environment variable to site key
  • Loading branch information
Kelello authored Dec 13, 2023
2 parents 2f44686 + bba3dbb commit 2f40969
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
RECAPTCHA_URL="http://localhost:PORT/assets/webpages/index.html?token=";
RECAPTCHA_TOKEN="";
28 changes: 14 additions & 14 deletions assets/webpages/index.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<html lang="en">
<head>
<script>
/// returns the response from the captcha
function callDartCallback(message) {
return grecaptcha.getResponse();
};
/// resets the captcha

function recaptchaExpiredCallback() {
grecaptcha.reset();
};
/// renders the captcha
var captchaCallBack = function () {
grecaptcha.render('html_element', {
'sitekey': '6LecGzwoAAAAAD5_B-a0Zr7YvL_UVpPCyGXfHCuy', // FOR LOCAL TESTING ONLY
'callback': function () {
var response = grecaptcha.getResponse();
},
'expired-callback': recaptchaExpiredCallback,
});
};
</script>
<script src="https://www.google.com/recaptcha/api.js?onload=captchaCallBack&render=explicit" async defer>

function renderCaptcha() {
const urlParams = new URLSearchParams(window.location.search);
const siteKey = urlParams.get('token');
grecaptcha.render('html_element', {
'sitekey': siteKey,
'callback': function () {
var response = grecaptcha.getResponse();
},
'expired-callback': recaptchaExpiredCallback,
});
};
</script>
<script src="https://www.google.com/recaptcha/api.js?onload=renderCaptcha&render=explicit" async defer></script>
</head>
<body>
<div id="html_element"></div>
Expand Down
2 changes: 1 addition & 1 deletion lib/home/sections/custom_webview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class CustomWebview extends HookConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final initialContent = '<div></div>';
const initialContent = '<div></div>';
final isMobile = ResponsiveBreakpoints.of(context).equals(MOBILE);

final webView = ref.watch(webViewProvider);
Expand Down
1 change: 0 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:faucet/shared/providers/app_theme_provider.dart';
import 'package:faucet/shared/theme.dart';
import 'package:flutter/material.dart';
import 'package:hive_flutter/hive_flutter.dart';

import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:vrouter/vrouter.dart';
import 'package:responsive_framework/responsive_framework.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ class WebViewNotifier extends StateNotifier<AsyncValue<WebViewXController<dynami
state = AsyncData(controller);
}

final String RECAPTCHA_URL = const String.fromEnvironment('RECAPTCHA_URL', defaultValue: 'RECAPTCHA_URL');
final String RECAPTCHA_TOKEN = const String.fromEnvironment('RECAPTCHA_TOKEN', defaultValue: 'RECAPTCHA_TOKEN');

loadContent(WebViewXController<dynamic> controller) async {
await controller.loadContent(
'http://localhost:PORT/assets/webpages/index.html',
'{$RECAPTCHA_URL}{$RECAPTCHA_TOKEN}',
SourceType.url,
);
}
Expand Down

0 comments on commit 2f40969

Please sign in to comment.