Skip to content

Commit

Permalink
more ui polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
x86y committed Mar 17, 2024
1 parent 0217ee1 commit 0885ee5
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 61 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ A cross-platform native desktop application for trading cryptocurrency. Only Bin
To use set DYN_PUB and DYN_SEC environment variables to your Binance API keys respectively.

## updated visuals, no gif yet:
![CleanShot 2023-09-16 at 20 04 26](assets/new.png)
![CleanShot 2023-09-16 at 20 04 26](assets/demo.png)

## old ui, animated
![CleanShot 2023-09-16 at 20 04 26](https://github.com/x86y/dynasty/assets/68605763/881a390d-62e2-443e-823e-fd4d8d6db3fc)
Expand Down
Binary file added assets/demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/new.png
Binary file not shown.
45 changes: 45 additions & 0 deletions scripts/macos
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

TARGET="dynasty"
ASSETS_DIR="assets"
RELEASE_DIR="target/release"
APP_NAME="Dynasty.app"
APP_TEMPLATE="$ASSETS_DIR/macos/$APP_NAME"
APP_TEMPLATE_PLIST="$APP_TEMPLATE/Contents/Info.plist"
APP_DIR="$RELEASE_DIR/macos"
APP_BINARY="$RELEASE_DIR/$TARGET"
APP_BINARY_DIR="$APP_DIR/$APP_NAME/Contents/MacOS"
APP_EXTRAS_DIR="$APP_DIR/$APP_NAME/Contents/Resources"

DMG_NAME="dynasty.dmg"
DMG_DIR="$RELEASE_DIR/macos"

VERSION="0.1.0"
BUILD=$(git describe --always --dirty --exclude='*')

# update version and build
sed -i '' -e "s/{{ VERSION }}/$VERSION/g" "$APP_TEMPLATE_PLIST"
sed -i '' -e "s/{{ BUILD }}/$BUILD/g" "$APP_TEMPLATE_PLIST"

# build binary
export MACOSX_DEPLOYMENT_TARGET="11.0"
rustup target add x86_64-apple-darwin
rustup target add aarch64-apple-darwin
cargo build --release --target=x86_64-apple-darwin
cargo build --release --target=aarch64-apple-darwin
lipo "target/x86_64-apple-darwin/release/$TARGET" "target/aarch64-apple-darwin/release/$TARGET" -create -output "$APP_BINARY"

# build app
mkdir -p "$APP_BINARY_DIR"
mkdir -p "$APP_EXTRAS_DIR"
cp -fRp "$APP_TEMPLATE" "$APP_DIR"
cp -fp "$APP_BINARY" "$APP_BINARY_DIR"
touch -r "$APP_BINARY" "$APP_DIR/$APP_NAME"
echo "Created '$APP_NAME' in '$APP_DIR'"

# package dmg
echo "Packing disk image..."
ln -sf /Applications "$DMG_DIR/Applications"
hdiutil create "$DMG_DIR/$DMG_NAME" -volname "Dynasty" -fs HFS+ -srcfolder "$APP_DIR" -ov -format UDZO
echo "Packed '$APP_NAME' in '$APP_DIR'"

53 changes: 31 additions & 22 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,38 @@ lazy_static! {
pub async fn orders_history() -> Vec<Order> {
let now = chrono::offset::Local::now();
let ago = now.checked_sub_signed(chrono::Duration::weeks(8)).unwrap();
let assets = ["LINKUSDT", "UNIUSDT", "1INCHUSDT", "OPUSDT", "ARBUSDT", "SYNUSDT"];
let mut os: Vec<Order> = join_all(assets.iter().map(async move |a| {
match B
.get_all_orders(binance::account::OrdersQuery {
symbol: a.to_string(),
order_id: None,
start_time: Some(ago.timestamp_millis() as u64),
end_time: None,
limit: None,
recv_window: None,
})
.await
{
Ok(r) => r,
Err(_e) => {
vec![]
let assets =
[
"LINKUSDT",
"UNIUSDT",
"1INCHUSDT",
"OPUSDT",
"ARBUSDT",
"SYNUSDT",
];
let mut os: Vec<Order> =
join_all(assets.iter().map(async move |a| {
match B
.get_all_orders(binance::account::OrdersQuery {
symbol: a.to_string(),
order_id: None,
start_time: Some(ago.timestamp_millis() as u64),
end_time: None,
limit: None,
recv_window: None,
})
.await
{
Ok(r) => r,
Err(_e) => {
vec![]
}
}
}
}))
.await
.into_iter()
.flatten()
.collect();
}))
.await
.into_iter()
.flatten()
.collect();
os.sort_by(|o, n| n.time.cmp(&o.time));
os
}
Expand Down
10 changes: 6 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,17 +534,19 @@ impl Application for App {
let svg = svg(handle)
.width(Length::Fixed(16.0))
.height(Length::Fixed(16.0));
return row![svg, text(price_now)]
return row![svg, text(format!("{:.2}", price_now))]
.spacing(4)
.align_items(iced::Alignment::Center);
})
.map(Element::from)
)
.spacing(8),
.spacing(12),
Space::new(Length::Fill, 1),
button("⚙").padding(8).style(iced::theme::Button::Text)
button("Settings")
.padding(8)
.style(iced::theme::Button::Text)
]
.spacing(8);
.align_items(iced::Alignment::Center);
let message_log: Element<_> = if self.data.prices.is_empty() {
container(text("Loading...").style(Color::from_rgb8(0x88, 0x88, 0x88)))
.width(Length::Fill)
Expand Down
21 changes: 18 additions & 3 deletions src/views/components/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ impl text_input::StyleSheet for Inp {
border: iced::Border {
radius: 0.0.into(),
width: 1.0,
color: Color { r: 0.0, g: 0.0, b: 0.0, a: 0.3, },
color: Color {
r: 0.0,
g: 0.0,
b: 0.0,
a: 0.3,
},
},
icon_color: Default::default(),
}
Expand All @@ -23,7 +28,12 @@ impl text_input::StyleSheet for Inp {
border: iced::Border {
radius: 0.0.into(),
width: 1.0,
color: Color { a: 0.5, r: 0.5, g: 0.5, b: 0.5, },
color: Color {
a: 0.5,
r: 0.5,
g: 0.5,
b: 0.5,
},
},
icon_color: Default::default(),
}
Expand Down Expand Up @@ -51,7 +61,12 @@ impl text_input::StyleSheet for Inp {
border: iced::Border {
radius: 0.0.into(),
width: 1.0,
color: Color { a: 0.5, r: 0.5, g: 0.5, b: 0.5, },
color: Color {
a: 0.5,
r: 0.5,
g: 0.5,
b: 0.5,
},
},
icon_color: Default::default(),
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/components/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod better_btn;
pub mod input;
pub mod scrollbar;
pub mod list;
pub mod scrollbar;
pub mod unstyled_btn;
2 changes: 1 addition & 1 deletion src/views/panes/balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;

use binance::rest_model::Balance;
use iced::{
widget::{button, column, container, row, scrollable, svg, text, Column, Space},
widget::{button, container, row, scrollable, svg, text, Column, Space},
Element, Length,
};

Expand Down
25 changes: 12 additions & 13 deletions src/views/panes/book.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn book_view(
let ask_rows = Column::with_children(
book.1
.iter()
.take(10)
.take(9)
.map(|(price, quantity)| {
row![
t(format!("{:.2}", price.parse::<f64>().unwrap()))
Expand All @@ -45,7 +45,7 @@ pub fn book_view(
book.2
.iter()
.rev()
.take(10)
.take(9)
.map(|(price, quantity)| {
row![
t(format!("{:.2}", price.parse::<f64>().unwrap()))
Expand All @@ -63,17 +63,16 @@ pub fn book_view(
.map(Element::from),
);

let content = column![
header,
ask_rows,
Rule::horizontal(1),
t(format!("${}", book.1.iter().next_back().unwrap().0)),
Rule::horizontal(1),
bid_rows,
]
.padding(12)
.spacing(10)
.max_width(500);
let content =
column![
header,
ask_rows,
t(format!("${}", book.1.iter().next_back().unwrap().0)),
bid_rows,
]
.padding(12)
.spacing(10)
.max_width(500);

Container::new(scrollable(content)).into()
}
4 changes: 1 addition & 3 deletions src/views/panes/market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ use crate::Message;

macro_rules! bbtn {
($e: expr) => {
button($e)
.style(iced::theme::Button::Text)
.padding(8)
button($e).style(iced::theme::Button::Text).padding(8)
};
}

Expand Down
5 changes: 4 additions & 1 deletion src/views/panes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ pub mod style {
container::Appearance {
text_color: Some(palette.primary.strong.text),
background: Some(iced::Background::Color(Color::from_rgb(0.07, 0.07, 0.07))),
border: iced::Border { radius: 16.0.into(), ..Default::default() },
border: iced::Border {
radius: 16.0.into(),
..Default::default()
},
..Default::default()
}
}
Expand Down
24 changes: 18 additions & 6 deletions src/views/panes/watchlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,25 @@ pub fn watchlist_view<'a>(
})
.map(|(n, p)| {
container(row![
button(text(n).style(h2c("EFE1D1").unwrap()))
.on_press(Message::AssetSelected(n.to_string()))
.style(iced::theme::Button::Custom(Box::new(UnstyledBtn {}))),
button(
text(n)
.font(iced::Font {
weight: iced::font::Weight::Bold,
..Default::default()
})
.size(14)
.style(h2c("EFE1D1").unwrap())
)
.on_press(Message::AssetSelected(n.to_string()))
.style(iced::theme::Button::Custom(Box::new(UnstyledBtn {}))),
Space::new(Length::Fill, 1.0),
button(text(format!["{p} "]).style(h2c("B7BDB76").unwrap()))
.on_press(Message::AssetSelected(n.to_string()))
.style(iced::theme::Button::Custom(Box::new(UnstyledBtn {}))),
button(
text(format!["{p} "])
.size(14)
.style(h2c("B7BDB76").unwrap())
)
.on_press(Message::AssetSelected(n.to_string()))
.style(iced::theme::Button::Custom(Box::new(UnstyledBtn {}))),
])
.width(Length::Fill)
})
Expand Down
10 changes: 4 additions & 6 deletions src/ws/util.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pub mod m {
macro_rules! con {
($event:ty, $stream:expr, $connect_expr:expr, $process_msg:expr) => {
use iced::subscription::{self, Subscription};
use iced_futures::futures;
use futures::sink::SinkExt;
use futures::FutureExt;
use iced::subscription::{self, Subscription};
use iced_futures::futures;
use std::sync::atomic::AtomicBool;
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};

Expand All @@ -16,10 +16,8 @@ pub mod m {
100,
|mut output| async move {
let keep_running = AtomicBool::new(true);
let (s, mut r): (
UnboundedSender<$event>,
UnboundedReceiver<$event>,
) = unbounded_channel();
let (s, mut r): (UnboundedSender<$event>, UnboundedReceiver<$event>) =
unbounded_channel();

let mut web_socket_connection = $connect_expr();

Expand Down

0 comments on commit 0885ee5

Please sign in to comment.