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

Commit

Permalink
hotfix: improved reward address logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ozgunozerk committed May 5, 2022
1 parent c05c98b commit c589fcf
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "subspace-desktop",
"version": "0.4.2",
"version": "0.4.5",
"private": true,
"description": "Subspace desktop",
"author": "Subspace Labs <https://subspace.network>",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subspace-desktop"
version = "0.4.4"
version = "0.4.5"
description = "Subspace desktop"
authors = ["Subspace Labs <https://subspace.network>"]
license = "Apache-2.0"
Expand Down
13 changes: 8 additions & 5 deletions src/components/farmedList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ 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 Expand Up @@ -95,13 +96,15 @@ export default defineComponent({
return formatDistanceToNowStrict(date)
},
displayRewardAddress() {
const addr: string | null = LocalStorage.getItem("rewardAddress")
if (addr == null) {
console.error("Reward Address was null!")
return "???"
const config = appConfig.getAppConfig()
let addr = ""
if (config && config.rewardAddress !== "") {
addr = config.rewardAddress
} else {
return addr
console.error("FARMED LIST | could not retrieve reward address from config")
addr = "???"
}
return addr
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/MainLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ q-layout(view="hHh lpr fFf")
q-toolbar-title
.row
.col-auto.q-mr-lg.relative-position
p {{ "0.4.4 "}}
p {{ "0.4.5 "}}
.col-auto.q-mr-md.relative-position
q-badge(color="grey" text-color="white")
.q-pa-xs(style="font-size: 14px") {{ lang.nonIncentivizedLabel }}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/appConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const appConfig = {
plot: Plot | null,
segmentCache: SegmentCache | null,
launchOnBoot: boolean | null,
importedRewAddr: boolean | null,
rewardAddress: string | null,
plottingStarted: boolean | null
): void {
const appConfig = this.getAppConfig()
Expand All @@ -23,7 +23,7 @@ export const appConfig = {
if (plot) newAppConfig.plot = plot
if (segmentCache) newAppConfig.segmentCache = segmentCache
if (launchOnBoot != null) newAppConfig.launchOnBoot = launchOnBoot
if (importedRewAddr != null) newAppConfig.importedRewAddr = importedRewAddr
if (rewardAddress) newAppConfig.rewardAddress = rewardAddress
if (plottingStarted != null) newAppConfig.plottingStarted = plottingStarted
LocalStorage.set("appConfig", newAppConfig)
}
Expand Down
22 changes: 14 additions & 8 deletions src/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
SubPreDigest
} from "src/lib/types"
import EventEmitter from "events"
import { appConfig } from "./appConfig"

export const myEmitter = new EventEmitter();

Expand Down Expand Up @@ -52,13 +53,15 @@ export class Client {
this.stop()
},
start: async (): Promise<void> => {

const farmerAddress = LocalStorage.getItem("rewardAddress")
if (farmerAddress === null) {
console.error("Reward address should not have been null...")
const config = appConfig.getAppConfig()
let farmerAddress = ""
if (config && config.rewardAddress !== "") {
farmerAddress = config.rewardAddress
}
if (farmerAddress === "") {
console.error("Reward address should not have been empty...")
return
}

this.unsubscribe = await this.localApi.rpc.chain.subscribeNewHeads(
async ({ hash, number }) => {
const blockNum = number.toNumber()
Expand Down Expand Up @@ -234,15 +237,18 @@ export class Client {
const keyring = new Keyring()
const pair = keyring.createFromUri(mnemonic)
keyring.setSS58Format(2254); // 2254 is the prefix for subspace-testnet
LocalStorage.set("rewardAddress", pair.address)
appConfig.updateAppConfig(null, null, null, pair.address, null)
this.mnemonic = mnemonic
}

/* FARMER INTEGRATION */
public async startFarming(path: string, plotSizeGB: number): Promise<boolean> {
const plotSize = Math.round(plotSizeGB * 1048576)
const rewardAddress: string | null = LocalStorage.getItem("rewardAddress")
if (rewardAddress == null) {
const config = appConfig.getAppConfig()
let rewardAddress = ""
if (config && config.rewardAddress !== "") {
rewardAddress = config.rewardAddress
} else {
console.error("Tried to send empty reward address to backend!")
}
return await tauri.invoke("farming", { path, rewardAddress, plotSize })
Expand Down
4 changes: 2 additions & 2 deletions src/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface AppConfig {
plot: Plot
segmentCache: SegmentCache
launchOnBoot: boolean
importedRewAddr: boolean
rewardAddress: string
plottingStarted: boolean
}

Expand All @@ -60,7 +60,7 @@ export const emptyAppConfig: AppConfig = {
plot: { location: "", sizeGB: 0 },
segmentCache: { networkSegmentCount: 0, blockchainSizeGB: 0 },
launchOnBoot: true,
importedRewAddr: false,
rewardAddress: "",
plottingStarted: false
}

Expand Down
3 changes: 1 addition & 2 deletions src/pages/ImportKey.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ export default defineComponent({
}
},
async importKey() {
LocalStorage.set("rewardAddress", this.rewardAddress)
appConfig.updateAppConfig(null, null, null, true, null)
appConfig.updateAppConfig(null, null, null, this.rewardAddress, null)
this.$router.replace({ name: "setupPlot" })
},
skip() {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/SetupPlot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export default defineComponent({
async checkIdentity() {
const config = appConfig.getAppConfig()
if (config) {
if (config.importedRewAddr === false) {
if (config.rewardAddress === "") {
await this.client.createRewardAddress()
await this.viewMnemonic()
} else {
Expand Down

0 comments on commit c589fcf

Please sign in to comment.