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

Commit

Permalink
Merge branch 'main' into fix/update-default-plot-directory
Browse files Browse the repository at this point in the history
  • Loading branch information
dnoishi authored Sep 27, 2022
2 parents 5efe17b + 4d3a8e8 commit 285bca6
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 21 deletions.
5 changes: 5 additions & 0 deletions src-tauri/src/farmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ impl Default for ArchivingFrom {
}
}

#[tauri::command]
pub(crate) fn validate_reward_address(addr: &str) -> bool {
parse_reward_address(addr).is_ok()
}

/// manages the `farm` process
/// waits on the `farm` handle, and restarts the `farm` process if needed
#[tauri::command]
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ async fn main() -> Result<()> {
#[cfg(not(target_os = "windows"))]
tauri::generate_handler![
farmer::farming,
farmer::validate_reward_address,
node::start_node,
utils::frontend_error_logger,
utils::frontend_info_logger,
Expand All @@ -111,6 +112,7 @@ async fn main() -> Result<()> {
windows::winreg_set,
windows::winreg_delete,
farmer::farming,
farmer::validate_reward_address,
node::start_node,
utils::frontend_error_logger,
utils::frontend_info_logger,
Expand Down
6 changes: 3 additions & 3 deletions src-tauri/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ pub(crate) fn open_folder(dir: String) {
Command::new("explorer")
.arg(dir)
.spawn()
.expect("could not open to specified directory");
.expect("could not open the specified directory");

#[cfg(target_os = "macos")]
Command::new("open")
.arg(dir)
.spawn()
.expect("could not open to specified directory");
.expect("could not open the specified directory");

#[cfg(target_os = "linux")]
Command::new("xdg-open")
.arg(dir)
.spawn()
.expect("could not open to specified directory");
.expect("could not open the specified directory");
}

#[tauri::command]
Expand Down
5 changes: 2 additions & 3 deletions src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@
"importKey": {
"tooltip": "Please provide a valid Reward Address to proceed.",
"pageTitle": "Import Reward Address",
"rewardAddress": "Please enter your Reward Address in SS58 format (it should start with the letters \"st\")",
"rewardAddress": "Please use a proper wallet address from Subwallet or Polkadot.js extension",
"continue": "continue",
"cancel": "Cancel",
"addressErrorMsg": "Invalid address"
"cancel": "Cancel"
},
"header": {
"IncentivizedLabel": "Incentivized Testnet",
Expand Down
44 changes: 29 additions & 15 deletions src/pages/ImportKey.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,56 +11,70 @@ q-page(padding)
class="reward-address"
v-model="store.rewardAddress"
input-class="text-center"
:rules="[val => isValidSubstrateAddress(val) || $t('importKey.addressErrorMsg')]"
:error="!!store.rewardAddress && !isValidAddress"
:error-message="$t('importKey.rewardAddress')"
)
.row.justify-center.q-mt-sm
.row.justify-end.items-center.q-mt-lg.absolute-bottom.q-pa-lg
.col-auto.q-mr-md
q-btn(
@click="$router.replace({ name: 'index' })"
:label="$t('importKey.cancel')"
outline
size="lg"
@click="$router.replace({ name: 'index' })"
:label="$t('importKey.cancel')"
outline
size="lg"
icon-right="cancel"
)
q-space
.col-auto
q-btn(
:disable="!isValidSubstrateAddress(store.rewardAddress)"
:disable="!isValidAddress"
:label="$t('importKey.continue')"
@click="importKey()"
icon-right="arrow_forward"
outline
size="lg"
)
q-tooltip.q-pa-md(v-if="!isValidSubstrateAddress(store.rewardAddress)")
q-tooltip.q-pa-md(v-if="!isValidAddress")
p.q-mb-lg {{ $t('importKey.tooltip') }}
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import { decodeAddress, encodeAddress } from '@polkadot/keyring';
import { hexToU8a, isHex } from '@polkadot/util';
import { defineComponent, watch } from 'vue';
import * as tauri from '@tauri-apps/api';
import { useStore } from '../stores/store';
import { errorLogger } from '../lib/util';
export default defineComponent({
setup() {
const store = useStore();
return { store };
},
data() {
return {
isValidAddress: false,
};
},
mounted() {
watch(
() => this.store.rewardAddress,
async () => {
this.isValidAddress = await this.validateAddress(this.store.rewardAddress);
},
);
},
methods: {
isValidSubstrateAddress(val: string): boolean {
async validateAddress(addr: string): Promise<boolean> {
try {
encodeAddress(isHex(val) ? hexToU8a(val) : decodeAddress(val));
return true;
const result: boolean = await tauri.invoke('validate_reward_address', { addr });
return result;
} catch (error) {
errorLogger(error);
return false;
}
},
async importKey() {
this.$router.replace({ name: 'setupPlot' });
},
}
}
});
</script>
Expand Down

0 comments on commit 285bca6

Please sign in to comment.