Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
display node name and version (#180)
Browse files Browse the repository at this point in the history
* display node name and version

* testSSC fixes and lint fix

* plotStarted bug fix, and remove unnecessary `viewedIntro` from plottingProgress
  • Loading branch information
ozgunozerk committed Apr 26, 2022
1 parent 21dfc54 commit 417ce64
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 33 deletions.
14 changes: 10 additions & 4 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ async fn farming(path: String, reward_address: String, plot_size: u64) -> bool {
}

#[tauri::command]
async fn start_node(path: String) {
init_node(path.into()).await.unwrap();
async fn start_node(path: String) -> String {
let node_name = node::generate_node_name();
init_node(path.into(), node_name.clone()).await.unwrap();
node_name
}

#[tauri::command]
Expand Down Expand Up @@ -157,15 +159,19 @@ async fn main() -> Result<()> {
Ok(())
}

async fn init_node(base_directory: PathBuf) -> Result<()> {
async fn init_node(base_directory: PathBuf, node_name: String) -> Result<()> {
let chain_spec =
sc_service::GenericChainSpec::<subspace_runtime::GenesisConfig>::from_json_bytes(
include_bytes!("../chain-spec.json").as_ref(),
)
.map_err(anyhow::Error::msg)?;

let full_client_fut = tokio::task::spawn_blocking(move || {
Handle::current().block_on(node::create_full_client(chain_spec, base_directory))
Handle::current().block_on(node::create_full_client(
chain_spec,
base_directory,
node_name,
))
});
let mut full_client = full_client_fut.await??;

Expand Down
5 changes: 4 additions & 1 deletion src-tauri/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl NativeExecutionDispatch for ExecutorDispatch {
pub(crate) async fn create_full_client<CS: ChainSpec + 'static>(
chain_spec: CS,
base_path: PathBuf,
node_name: String,
) -> Result<NewFull<Arc<FullClient<subspace_runtime::RuntimeApi, ExecutorDispatch>>>> {
// This must only be initialized once
INITIALIZE_SUBSTRATE.call_once(|| {
Expand Down Expand Up @@ -86,6 +87,7 @@ pub(crate) async fn create_full_client<CS: ChainSpec + 'static>(
BasePath::Permanenent(base_path),
chain_spec,
Handle::current(),
node_name,
)?;

subspace_service::new_full::<subspace_runtime::RuntimeApi, ExecutorDispatch>(config, true)
Expand Down Expand Up @@ -117,6 +119,7 @@ fn create_configuration<CS: ChainSpec + 'static>(
base_path: BasePath,
chain_spec: CS,
tokio_handle: tokio::runtime::Handle,
node_name: String,
) -> Result<Configuration> {
let impl_name = "Subspace-desktop".to_string();
let impl_version = env!("SUBSTRATE_CLI_IMPL_VERSION").to_string();
Expand All @@ -125,7 +128,7 @@ fn create_configuration<CS: ChainSpec + 'static>(
let client_id = format!("{}/v{}", impl_name, impl_version);
let database_cache_size = 1024;
let mut network = NetworkConfiguration::new(
generate_node_name(),
node_name,
client_id,
NodeKeyConfig::Ed25519(Secret::File(net_config_dir.join(NODE_KEY_ED25519_FILE))),
Some(net_config_dir),
Expand Down
2 changes: 1 addition & 1 deletion src/components/disclaimer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ q-dialog(@hide="onDialogHide" persistent ref="dialog")
q-space
q-icon(color="grey" name="info" size="40px")
q-card-section.q-pt-none
| Tokens/credits generated on the Subspace Network testnet ("tSSCs") do not equate to Subspace Network mainnet tokens, have no monetary value, and cannot be exchanged for cash, cash equivalent, or other tokens or cryptocurrencies.
| Tokens/credits generated on the Subspace Network testnet ("testSSCs") do not equate to Subspace Network mainnet tokens, have no monetary value, and cannot be exchanged for cash, cash equivalent, or other tokens or cryptocurrencies.
q-card-actions(align='right')
q-btn(flat='', label='I understand', color='primary', v-close-popup='')

Expand Down
5 changes: 2 additions & 3 deletions src/components/farmedList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ q-card(bordered flat)
h6 {{ farmedBlocksList?.length }}
.col-auto.q-mr-xl
.text-weight-light Total Earned
p {{ farmedTotalEarned }} testnetSSC
p {{ farmedTotalEarned }} testSSC
.col-auto
.text-weight-light Reward Address
.reward-address {{ rewardAddress }}
Expand Down Expand Up @@ -57,7 +57,7 @@ q-card(bordered flat)
.col-3
p.text-weight-light {{ formatDate(block.time) }}
.col-2
p {{ block.blockReward }} testnetSSC
p {{ block.blockReward }} testSSC
</template>

<script lang="ts">
Expand All @@ -67,7 +67,6 @@ import { globalState as global } from "src/lib/global"
import { FarmedBlock } from "src/lib/types"
import { formatDistanceToNowStrict } from "date-fns"
import { LocalStorage } from "quasar"
import { appConfig } from "src/lib/appConfig"
const lang = global.data.loc.text.dashboard
Expand Down
11 changes: 3 additions & 8 deletions src/components/mainMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ q-menu(auto-close)
.col
p.text-grey(v-if="!launchOnStart") {{ lang.autoStart }}
p.text-black(v-else) {{ lang.autoStart }}
q-item(@click="reset()" clickable v-if="devMode")
q-item(@click="reset()" clickable v-if="util.CONTEXT_MENU != 'OFF'")
.row.items-center
.col-auto.q-mr-md
q-icon(color="red" name="refresh")
Expand All @@ -32,21 +32,16 @@ export default defineComponent({
data() {
return {
lang,
util,
launchOnStart: false,
autoLauncher: global.autoLauncher,
disableAutoLaunch: false,
devMode: false
disableAutoLaunch: false
}
},
mounted() {
this.checkDev()
this.initMenu()
},
methods: {
checkDev() {
if (util.CONTEXT_MENU != "OFF")
this.devMode = true
},
async toggleClicked() {
if (this.disableAutoLaunch) {
Notify.create({
Expand Down
27 changes: 23 additions & 4 deletions src/layouts/MainLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ q-layout(view="hHh lpr fFf")
q-img(no-spinner src="subspacelogo.png" width="150px")
q-toolbar-title
.row
.col-auto.q-mr-lg.relative-position
p {{ "0.4.1 "}}
.col-auto.q-mr-md.relative-position
q-badge(color="grey" text-color="white")
.q-pa-xs(style="font-size: 14px") {{ lang.nonIncentivizedLabel }}
q-tooltip
.col
p.no-margin(style="font-size: 12px") {{ lang.nonIncentivizedTooltip }}
// Show the dashboard status indicator when on the dashboard page.
.col-auto.q-mr-md.relative-position(
v-if="nodeName != ''"
)
q-badge(color="blue-8" text-color="white")
.q-ma-xs(style="font-size: 14px") {{ "Node Name:" }}
.q-mr-xs(class="text-italic" style="font-size: 14px") {{ nodeName }}
// Show the dashboard status indicator when on the dashboard page.
.col-auto.q-mr-md.relative-position(
v-if="$route.name == 'dashboard'"
)
Expand Down Expand Up @@ -46,6 +54,8 @@ import { defineComponent } from "vue"
import { globalState as global } from "src/lib/global"
import * as util from "src/lib/util"
import MainMenu from "components/mainMenu.vue"
import { myEmitter } from "src/lib/client"
const lang = global.data.loc.text.mainMenu
export default defineComponent({
Expand All @@ -58,10 +68,19 @@ export default defineComponent({
lang,
global: global.data,
util,
autoLaunch: false
autoLaunch: false,
nodeName: ''
}
},
methods: {}
mounted() {
this.nodeNameChanger()
},
methods: {
async nodeNameChanger() {
myEmitter.on("nodeName", (arg1: string) => {
this.nodeName = arg1
});
},
}
})
</script>
8 changes: 5 additions & 3 deletions src/lib/client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ApiPromise, Keyring, WsProvider } from "@polkadot/api"
import type { Vec } from "@polkadot/types/codec"
import type { u128, u32 } from "@polkadot/types"
import type { AccountId32 } from "@polkadot/types/interfaces"
import { mnemonicGenerate } from "@polkadot/util-crypto"
import * as event from "@tauri-apps/api/event"
import { invoke } from "@tauri-apps/api/tauri"
Expand All @@ -16,7 +15,9 @@ import {
FarmedBlock,
SubPreDigest
} from "src/lib/types"
import { appConfig } from "./appConfig"
import EventEmitter from "events"

export const myEmitter = new EventEmitter();

const tauri = { event, invoke }
const SUNIT = 1000000000000000000n
Expand Down Expand Up @@ -216,7 +217,8 @@ export class Client {

// TODO: Disable mnemonic return from tauri commmand instead of this validation.
private async startNode(path: string): Promise<void> {
await tauri.invoke("start_node", { path })
const nodeName: string = await tauri.invoke("start_node", { path })
myEmitter.emit("nodeName", nodeName)
if (!this.firstLoad) {
this.loadStoredBlocks()
}
Expand Down
4 changes: 2 additions & 2 deletions src/loc/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"hint": "Hint:",
"hints": "Hints",
"resume": "Resume Plotting",
"hintInfo": "Join the Subspace Discord while you wait, meet the community and earn some testnetSSC",
"hintInfo": "Join the Subspace Discord while you wait, meet the community and earn some testSSC",
"remaining": "Remaining",
"next": "Next"
},
Expand Down Expand Up @@ -80,7 +80,7 @@
},
"mainMenu": {
"nonIncentivizedLabel": "Non-Incentivized Testnet",
"nonIncentivizedTooltip": "Rewards (testnetSSC) you earn from farming do not and will not hold a real value throughout the testnet phase.",
"nonIncentivizedTooltip": "Rewards (testSSC) you earn from farming do not and will not hold a real value throughout the testnet phase.",
"reset": "Reset",
"autoStart": "Start on Boot",
"willAutoLaunch": "Subspace will launch automatically during boot",
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export default defineComponent({
progress: true,
message: `${lang.farmedBlock}: ${block.blockNum} ${lang.reward} ${
block.blockReward + block.feeReward
} testnetSSC`,
} testSSC`,
position: "bottom-right"
})
}
Expand Down
6 changes: 1 addition & 5 deletions src/pages/PlottingProgress.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ export default defineComponent({
status: lang.fetchingPlot
},
client: global.client,
viewedIntro: false,
plotFinished: false,
localSegmentCount: 0,
networkSegmentCount: 0,
Expand Down Expand Up @@ -248,10 +247,7 @@ export default defineComponent({
this.pausePlotting()
},
async viewIntro() {
const modal = await util.showModal(introModal)
modal?.onDismiss(() => {
this.viewedIntro = true
})
await util.showModal(introModal)
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/pages/SetupPlot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export default defineComponent({
async viewMnemonic() {
const modal = await util.showModal(mnemonicModal)
modal?.onDismiss(() => {
appConfig.updateAppConfig(null, null, null, true, null)
appConfig.updateAppConfig(null, null, null, null, true)
this.$router.replace({ name: "plottingProgress" })
})
}
Expand Down

0 comments on commit 417ce64

Please sign in to comment.