Skip to content

Commit

Permalink
Merge pull request #1281 from Drakkar-Software/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
GuillaumeDSM authored Jul 5, 2024
2 parents 2395961 + a382ad5 commit f5e7e0b
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Services/Interfaces/web_interface/api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ def display_config():
return util.get_rest_reply(flask.jsonify(message), 200 if success else 500)


@blueprint.route('/hide_announcement<key>', methods=["POST"])
@login.login_required_when_activated
def hide_announcement(key):
models.set_display_announcement(key, False)
return util.get_rest_reply(flask.jsonify(""), 200)


@blueprint.route('/start_copy_trading', methods=["POST"])
@login.login_required_when_activated
def start_copy_trading():
Expand Down
3 changes: 3 additions & 0 deletions Services/Interfaces/web_interface/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@

# data collector
BOT_TOOLS_DATA_COLLECTOR = "data_collector"

PRODUCT_HUNT_ANNOUNCEMENT = "product_hunt_announcement"
PRODUCT_HUNT_ANNOUNCEMENT_DAY = 1720162860 # Wednesday, July 10, 2024 7:01:00 AM UTC
24 changes: 23 additions & 1 deletion Services/Interfaces/web_interface/controllers/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
import time
import flask

import octobot_commons.authentication as authentication
import octobot_services.interfaces.util as interfaces_util
import tentacles.Services.Interfaces.web_interface.login as login
import tentacles.Services.Interfaces.web_interface.models as models
import tentacles.Services.Interfaces.web_interface.flask_util as flask_util
import tentacles.Services.Interfaces.web_interface.constants as web_constants
import octobot.constants as constants
import octobot_commons.constants
import octobot_commons.enums


def register(blueprint):
Expand Down Expand Up @@ -49,6 +53,22 @@ def home():
# no authenticated user: don't display form
user_id = None
display_feedback_form = False
past_launch_time = (
web_constants.PRODUCT_HUNT_ANNOUNCEMENT_DAY
+ (
octobot_commons.enums.TimeFramesMinutes[octobot_commons.enums.TimeFrames.ONE_DAY]
* octobot_commons.constants.MINUTE_TO_SECONDS
)
)
is_launching = (
web_constants.PRODUCT_HUNT_ANNOUNCEMENT_DAY
<= time.time()
<= past_launch_time
)

display_ph_launch = (
models.get_display_announcement(web_constants.PRODUCT_HUNT_ANNOUNCEMENT) or is_launching
) and not time.time() > past_launch_time
return flask.render_template(
'index.html',
has_pnl_history=bool(pnl_symbols),
Expand All @@ -64,7 +84,9 @@ def home():
user_id=user_id,
form_to_display=form_to_display,
display_feedback_form=display_feedback_form,
sandbox_exchanges=sandbox_exchanges
sandbox_exchanges=sandbox_exchanges,
display_ph_launch=display_ph_launch,
is_launching=is_launching,
)
else:
return flask.redirect(flask.url_for("terms"))
4 changes: 4 additions & 0 deletions Services/Interfaces/web_interface/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@
get_display_timeframe,
set_color_mode,
get_color_mode,
set_display_announcement,
get_display_announcement,
get_display_orders,
set_display_timeframe,
set_display_orders,
Expand Down Expand Up @@ -392,6 +394,8 @@
"get_display_timeframe",
"set_color_mode",
"get_color_mode",
"set_display_announcement",
"get_display_announcement",
"get_display_orders",
"set_display_timeframe",
"set_display_orders",
Expand Down
21 changes: 21 additions & 0 deletions Services/Interfaces/web_interface/models/interface_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,27 @@ def set_color_mode(color_mode: str):
return _save_edition()


def set_display_announcement(key: str, display: bool):
try:
get_web_interface_config()[
web_interface.WebInterface.ANNOUNCEMENTS
][key] = display
except KeyError:
get_web_interface_config()[
web_interface.WebInterface.ANNOUNCEMENTS
] = {key: display}
return _save_edition()


def get_display_announcement(key: str) -> bool:
try:
return get_web_interface_config()[
web_interface.WebInterface.ANNOUNCEMENTS
][key]
except KeyError:
return True


def get_color_mode() -> web_enums.ColorModes:
return web_enums.ColorModes(get_web_interface_config().get(
web_interface.WebInterface.COLOR_MODE, web_enums.ColorModes.DEFAULT.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
*/

$(document).ready(function () {
const handleAnnouncementsHide = () => {
$("button[data-role=\"hide-announcement\"]").click(async (event) => {
const source = $(event.currentTarget);
const url = source.data("url");
await async_send_and_interpret_bot_update(undefined, url);
})
}

function _refresh_profitability(socket) {
socket.emit('profitability');
waiting_profitability_update = false;
Expand Down Expand Up @@ -265,6 +273,7 @@ $(document).ready(function () {
init_dashboard_websocket();
init_graphs();
registerConfigUpdates();
handleAnnouncementsHide();
if(!startTutorialIfNecessary("home", displayFeedbackFormIfNecessary)){
displayFeedbackFormIfNecessary()
}
Expand Down
20 changes: 20 additions & 0 deletions Services/Interfaces/web_interface/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,26 @@
{% block body %}
<br>
<div update-url="{{ url_for('api.announcements') }}" class="alert alert-danger text-center d-none" role="alert" id="annoncementsAlert"></div>

{% if display_ph_launch %}
<div class="alert alert-primary text-center" role="alert">
<h5 class="">
🎉 Major news! OctoBot is launching on Product Hunt {{'today' if is_launching else 'on the 10th of July'}}.
{% if not is_launching %}
<button type="button" class="close" data-dismiss="alert" aria-label="Close" data-role="hide-announcement" data-url="{{url_for('api.hide_announcement', key='product_hunt_announcement')}}">
<span aria-hidden="true">&times;</span>
</button>
{% endif %}
</h5>
<p class="text-center pt-3 mb-0">
<a href="https://www.producthunt.com/posts/octobot-open-source?embed=true&utm_source=badge-featured&utm_medium=badge&utm_souce=badge-octobot&#0045;open&#0045;source" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=463219&theme={{get_color_mode()}}" alt="OctoBot&#0032;open&#0032;source - Your&#0032;open&#0032;source&#0032;investment&#0032;strategy&#0032;builder | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>

</p>
<p class="text-center pt-3 mb-0">
Follow the launch to get your exclusive discount.
</p>
</div>
{% endif %}
{% if not IS_CLOUD %}
<div class="d-none alert alert-success text-center my-2" role="alert">
<h5 class="d-none d-sm-inline"><span class="d-none d-md-inline"><i class="far fa-bell"></i> Good news ! </span>OctoBot version <span update-url="{{ url_for('api.upgrade_version') }}" id="upgradeVersion"></span> is available.</h5><button route="{{ url_for('commands', cmd='update') }}" type="button" class="btn btn-warning waves-effect">Upgrade now <i class="fas fa-cloud-download-alt"></i></button>
Expand Down
1 change: 1 addition & 0 deletions Services/Interfaces/web_interface/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class WebInterface(services_interfaces.AbstractWebInterface):

REQUIRED_SERVICES = [Service_bases.WebService]
COLOR_MODE = "color_mode"
ANNOUNCEMENTS = "announcements"
DISPLAY_TIME_FRAME = "display_time_frame"
DISPLAY_ORDERS = "display_orders"
WATCHED_SYMBOLS = "watched_symbols"
Expand Down

0 comments on commit f5e7e0b

Please sign in to comment.