Skip to content

Commit

Permalink
Fix: Disable default features for sp-core (#185)
Browse files Browse the repository at this point in the history
* change(Cargo): update `sp-core`, set project to disable `std` on `sp-core`.

* change(src): use `from_ss58check` instead of `from_str` since `sp-core` no longer has `std` enabled.
  • Loading branch information
pandres95 authored Dec 5, 2024
1 parent 570f5d1 commit eec8c41
Show file tree
Hide file tree
Showing 10 changed files with 645 additions and 874 deletions.
1,473 changes: 621 additions & 852 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ serde = "1.0.197"
serde_json = "1.0.114"
hex = "0.4.3"
wasm-bindgen-futures = "0.4.42"
sp-core = "32.0.0"
sp-core = { version = "34.0.0", default-features = false, features = ["serde"] }
reqwest = { version = "0.12.4", features = ["multipart", "json"] }
pulldown-cmark = "0.11.0"
blake2 = "0.10.6"
Expand Down
4 changes: 2 additions & 2 deletions src/components/molecules/actions/members.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::str::FromStr;
use sp_core::crypto::Ss58Codec;

use crate::{
components::atoms::{
Expand Down Expand Up @@ -43,7 +43,7 @@ pub fn MembersAction(props: VotingProps) -> Element {
MediumOptions::Wallet => translate!(i18, "onboard.invite.form.wallet.placeholder"),
},
error: {
match sp_core::sr25519::Public::from_str(&member.account) {
match sp_core::sr25519::Public::from_ss58check(&member.account) {
Ok(_) => None,
Err(_) => Some(translate!(i18, "onboard.invite.form.error.invalid_address")),
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/molecules/actions/transfer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::str::FromStr;
use sp_core::crypto::Ss58Codec;

use crate::{
components::atoms::{
Expand Down Expand Up @@ -35,7 +35,7 @@ pub fn TransferAction(props: VotingProps) -> Element {
size: ElementSize::Small,
placeholder: translate!(i18, "initiative.steps.actions.community_transfer.dest.placeholder"),
error: {
match sp_core::sr25519::Public::from_str(&transfer.account) {
match sp_core::sr25519::Public::from_ss58check(&transfer.account) {
Ok(_) => None,
Err(_) => Some(translate!(i18, "initiative.steps.actions.error.invalid_address")),
}
Expand Down
8 changes: 4 additions & 4 deletions src/hooks/use_accounts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::str::FromStr;
use sp_core::crypto::Ss58Codec;

use dioxus::prelude::*;
use dioxus_std::{i18n::use_i18, translate};
Expand Down Expand Up @@ -63,7 +63,7 @@ pub fn use_accounts() -> UseAccountsState {
set_signer(selected_account.address().clone());

let Ok(address) =
sp_core::sr25519::Public::from_str(&selected_account.address())
sp_core::sr25519::Public::from_ss58check(&selected_account.address())
else {
log::warn!("Not found public address");
return notification
Expand Down Expand Up @@ -131,8 +131,8 @@ impl UseAccountsState {
.get_account()
.ok_or("errors.wallet.accounts_not_found")?;
let account_address = pjs_account.address();
let address = sp_core::sr25519::Public::from_str(&account_address).map_err(|e| {
log::warn!("Not found public address: {}", e);
let address = sp_core::sr25519::Public::from_ss58check(&account_address).map_err(|e| {
log::warn!("Not found public address: {:?}", e);
"errors.wallet.account_address".to_string()
})?;
let hex_address = hex::encode(address.0);
Expand Down
5 changes: 3 additions & 2 deletions src/hooks/use_communities.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{str::FromStr, vec};
use std::vec;
use sp_core::crypto::Ss58Codec;

use dioxus::prelude::*;
use dioxus_std::{i18n::use_i18, translate};
Expand Down Expand Up @@ -45,7 +46,7 @@ pub fn use_communities() -> UseCommunitiesState {
let public_address = session
.get()
.and_then(
|session| match sp_core::sr25519::Public::from_str(&session.address) {
|session| match sp_core::sr25519::Public::from_ss58check(&session.address) {
Ok(public_address) => Some(public_address.0),
Err(_) => {
log::warn!("error here by address");
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/use_deposit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::str::FromStr;
use sp_core::crypto::Ss58Codec;

use dioxus::prelude::*;

Expand Down Expand Up @@ -45,7 +45,7 @@ impl DepositForm {
let amount = (amount * 1_000_000_000_000.0) as u64;
match &self.dest {
DepositTo::Address(addrs) => {
let address = sp_core::sr25519::Public::from_str(addrs)
let address = sp_core::sr25519::Public::from_ss58check(addrs)
.map_err(|_| DepositError::MalformedAddress)?;
let hex_address = format!("0x{}", hex::encode(address.0));
Ok((hex_address, amount, false))
Expand Down
5 changes: 3 additions & 2 deletions src/hooks/use_initiative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::components::atoms::dropdown::DropdownItem;
use chrono::{DateTime, NaiveDate, NaiveDateTime, Utc};
use dioxus::prelude::*;
use serde::{Deserialize, Serialize};
use sp_core::crypto::Ss58Codec;
const BLOCK_TIME_IN_SECONDS: i64 = 6;
#[derive(Clone, Default, Deserialize, Serialize, Debug)]
pub struct InfoForm {
Expand Down Expand Up @@ -399,7 +400,7 @@ impl UseInitiativeState {
.into_iter()
.filter_map(|member| {
if !member.account.is_empty() {
match sp_core::sr25519::Public::from_str(&member.account) {
match sp_core::sr25519::Public::from_ss58check(&member.account) {
Ok(_) => Some(member.account),
Err(_) => None,
}
Expand Down Expand Up @@ -564,7 +565,7 @@ impl UseInitiativeState {
.into_iter()
.filter_map(|transfer| {
if transfer.value > 0 {
match sp_core::sr25519::Public::from_str(&transfer.account) {
match sp_core::sr25519::Public::from_ss58check(&transfer.account) {
Ok(_) => Some(transfer),
Err(_) => None,
}
Expand Down
8 changes: 4 additions & 4 deletions src/pages/vote.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::str::FromStr;
use sp_core::crypto::Ss58Codec;
use dioxus::prelude::*;
use dioxus_std::{i18n::use_i18, translate};
use futures_util::{StreamExt, TryFutureExt};
Expand Down Expand Up @@ -71,7 +71,7 @@ pub fn Vote(id: u16, initiativeid: u16) -> Element {
.handle_error(&translate!(i18, "errors.communities.query_failed"));
return;
};
let Ok(address) = sp_core::sr25519::Public::from_str(&account.address) else {
let Ok(address) = sp_core::sr25519::Public::from_ss58check(&account.address) else {
log::info!("error here by address");
notification
.handle_error(&translate!(i18, "errors.wallet.account_address"));
Expand Down Expand Up @@ -187,9 +187,9 @@ pub fn Vote(id: u16, initiativeid: u16) -> Element {
.get()
.ok_or(translate!(i18, "errors.wallet.account_address"))?
.address;
let address = sp_core::sr25519::Public::from_str(&account_address)
let address = sp_core::sr25519::Public::from_ss58check(&account_address)
.map_err(|e| {
log::warn!("Not found public address: {}", e);
log::warn!("Not found public address: {:?}", e);
translate!(i18, "errors.wallet.account_address")
})?;
let hex_address = hex::encode(address.0);
Expand Down
6 changes: 3 additions & 3 deletions src/pages/withdraw.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::str::FromStr;
use sp_core::crypto::Ss58Codec;

use dioxus::prelude::*;
use dioxus_std::{i18n::use_i18, translate};
Expand Down Expand Up @@ -307,11 +307,11 @@ pub fn Withdraw() -> Element {
body: "This could take a moment".to_string(),
show: true,
});
let address = sp_core::sr25519::Public::from_str(
let address = sp_core::sr25519::Public::from_ss58check(
&withdraw.get_withdraw().address,
)
.map_err(|e| {
log::warn!("Not found public address: {}", e);
log::warn!("Not found public address: {:?}", e);
translate!(i18, "errors.wallet.account_address")
})?;
let hex_address = hex::encode(address.0);
Expand Down

0 comments on commit eec8c41

Please sign in to comment.