Skip to content

Commit

Permalink
Merge pull request #2395 from KomodoPlatform/activation-v2-boilerplate
Browse files Browse the repository at this point in the history
Refactor and ercv2 boilerplate
  • Loading branch information
smk762 authored Dec 21, 2023
2 parents 443abb1 + b123f69 commit 42fea1a
Show file tree
Hide file tree
Showing 103 changed files with 2,912 additions and 2,001 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ endif ()
##! We fetch our dependencies
if (APPLE)
FetchContent_Declare(mm2
URL https://sdk.devbuilds.komodo.earth/dev/mm2_6d7d05f-mac-x86-64.zip)
URL https://sdk.devbuilds.komodo.earth/main/mm2_b0fd99e-mac-x86-64.zip)
elseif (UNIX AND NOT APPLE)
FetchContent_Declare(mm2
URL https://sdk.devbuilds.komodo.earth/dev/mm2_6d7d05f-linux-x86-64.zip)
URL https://sdk.devbuilds.komodo.earth/main/mm2_b0fd99e-linux-x86-64.zip)
else ()
FetchContent_Declare(mm2
URL https://sdk.devbuilds.komodo.earth/dev/mm2_6d7d05f-win-x86-64.zip)
URL https://sdk.devbuilds.komodo.earth/main/mm2_b0fd99e-win-x86-64.zip)
endif ()

#FetchContent_Declare(qmaterial URL https://github.com/KomodoPlatform/Qaterial/archive/last-clang-working-2.zip)
Expand Down
6 changes: 6 additions & 0 deletions atomic_defi_design/Dex/Components/CoinMenu.qml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Menu {

MenuItem {
id: disable_action
height: 40
text: qsTr("Disable %1", "TICKER").arg(ticker)
onTriggered: API.app.disable_coins([ticker])
enabled: can_disable
Expand All @@ -41,22 +42,27 @@ Menu {
restart_modal.open()
}
enabled: disable_action.enabled && API.app.portfolio_pg.global_cfg_mdl.get_coin_info(ticker).is_custom_coin
visible: enabled
height: enabled ? 40 : 0
}

MenuItem {
height: 40
enabled: !General.prevent_coin_disabling.running
text: qsTr("Disable all %1 assets").arg(type)
onTriggered: API.app.disable_coins(API.app.portfolio_pg.get_all_coins_by_type(type))
}

MenuItem {
height: 40
enabled: !General.prevent_coin_disabling.running
text: qsTr("Disable all assets")
onTriggered: API.app.disable_coins(API.app.portfolio_pg.get_all_enabled_coins())
}

MenuItem
{
height: 40
enabled: !General.prevent_coin_disabling.running
text: qsTr("Disable 0 balance assets")
onTriggered: API.app.disable_no_balance_coins()
Expand Down
114 changes: 60 additions & 54 deletions atomic_defi_design/Dex/Constants/General.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ QtObject {
readonly property string custom_coin_icons_path: os_file_prefix + API.app.settings_pg.get_custom_coins_icons_path() + "/"
readonly property string providerIconsPath: image_path + "providers/"

/* Timers */
property Timer prevent_coin_disabling: Timer { interval: 5000 }

function coinIcon(ticker)
{
if (ticker === "" || ticker === "All" || ticker===undefined)
Expand Down Expand Up @@ -67,19 +70,12 @@ QtObject {
}

function coinName(ticker) {
if(ticker === "" || ticker === "All" || ticker===undefined) {
return ""
} else {
const name = API.app.portfolio_pg.global_cfg_mdl.get_coin_info(ticker).name
return name
}
return (ticker === "" || ticker === "All" || ticker===undefined) ? "" : API.app.portfolio_pg.global_cfg_mdl.get_coin_info(ticker).name
}

function canSend(ticker, progress=100)
{
if (!API.app.wallet_pg.send_available) return false
if (isZhtlc(ticker) && progress < 100) return false
return true
return !API.app.wallet_pg.send_available ? false : progress < 100 ? false : true
}

function isWalletOnly(ticker)
Expand All @@ -92,78 +88,84 @@ QtObject {
return API.app.portfolio_pg.global_cfg_mdl.get_coin_info(ticker).is_faucet_coin
}

function isCoinWithMemo(ticker) {
const coin_info = API.app.portfolio_pg.global_cfg_mdl.get_coin_info(ticker)
return coin_info.has_memos
function isCoinWithMemo(ticker)
{
return API.app.portfolio_pg.global_cfg_mdl.get_coin_info(ticker).has_memos
}

function getLanguage()
{
return API.app.settings_pg.lang
}

function isZhtlc(ticker)
function isZhtlc(coin)
{
const coin_info = API.app.portfolio_pg.global_cfg_mdl.get_coin_info(ticker)
return coin_info.is_zhtlc_family
return API.app.portfolio_pg.global_cfg_mdl.get_coin_info(coin).is_zhtlc_family
}

function isZhtlcReady(ticker)
function isZhtlcReady(coin)
{
if (!isZhtlc(ticker)) return true
let activation_status = API.app.get_zhtlc_status(ticker)
let progress = zhtlcActivationProgress(activation_status, ticker)
if (progress == 100) return true
return false
return !isZhtlc(coin) ? true : (zhtlcActivationProgress(coin) == 100) ? true : false
}

function zhtlcActivationProgress(activation_status, coin='ARRR')
{
let progress = 100
if (!activation_status.hasOwnProperty("result")) return progress
const coin_info = API.app.portfolio_pg.global_cfg_mdl.get_coin_info(coin)
let block_offset = coin_info.checkpoint_height
if (!isZhtlc(coin)) return progress
if (!activation_status.hasOwnProperty("result"))
{
return progress
}
let status = activation_status.result.status
let details = activation_status.result.details
// use range from checkpoint block to present

if (!status)
{
return -1
return 0
}
else if (status == "Ok")
{
if (details.hasOwnProperty("error"))
{
console.log("["+coin+"] [zhtlcActivationProgress] Error enabling: " + JSON.stringify(details.error))
return 0
}
}
else if (status == "InProgress")
{
if (details.hasOwnProperty("UpdatingBlocksCache"))
{
block_offset = details.UpdatingBlocksCache.first_sync_block.actual
let n = details.UpdatingBlocksCache.current_scanned_block - block_offset
let d = details.UpdatingBlocksCache.latest_block - block_offset
progress = 5 + parseInt(n/d*20)
let current = details.UpdatingBlocksCache.current_scanned_block
let latest = details.UpdatingBlocksCache.latest_block
let abs_pct = parseFloat(current/latest)
progress = parseInt(15 * abs_pct)
// console.log("["+coin+"] [zhtlcActivationProgress] UpdatingBlocksCache ["+current+"/"+latest+" * "+abs_pct+" | "+progress+"%]: " + JSON.stringify(details.UpdatingBlocksCache))
}
else if (details.hasOwnProperty("BuildingWalletDb"))
{
block_offset = details.BuildingWalletDb.first_sync_block.actual
let n = details.BuildingWalletDb.current_scanned_block - block_offset
let d = details.BuildingWalletDb.latest_block - block_offset
progress = 45 + parseInt(n/d*60)
if (progress > 95) {
progress = 95
let current = details.BuildingWalletDb.current_scanned_block
let latest = details.BuildingWalletDb.latest_block
let abs_pct = parseFloat(current/latest)
progress = parseInt(98 * abs_pct)
// console.log("["+coin+"] [zhtlcActivationProgress] BuildingWalletDb ["+current+"/"+latest+" * "+abs_pct+" * 98 | "+progress+"%]: " + JSON.stringify(details.BuildingWalletDb))
if (progress < 15) {
progress = 15
}
else if (progress > 98) {
progress = 98
}

}
else if (details.hasOwnProperty("RequestingBalance")) progress = 95
else if (details.hasOwnProperty("ActivatingCoin")) progress = 5
else progress = 5
else if (details.hasOwnProperty("RequestingWalletBalance")) progress = 99
else if (details.hasOwnProperty("ActivatingCoin")) progress = 1
else
{
progress = 2
}
}
else console.log("["+coin+"] [zhtlcActivationProgress] Unexpected status: " + status)
else console.log("["+coin+"] [zhtlcActivationProgress] Unexpected status: " + JSON.stringify(status))
if (progress > 100) {
progress = 98
}

progress = 100
}
return progress
}

Expand Down Expand Up @@ -476,6 +478,11 @@ QtObject {
return coin_info.tx_uri
}

function getBlockUri(coin_info) {
if (coin_info.block_uri == "") return "block/"
return coin_info.block_uri
}

function getTxExplorerURL(ticker, txid, add_0x=true) {
if(txid !== '') {
const coin_info = API.app.portfolio_pg.global_cfg_mdl.get_coin_info(ticker)
Expand Down Expand Up @@ -678,13 +685,12 @@ QtObject {
return false
}

property Timer prevent_coin_disabling: Timer { interval: 5000 }

function canDisable(ticker) {
if (prevent_coin_disabling.running) return false
if (ticker === atomic_app_primary_coin || ticker === atomic_app_secondary_coin) return false
if (ticker === "ETH") return !General.isParentCoinNeeded("ETH", "ERC-20")
if (ticker === "MATIC") return !General.isParentCoinNeeded("MATIC", "Matic")
if (ticker === "MATIC") return !General.isParentCoinNeeded("MATIC", "PLG-20")
if (ticker === "FTM") return !General.isParentCoinNeeded("FTM", "FTM-20")
if (ticker === "AVAX") return !General.isParentCoinNeeded("AVAX", "AVX-20")
if (ticker === "BNB") return !General.isParentCoinNeeded("BNB", "BEP-20")
Expand All @@ -695,13 +701,9 @@ QtObject {
if (ticker === "BCH") return !General.isParentCoinNeeded("BCH", "SLP")
if (ticker === "UBQ") return !General.isParentCoinNeeded("UBQ", "Ubiq")
if (ticker === "MOVR") return !General.isParentCoinNeeded("MOVR", "Moonriver")
if (ticker === "GLMR") return !General.isParentCoinNeeded("GLMR", "Moonbeam")
if (General.isZhtlc(ticker))
{
let progress = General.zhtlcActivationProgress(API.app.wallet_pg.ticker_infos.activation_status, ticker)
if (progress != 100) return false
}

if (ticker === "IRIS") return !General.isParentCoinNeeded("IRIS", "COSMOS")
if (ticker === "OSMO") return !General.isParentCoinNeeded("OSMO", "COSMOS")
if (ticker === "ATOM") return !General.isParentCoinNeeded("ATOM", "COSMOS")
return true
}

Expand All @@ -722,7 +724,11 @@ QtObject {
}

function isERC20(current_ticker_infos) {
return current_ticker_infos.type === "ERC-20" || current_ticker_infos.type === "BEP-20" || current_ticker_infos.type == "Matic"
return current_ticker_infos.type === "ERC-20"
|| current_ticker_infos.type === "BEP-20"
|| current_ticker_infos.type == "PLG-20"
|| current_ticker_infos.type == "FTM-20"
|| current_ticker_infos.type == "AVX-20"
}

function isParentCoin(ticker) {
Expand Down
6 changes: 4 additions & 2 deletions atomic_defi_design/Dex/Constants/Style.qml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ QtObject {
case 'QRC-20': return dark_theme ? colorCoinDark["QTUM"] : colorCoin["QTUM"]
case 'KRC-20': return dark_theme ? colorCoinDark["KCS"] : colorCoin["KCS"]
case 'Smart Chain': return dark_theme ? colorCoinDark["KMD"] : colorCoin["KMD"]
case 'Matic': return dark_theme ? colorCoinDark["MATIC"] : colorCoin["MATIC"]
case 'Matic':
case 'PLG-20': return dark_theme ? colorCoinDark["MATIC"] : colorCoin["MATIC"]
case 'Moonriver': return dark_theme ? colorCoinDark["MOVR"] : colorCoin["MOVR"]
case 'HRC-20': return dark_theme ? colorCoinDark["ONE"] : colorCoin["ONE"]
case 'SmartBCH': return dark_theme ? colorCoinDark["SBCH"] : colorCoin["SBCH"]
Expand Down Expand Up @@ -245,7 +246,8 @@ QtObject {
case 'QRC-20': return dark_theme ? colorCoinDark["QTUM"] : colorCoin["QTUM"]
case 'KRC-20': return dark_theme ? colorCoinDark["KCS"] : colorCoin["KCS"]
case 'Smart Chain': return dark_theme ? colorCoinDark["KMD"] : colorCoin["KMD"]
case 'Matic': return dark_theme ? colorCoinDark["MATIC"] : colorCoin["MATIC"]
case 'Matic':
case 'PLG-20': return dark_theme ? colorCoinDark["MATIC"] : colorCoin["MATIC"]
case 'Moonriver': return dark_theme ? colorCoinDark["MOVR"] : colorCoin["MOVR"]
case 'HRC-20': return dark_theme ? colorCoinDark["ONE"] : colorCoin["ONE"]
case 'SmartBCH': return dark_theme ? colorCoinDark["SBCH"] : colorCoin["SBCH"]
Expand Down
16 changes: 11 additions & 5 deletions atomic_defi_design/Dex/Exchange/ProView/DexComboBoxLine.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ RowLayout
property color color: !details ? "white" : Style.getCoinColor(details.ticker)
property alias middle_text: middle_line.text_value
property alias bottom_text: bottom_line.text_value
property int activation_progress: Dex.General.zhtlcActivationProgress(details.activation_status, details.ticker)

property int activation_pct: General.zhtlcActivationProgress(API.app.get_zhtlc_status(details.ticker), details.ticker)
Connections
{
target: API.app.settings_pg
function onZhtlcStatusChanged() {
activation_pct = General.zhtlcActivationProgress(API.app.get_zhtlc_status(details.ticker), details.ticker)
}
}
Behavior on color { ColorAnimation { duration: Style.animationDuration } }

Dex.Image
Expand All @@ -40,7 +46,7 @@ RowLayout
anchors.centerIn: parent
anchors.fill: parent
radius: 10
enabled: Dex.General.isZhtlc(details.ticker) ? activation_progress < 100 : false
enabled: activation_pct < 100
visible: enabled
opacity: .9
color: Dex.DexTheme.backgroundColor
Expand All @@ -50,11 +56,11 @@ RowLayout
{
anchors.centerIn: parent
anchors.fill: parent
enabled: Dex.General.isZhtlc(details.ticker) ? activation_progress < 100 : false
enabled: activation_pct < 100
visible: enabled
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: activation_progress + "%"
text: activation_pct + "%"
font: Dex.DexTypo.body2
color: Dex.DexTheme.okColor
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ ColumnLayout
function getMaxBalance()
{
if (General.isFilled(base_ticker))
return API.app.get_balance(base_ticker)

return API.app.get_balance_info_qstr(base_ticker)
return "0"
}

Expand Down
6 changes: 3 additions & 3 deletions atomic_defi_design/Dex/Exchange/Trade/SimpleView/Trade.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ClipRRect // Trade Card
readonly property var fees: Constants.API.app.trading_pg.fees
readonly property var max_trade_volume: Constants.API.app.trading_pg.max_volume
readonly property var min_trade_volume: Constants.API.app.trading_pg.min_trade_vol
readonly property var sell_ticker_balance: parseFloat(API.app.get_balance(left_ticker))
readonly property var sell_ticker_balance: parseFloat(API.app.get_balance_info_qstr(left_ticker))
readonly property bool coin_tradable: selectedTicker !== "" && sell_ticker_balance > 0
readonly property bool waiting_for_sell_coin_info: (max_trade_volume == 0 || !Constants.General.isZhtlcReady(left_ticker)) && sell_ticker_balance != 0

Expand Down Expand Up @@ -398,7 +398,7 @@ ClipRRect // Trade Card

width: 60

text: _selectedTickerIcon.enabled ? atomic_qt_utilities.retrieve_main_ticker(selectedTicker) : qsTr("Pick a coin")
text: _selectedTickerIcon.enabled ? atomic_qt_utilities.retrieve_main_ticker(selectedTicker, false, true) : qsTr("Pick a coin")
font.pixelSize: Constants.Style.textSizeSmall2

wrapMode: Text.NoWrap
Expand Down Expand Up @@ -580,7 +580,7 @@ ClipRRect // Trade Card
anchors.leftMargin: 10
width: 60

text: enabled ? atomic_qt_utilities.retrieve_main_ticker(selectedOrder.coin) : ""
text: enabled ? atomic_qt_utilities.retrieve_main_ticker(selectedOrder.coin, false, true) : ""
font.pixelSize: Constants.Style.textSizeSmall2
wrapMode: Text.NoWrap

Expand Down
Loading

0 comments on commit 42fea1a

Please sign in to comment.