Skip to content

Commit

Permalink
Use match statement.
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Dec 19, 2023
1 parent 9314a7b commit e063c47
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions packages/dao-voting/src/deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use cosmwasm_std::{
};
use cw_utils::{must_pay, PaymentError};

use dao_interface::voting::DenomResponse;
use dao_interface::{token, voting::DenomResponse};

Check failure on line 7 in packages/dao-voting/src/deposit.rs

View workflow job for this annotation

GitHub Actions / Lints

unused import: `token`

Check failure on line 7 in packages/dao-voting/src/deposit.rs

View workflow job for this annotation

GitHub Actions / Lints

unused import: `token`

Check warning on line 7 in packages/dao-voting/src/deposit.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `token`

Check warning on line 7 in packages/dao-voting/src/deposit.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `token`
use thiserror::Error;

use cw_denom::{CheckedDenom, DenomError, UncheckedDenom};
Expand Down Expand Up @@ -113,26 +113,32 @@ impl UncheckedDepositInfo {
.querier
.query_wasm_smart(dao, &dao_interface::msg::QueryMsg::VotingModule {})?;

if token_type == VotingModuleTokenType::Native {
// If the voting module has no native token denom this will
// error. This is desirable.
let denom: DenomResponse = deps
.querier
.query_wasm_smart(voting_module, &dao_interface::voting::Query::Denom {})?;
// Validate that native denom is formatted correctly.
UncheckedDenom::Native(denom.denom).into_checked(deps)
} else {
// If the voting module has no cw20 token this will error.
// This is desirable.
let token_addr: Addr = deps.querier.query_wasm_smart(
voting_module,
&dao_interface::voting::Query::TokenContract {},
)?;
// We don't assume here that the voting module has
// returned a valid token. Conversion of the unchecked
// denom into a checked one will do a `TokenInfo {}`
// query.
UncheckedDenom::Cw20(token_addr.into_string()).into_checked(deps)
match token_type {
VotingModuleTokenType::Native => {
// If the voting module has no native token denom this
// will error. This is desirable.
let denom: DenomResponse = deps.querier.query_wasm_smart(
voting_module,
&dao_interface::voting::Query::Denom {},
)?;

// Validate that native denom is formatted correctly.
UncheckedDenom::Native(denom.denom).into_checked(deps)
}
VotingModuleTokenType::Cw20 => {
// If the voting module has no cw20 token this will
// error. This is desirable.
let token_addr: Addr = deps.querier.query_wasm_smart(
voting_module,
&dao_interface::voting::Query::TokenContract {},
)?;

// We don't assume here that the voting module has
// returned a valid token. Conversion of the unchecked
// denom into a checked one will do a `TokenInfo {}`
// query.
UncheckedDenom::Cw20(token_addr.into_string()).into_checked(deps)
}
}
}
}?;
Expand Down

0 comments on commit e063c47

Please sign in to comment.