Skip to content

Commit

Permalink
Merge pull request #2463 from get10101/tradingview-chart
Browse files Browse the repository at this point in the history
Tradingview chart
  • Loading branch information
bonomat authored May 9, 2024
2 parents 02bd2fb + 8d6e9d9 commit d0df781
Show file tree
Hide file tree
Showing 13 changed files with 249 additions and 145 deletions.
8 changes: 4 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ run-local-android args="":
fvm flutter run {{args}} \
--dart-define="COMMIT=$(git rev-parse HEAD)" \
--dart-define="BRANCH=$(git rev-parse --abbrev-ref HEAD)" \
--dart-define="ELECTRS_ENDPOINT=http://${LOCAL_IP}:5050" \
--dart-define="ELECTRS_ENDPOINT=http://${LOCAL_IP}:3000" \
--dart-define="COORDINATOR_P2P_ENDPOINT=02dd6abec97f9a748bf76ad502b004ce05d1b2d1f43a9e76bd7d85e767ffb022c9@${LOCAL_IP}:9045" \
--dart-define="COORDINATOR_PORT_HTTP=8000" \
--dart-define="ORACLE_ENDPOINT=http://${LOCAL_IP}:8081" \
Expand Down Expand Up @@ -204,7 +204,7 @@ wipe: wipe-docker wipe-coordinator wipe-maker wipe-app wipe-webapp
wipe-docker:
#!/usr/bin/env bash
set -euxo pipefail
docker-compose down -v
docker compose down -v
wipe-coordinator:
pkill -9 coordinator && echo "stopped coordinator" || echo "coordinator not running, skipped"
Expand Down Expand Up @@ -335,7 +335,7 @@ xxi-test args="": docker
# Runs background Docker services
docker:
#!/usr/bin/env bash
docker-compose up -d
docker compose up -d
height=$(docker exec bitcoin bitcoin-cli --regtest -rpcuser=admin1 -rpcpassword=123 getblockcount)
height="${height%%[[:cntrl:]]}"
Expand All @@ -347,7 +347,7 @@ docker:
fi

docker-logs:
docker-compose logs
docker compose logs

# Starts coordinator process in the background, piping logs to a file (used in other recipes)
run-coordinator-detached:
Expand Down
8 changes: 8 additions & 0 deletions mobile/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,12 @@
android:name="flutterEmbedding"
android:value="2" />
</application>

<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" />
</intent>
</queries>
</manifest>
3 changes: 2 additions & 1 deletion mobile/lib/common/app_bar_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:get_10101/common/settings/settings_screen.dart';
import 'package:get_10101/features/trade/contract_symbol_icon.dart';
import 'package:get_10101/features/trade/domain/contract_symbol.dart';
import 'package:get_10101/features/trade/trade_screen.dart';
import 'package:get_10101/main.dart';
import 'package:go_router/go_router.dart';

class AppBarWrapper extends StatelessWidget {
Expand All @@ -30,7 +31,7 @@ class AppBarWrapper extends StatelessWidget {
child: AppBar(
centerTitle: true,
elevation: 0,
backgroundColor: const Color(0xFFFAFAFA),
backgroundColor: appBackgroundColor,
iconTheme: const IconThemeData(color: tenTenOnePurple, size: appBarHeight - 8.0),
leading: leadingButton,
title: location == TradeScreen.route
Expand Down
4 changes: 0 additions & 4 deletions mobile/lib/common/init_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:get_10101/common/dlc_channel_service.dart';
import 'package:get_10101/common/domain/dlc_channel.dart';
import 'package:get_10101/common/domain/tentenone_config.dart';
import 'package:get_10101/features/brag/meme_service.dart';
import 'package:get_10101/features/trade/candlestick_change_notifier.dart';
import 'package:get_10101/features/trade/order_change_notifier.dart';
import 'package:get_10101/features/trade/position_change_notifier.dart';
import 'package:get_10101/common/amount_denomination_change_notifier.dart';
Expand All @@ -16,7 +15,6 @@ import 'package:get_10101/features/trade/trade_value_change_notifier.dart';
import 'package:get_10101/features/wallet/application/wallet_service.dart';
import 'package:get_10101/features/wallet/wallet_change_notifier.dart';
import 'package:get_10101/features/trade/submit_order_change_notifier.dart';
import 'package:get_10101/features/trade/application/candlestick_service.dart';
import 'package:get_10101/features/trade/application/order_service.dart';
import 'package:get_10101/features/trade/application/position_service.dart';
import 'package:get_10101/features/trade/application/trade_values_service.dart';
Expand Down Expand Up @@ -53,8 +51,6 @@ List<SingleChildWidget> createProviders() {
ChangeNotifierProvider(create: (context) => OrderChangeNotifier(OrderService())),
ChangeNotifierProvider(create: (context) => PositionChangeNotifier(PositionService())),
ChangeNotifierProvider(create: (context) => WalletChangeNotifier(const WalletService())),
ChangeNotifierProvider(
create: (context) => CandlestickChangeNotifier(const CandlestickService()).initialize()),
ChangeNotifierProvider(create: (context) => ServiceStatusNotifier()),
ChangeNotifierProvider(create: (context) => DlcChannelChangeNotifier(dlcChannelService)),
ChangeNotifierProvider(create: (context) => BackgroundTaskChangeNotifier()),
Expand Down
3 changes: 2 additions & 1 deletion mobile/lib/common/scaffold_with_nav_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:get_10101/common/app_bar_wrapper.dart';
import 'package:get_10101/common/color.dart';
import 'package:get_10101/features/trade/trade_screen.dart';
import 'package:get_10101/features/wallet/wallet_screen.dart';
import 'package:get_10101/main.dart';
import 'package:get_10101/util/constants.dart';
import 'package:go_router/go_router.dart';

Expand All @@ -25,7 +26,7 @@ class ScaffoldWithNavBar extends StatelessWidget {
appBar: const PreferredSize(
preferredSize: Size.fromHeight(40), child: SafeArea(child: AppBarWrapper())),
bottomNavigationBar: BottomNavigationBar(
backgroundColor: const Color(0xFFFAFAFA),
backgroundColor: appBackgroundColor,
selectedItemColor: tenTenOnePurple,
unselectedItemColor: Colors.black,
items: <BottomNavigationBarItem>[
Expand Down
26 changes: 0 additions & 26 deletions mobile/lib/features/trade/application/candlestick_service.dart

This file was deleted.

43 changes: 0 additions & 43 deletions mobile/lib/features/trade/candlestick_change_notifier.dart

This file was deleted.

11 changes: 3 additions & 8 deletions mobile/lib/features/trade/trade_screen.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import 'package:candlesticks/candlesticks.dart';
import 'package:flutter/material.dart';
import 'package:get_10101/common/domain/model.dart';
import 'package:get_10101/features/trade/candlestick_change_notifier.dart';
import 'package:get_10101/features/trade/domain/direction.dart';
import 'package:get_10101/features/trade/domain/order.dart';
import 'package:get_10101/features/trade/domain/position.dart';
Expand All @@ -15,6 +13,7 @@ import 'package:get_10101/features/trade/trade_bottom_sheet_confirmation.dart';
import 'package:get_10101/features/trade/trade_tabs.dart';
import 'package:get_10101/features/trade/trade_theme.dart';
import 'package:get_10101/features/trade/trade_value_change_notifier.dart';
import 'package:get_10101/features/trade/tradingview_candlestick.dart';
import 'package:get_10101/util/constants.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';
Expand All @@ -39,8 +38,6 @@ class TradeScreen extends StatelessWidget {

OrderChangeNotifier orderChangeNotifier = context.watch<OrderChangeNotifier>();
PositionChangeNotifier positionChangeNotifier = context.watch<PositionChangeNotifier>();
CandlestickChangeNotifier candlestickChangeNotifier =
context.watch<CandlestickChangeNotifier>();
TradeValuesChangeNotifier tradeValuesChangeNotifier = context.read<TradeValuesChangeNotifier>();
SubmitOrderChangeNotifier submitOrderChangeNotifier = context.read<SubmitOrderChangeNotifier>();

Expand Down Expand Up @@ -79,14 +76,12 @@ class TradeScreen extends StatelessWidget {
],
),
const SizedBox(height: 5),
Column(
const Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
SizedBox(
height: 250,
child: Candlesticks(
candles: candlestickChangeNotifier.candles,
),
child: TradingViewCandlestick(),
)
],
),
Expand Down
132 changes: 132 additions & 0 deletions mobile/lib/features/trade/tradingview_candlestick.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:get_10101/main.dart';

class TradingViewCandlestick extends StatefulWidget {
const TradingViewCandlestick({
super.key,
});

@override
State<TradingViewCandlestick> createState() => _TradingViewCandlestickState();
}

class _TradingViewCandlestickState extends State<TradingViewCandlestick> {
final GlobalKey webViewKey = GlobalKey();
InAppWebViewController? webViewController;

double progress = 0;

/// place holder if loading fails
late String html = """<html lang="en"><body><p>Tradingview chart not found</p></body></html>""";
// this url doesn't matter, it just has to exist
final baseUrl = WebUri("https://10101.finance/");

static bool enabled() => Platform.isAndroid || Platform.isIOS;

@override
void initState() {
super.initState();

const Color bg = appBackgroundColor;
String rgba = "rgba(${bg.red}, ${bg.green}, ${bg.blue}, ${255.0 / bg.alpha})";
html = '''
<html lang="en">
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
overflow: hidden;
}
html, body, #container, .tradingview-widget-container {
background-color: $rgba;
}
iframe {
height: 100% !important;
}
.tradingview-widget-copyright {
display: none;
}
</style>
</head>
<body>
<div id="container">
<!-- TradingView Widget BEGIN -->
<div class="tradingview-widget-container" style="height:100%;width:100%">
<div class="tradingview-widget-container__widget" style="height:100%;width:100%"></div>
<div class="tradingview-widget-copyright"><a href="https://www.tradingview.com/" rel="noopener nofollow" target="_blank"><span class="blue-text">Track all markets on TradingView</span></a></div>
<script type="text/javascript" src="https://s3.tradingview.com/external-embedding/embed-widget-advanced-chart.js" async>
{
"autosize": true,
"symbol": "BITMEX:XBT",
"interval": "D",
"timezone": "Etc/UTC",
"theme": "light",
"style": "1",
"locale": "en",
"enable_publishing": false,
"backgroundColor": "$rgba",
"hide_top_toolbar": true,
"hide_legend": true,
"allow_symbol_change": false,
"save_image": false,
"calendar": false,
"support_host": "https://www.tradingview.com"
}
</script>
</div>
</div>
<!-- TradingView Widget END -->
</body>
</html>
''';
}

@override
Widget build(BuildContext context) {
return enabled()
? Stack(
children: [
InAppWebView(
key: webViewKey,
onWebViewCreated: (controller) {
webViewController = controller;
webViewController!.loadData(data: html, baseUrl: baseUrl, historyUrl: baseUrl);
},
shouldOverrideUrlLoading: (controller, navigationAction) async {
var uri = navigationAction.request.url!;

if (uri.toString().startsWith("https://www.tradingview.com/chart")) {
// this is the link to the external chart, we want to open this in an external window
if (await canLaunchUrl(uri)) {
// Launch the App
await launchUrl(uri, mode: LaunchMode.externalApplication);
// and cancel the request
return NavigationActionPolicy.CANCEL;
}
}

return NavigationActionPolicy.ALLOW;
},
onProgressChanged: (controller, progress) {
setState(() {
this.progress = progress / 100;
});
},
),
progress < 1.0 ? LinearProgressIndicator(value: progress) : Container(),
],
)
: const Text("Platform not supported");
}
}
4 changes: 3 additions & 1 deletion mobile/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';
import 'package:get_10101/logger/logger.dart';

const Color appBackgroundColor = Color(0xFFFAFAFA);

void main() async {
WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
Expand Down Expand Up @@ -66,7 +68,7 @@ class _TenTenOneAppState extends State<TenTenOneApp> with WidgetsBindingObserver
scaffoldMessengerKey: scaffoldMessengerKey,
theme: ThemeData(
primarySwatch: swatch,
scaffoldBackgroundColor: const Color(0xFFFAFAFA),
scaffoldBackgroundColor: appBackgroundColor,
cardTheme: const CardTheme(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(12.0))),
surfaceTintColor: Colors.white,
Expand Down
Loading

0 comments on commit d0df781

Please sign in to comment.