Skip to content

Commit

Permalink
[*] improve ui
Browse files Browse the repository at this point in the history
  • Loading branch information
heng30 committed Jul 5, 2024
1 parent eb7ad1c commit 7796a82
Show file tree
Hide file tree
Showing 18 changed files with 252 additions and 75 deletions.
66 changes: 66 additions & 0 deletions '
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Theme, Icons } from "../../theme.slint";
import { Store } from "../../store.slint";
import { Logic } from "../../logic.slint";
import { Util } from "../../util.slint";
import { OkCancelDialogSetting, IconBtn, Head, Label, Tag, Link, NoDataImg, NoMessageImg, CenterLayout } from "../../base/widgets.slint";
import { Theme } from "../../theme.slint";
import { TestModeBanner } from "test-mode-banner.slint";


component TopHead inherits Head {
icon: Icons.recipient;
title: Logic.tr(Store.is-cn, "接收");
hbox-alignment: LayoutAlignment.start;
}

component Body inherits Rectangle {
VerticalLayout {
alignment: center;
spacing: Theme.spacing * 2;

CenterLayout {
Image {
width: Math.min(250px, root.width * 0.7);
height: self.width;
// source: Logic.qr-code(Store.current-account.pubkey);
source: Icons.wechat-pay;
}
}

CenterLayout {
HorizontalLayout {
spacing: Theme.spacing * 2;

Link {
// text: Store.current-account.pubkey;
text: "Store.current-account.pubkey";
overflow: elide;
wrap: TextWrap.no-wrap;
color: self.has-hover ? Theme.link-text-color : Theme.primary-text-color;
clicked => {
Logic.open-account-detail(Logic.get-current-network(), Store.current-account.pubkey);
}
}

IconBtn {
icon: Icons.copy;
clicked => {
Logic.copy-to-clipboard(Store.current-account.pubkey);
}
}
}
}
}
}

export component Recipient inherits VerticalLayout {
private property <string> network: Logic.get-current-network();

head := TopHead { }

if network != "main": TestModeBanner {
network: root.network;
}

body := Body { }
}
21 changes: 18 additions & 3 deletions src/logic/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ use crate::{
message_success, message_warn,
slint_generatedAppWindow::{
AccountEntry as UIAccountEntry, AccountMnemonicSetting, AppWindow, IconsDialogSetting,
Logic, SettingDetailIndex, Store,
Logic, SettingDetailIndex, Store, Util,
},
};
use anyhow::{bail, Context, Result};
use cutil::crypto;
use slint::{ComponentHandle, Model, SharedString, VecModel, Weak};
use std::cmp::Ordering;
use std::{cmp::Ordering, str::FromStr};
use uuid::Uuid;
use wallet::{mnemonic, prelude::*};
use wallet::{mnemonic, network::NetworkType, prelude::*};

#[macro_export]
macro_rules! store_accounts {
Expand Down Expand Up @@ -507,6 +507,21 @@ pub fn init(ui: &AppWindow) {
}
});
});

let ui_handle = ui.as_weak();
ui.global::<Logic>()
.on_open_account_detail(move |network, address| {
let ui = ui_handle.unwrap();
match NetworkType::from_str(&network) {
Ok(ty) => {
let url = ty.address_detail_url(&address);
ui.global::<Util>()
.invoke_open_url("Default".into(), url.into());
message_success!(ui, tr("打开成功"));
}
Err(e) => message_warn!(ui, format!("{}. {e:?}", tr("打开失败"))),
}
});
}

fn _new_account(ui: &AppWindow, name: SharedString, password: SharedString) {
Expand Down
31 changes: 21 additions & 10 deletions src/logic/tr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub fn tr(text: &str) -> String {
items.insert("原因", "Reason");
items.insert("取消", "Cancel");
items.insert("确认", "Confirm");
items.insert("确定", "Confirm");
items.insert("编辑", "Edit");
items.insert("删除", "Delete");
items.insert("清空", "Clear");
Expand Down Expand Up @@ -198,7 +199,7 @@ pub fn tr(text: &str) -> String {
items.insert("内部错误", "Internal error");
items.insert("密码错误", "Password is wrong");
items.insert("组记词", "Mnemonic");
items.insert("地址簿", "AddressBook");
items.insert("地址簿", "Address Book");
items.insert("移除地址", "Delete address");
items.insert("是否删除地址?", "Delete address or not?");
items.insert("地址名称", "Address name");
Expand All @@ -212,7 +213,7 @@ pub fn tr(text: &str) -> String {
items.insert("删除所有账户成功", "Delete all accounts success");
items.insert("打开成功", "Open link success");
items.insert("打开失败", "Open link failed");
items.insert("安全与隐私", "Security && Privacy ");
items.insert("安全与隐私", "Security & Privacy ");
items.insert("重置账户", "Reset account");
items.insert("是否重置账户?", "Reset account or not?");
items.insert("请输入旧密码", "Please input old password");
Expand All @@ -222,20 +223,30 @@ pub fn tr(text: &str) -> String {
items.insert("主网络", "Main Network");
items.insert("测试网络", "Test Network");
items.insert("开发网络", "Dev Network");
items.insert("注意: 当前处于", "Warn: current network is ");
items.insert("未知网络", "Unknown Network");
items.insert("注意: 当前处于", "Warning: Current Network is ");
items.insert("主页", "Home");
items.insert("接收", "Recipient");
items.insert("历史", "History");
items.insert("历史记录", "History");
items.insert("开发者模式", "Developer Mode");
items.insert("账户名称", "Account name");
items.insert("显示组记词", "Show mnemonics");
items.insert("移除账户", "Remove account");
items.insert("更改密码", "Change password");
items.insert("位组记词", "mnemonics");

// TODO
items.insert(
"订阅、搜索和预览RSS消息",
"Subscribe, search and review RSS message.",
"创建账户和使用组记词恢复账户",
"Create account and recover account from mnemonics",
);
items.insert(
"收藏喜欢的文章,以便以后重新阅读",
"Collecting the articals you like. You can read it latter.",
"查看、发送和接收Sol代币和Solana的通证",
"Show, send and receive Sol and tokens of Solana",
);
items.insert(
"欢迎使用,享受你的阅读之旅",
"Welcome! Enjoying you journey of reading.",
"欢迎使用,享受你的加密之旅",
"Welcome! Enjoying you journey of crypto.",
);

if let Some(txt) = items.get(text) {
Expand Down
6 changes: 3 additions & 3 deletions ui/appwindow.slint
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ export component AppWindow inherits Window {
details: [
{
picture: Icons.landing-subscription,
description: Logic.tr(Store.is-cn, "订阅、搜索和预览RSS消息"),
description: Logic.tr(Store.is-cn, "创建账户和使用组记词恢复账户"),
},
{
picture: Icons.landing-reading,
description: Logic.tr(Store.is-cn, "收藏喜欢的文章,以便以后重新阅读"),
description: Logic.tr(Store.is-cn, "查看、发送和接收Sol代币和Solana的通证"),
},
{
picture: Icons.landing-welcome,
description: Logic.tr(Store.is-cn, "欢迎使用,享受你的阅读之旅"),
description: Logic.tr(Store.is-cn, "欢迎使用,享受你的加密之旅"),
}
];
skipped => {
Expand Down
7 changes: 7 additions & 0 deletions ui/base/address-book.slint
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export struct AddressBookEntry {

export global AddressBookSetting {
in-out property <[AddressBookEntry]> entries: [
{
uuid: "uuid-1",
name: "Address-1",
address: "0xf1199999751b1a3A74590adBf95401D19AB30014"
},
{
uuid: "uuid-1",
name: "Address-1",
Expand Down Expand Up @@ -49,8 +54,10 @@ export component AddressBook inherits Rectangle {

sd := SettingDetail {
title: Logic.tr(Store.is-cn, "地址簿");
is-show-divider: true;

SettingDetailInner {
vbox-spacing: Theme.spacing * 2;
for item[index] in AddressBookSetting.entries: ListTile {
height: item-height;
background: self.has-hover ? Theme.base-background.darker(3%) : Theme.base-background;
Expand Down
1 change: 1 addition & 0 deletions ui/base/link.slint
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export component Link inherits Text {
in-out property <bool> is-read;

callback clicked <=> touch.clicked;
out property has-hover <=> touch.has-hover;

wrap: word-wrap;
font-size: Theme.title5-font-size;
Expand Down
2 changes: 1 addition & 1 deletion ui/base/login.slint
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export component Login inherits Rectangle {
}

ConfirmBtn {
text: Logic.tr(Store.is-cn, "确定");
text: Logic.tr(Store.is-cn, "确认");

clicked => {
root.error-message = root.confirm(username-lineedit.text, password-lineedit.text);
Expand Down
4 changes: 2 additions & 2 deletions ui/base/mnemonic.slint
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export component Mnemonic inherits Rectangle {
private property <int> max-blocks: mnemonics.length == 24 ? 2 : (mnemonics.length == 12 ? 1 : 0);

out property <bool> is-mnemonic-counts-12: max-blocks != 2;
private property <string> switch-mnemonic-counts-btn-text: Logic.tr(Store.is-cn, (is-mnemonic-counts-12 ? "24" : "12") + "位组记词");
private property <string> switch-mnemonic-counts-btn-text: (is-mnemonic-counts-12 ? "24" : "12") + Logic.tr(Store.is-cn, "位组记词");

callback back();
callback copy([string]);
Expand Down Expand Up @@ -211,7 +211,7 @@ export component Mnemonic inherits Rectangle {
}

ConfirmBtn {
text: Logic.tr(Store.is-cn, "确定");
text: Logic.tr(Store.is-cn, "确认");
clicked => {
root.confirm();
}
Expand Down
2 changes: 1 addition & 1 deletion ui/base/password.slint
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export component Password inherits Rectangle {
}

ConfirmBtn {
text: Logic.tr(Store.is-cn, "确定");
text: Logic.tr(Store.is-cn, "确认");

clicked => {
root.error-message = root.confirm(PasswordSetting.handle-type, password-lineedit.text, PasswordSetting.user-data);
Expand Down
2 changes: 1 addition & 1 deletion ui/base/reset-password.slint
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export component ResetPassword inherits Rectangle {
}

ConfirmBtn {
text: Logic.tr(Store.is-cn, "确定");
text: Logic.tr(Store.is-cn, "确认");

clicked => {
root.error-message = root.confirm(password-old-lineedit.text, password-first-lineedit.text, password-second-lineedit.text);
Expand Down
6 changes: 5 additions & 1 deletion ui/base/setting-detail.slint
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ export component SettingDetail inherits Rectangle {

in-out property <string> title;
in-out property <bool> is-show-header: true;
in-out property <bool> is-show-divider;

VerticalLayout {
if is-show-header: Head {
title: root.title;
is-show-divider: root.is-show-divider;
hbox-alignment: LayoutAlignment.start;
clicked => {
root.back();
Expand All @@ -25,8 +27,10 @@ export component SettingDetail inherits Rectangle {

export component SettingDetailInner inherits Flickable {
in-out property <LayoutAlignment> vbox-alignment: LayoutAlignment.start;
in-out property vbox-padding <=> vbox.padding;
in-out property vbox-spacing <=> vbox.spacing;

VerticalLayout {
vbox := VerticalLayout {
alignment: root.vbox-alignment;
padding: Theme.padding * 2;
spacing: Theme.spacing * 4;
Expand Down
2 changes: 1 addition & 1 deletion ui/base/sign-in.slint
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export component SignIn inherits Rectangle {
}

ConfirmBtn {
text: Logic.tr(Store.is-cn, "确定");
text: Logic.tr(Store.is-cn, "确认");

clicked => {
root.error-message = root.confirm(username-lineedit.text, password-first-lineedit.text, password-second-lineedit.text);
Expand Down
Loading

0 comments on commit 7796a82

Please sign in to comment.