Skip to content

Commit

Permalink
fix review notes
Browse files Browse the repository at this point in the history
  • Loading branch information
borngraced committed Nov 13, 2024
1 parent 59db165 commit f5caa19
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 43 deletions.
10 changes: 5 additions & 5 deletions mm2src/coins/tendermint/tendermint_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,12 @@ pub enum TendermintWalletConnectionType {
Wc,
WcLedger,
KeplrLedger,
Internal,
Keplr,
Native,
}

impl Default for TendermintWalletConnectionType {
fn default() -> Self { Self::Internal }
fn default() -> Self { Self::Native }
}

pub struct TendermintCoinImpl {
Expand Down Expand Up @@ -1380,9 +1381,8 @@ impl TendermintCoin {

let tx_json = if self.is_wallet_connect() {
// if wallet_type is WalletConnect, update tx_json to use WalletConnect type.
let my_address = self.my_address().unwrap();
json!({
"signerAddress": my_address,
"signerAddress": self.my_address()?,
"signDoc": {
"accountNumber": sign_doc.account_number.to_string(),
"chainId": sign_doc.chain_id,
Expand All @@ -1407,7 +1407,7 @@ impl TendermintCoin {
})
}

/// This should only be used for Keplr from Ledger!
/// This should only be used for Keplr/WalletConnect from Ledger!
/// When using Keplr from Ledger, they don't accept `SING_MODE_DIRECT` transactions.
///
/// Visit https://docs.cosmos.network/main/build/architecture/adr-050-sign-mode-textual#context for more context.
Expand Down
71 changes: 33 additions & 38 deletions mm2src/coins_activation/src/tendermint_with_assets_activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,36 +233,30 @@ async fn activate_with_walletconnect(
ctx: &MmArc,
chain_id: &str,
ticker: &str,
wallet_type: &mut TendermintWalletConnectionType,
) -> MmResult<TendermintActivationPolicy, TendermintInitError> {
let account = {
let wc = WalletConnectCtx::from_ctx(ctx).expect("WalletConnectCtx should be initialized by now!");

if wc.is_ledger_connection().await {
*wallet_type = TendermintWalletConnectionType::WcLedger;
} else {
*wallet_type = TendermintWalletConnectionType::Wc;
};

cosmos_get_accounts_impl(&wc, chain_id)
.await
.mm_err(|err| TendermintInitError {
ticker: ticker.to_string(),
kind: TendermintInitErrorKind::UnableToFetchChainAccount(err.to_string()),
})?
) -> MmResult<(TendermintActivationPolicy, TendermintWalletConnectionType), TendermintInitError> {
let wc = WalletConnectCtx::from_ctx(ctx).expect("WalletConnectCtx should be initialized by now!");
let account = cosmos_get_accounts_impl(&wc, chain_id)
.await
.mm_err(|err| TendermintInitError {
ticker: ticker.to_string(),
kind: TendermintInitErrorKind::UnableToFetchChainAccount(err.to_string()),
})?;
let wallet_type = if wc.is_ledger_connection().await {
TendermintWalletConnectionType::WcLedger
} else {
TendermintWalletConnectionType::Wc
};

let pubkey = match account.algo {
CosmosAccountAlgo::Secp256k1 | CosmosAccountAlgo::TendermintSecp256k1 => {
TendermintPublicKey::from_raw_secp256k1(&account.pubkey).ok_or("Invalid secp256k1 pubkey".to_owned())
TendermintPublicKey::from_raw_secp256k1(&account.pubkey).ok_or(TendermintInitError {
ticker: ticker.to_string(),
kind: TendermintInitErrorKind::Internal("Invalid secp256k1 pubkey".to_owned()),
})?
},
}
.map_to_mm(|e| TendermintInitError {
ticker: ticker.to_string(),
kind: TendermintInitErrorKind::Internal(e),
})?;
};

Ok(TendermintActivationPolicy::with_public_key(pubkey))
Ok((TendermintActivationPolicy::with_public_key(pubkey), wallet_type))
}

#[async_trait]
Expand All @@ -284,9 +278,8 @@ impl PlatformCoinWithTokensActivationOps for TendermintCoin {
protocol_conf: Self::PlatformProtocolInfo,
) -> Result<Self, MmError<Self::ActivationError>> {
let conf = TendermintConf::try_from_json(&ticker, coin_conf)?;
let mut wallet_connectin_type = TendermintWalletConnectionType::Internal;

let activation_policy = if let Some(params) = activation_request.activation_params {
let (activation_policy, wallet_connection_type) = if let Some(params) = activation_request.activation_params {
if ctx.is_watcher() || ctx.use_watchers() {
return MmError::err(TendermintInitError {
ticker: ticker.clone(),
Expand All @@ -299,20 +292,19 @@ impl PlatformCoinWithTokensActivationOps for TendermintCoin {
pubkey,
is_ledger_connection,
} => {
if is_ledger_connection {
wallet_connectin_type = TendermintWalletConnectionType::KeplrLedger;
let wallet_connection_type = if is_ledger_connection {
TendermintWalletConnectionType::KeplrLedger
} else {
TendermintWalletConnectionType::Keplr
};

TendermintActivationPolicy::with_public_key(pubkey)
(
TendermintActivationPolicy::with_public_key(pubkey),
wallet_connection_type,
)
},
TendermintPubkeyActivationParams::WalletConnect => {
activate_with_walletconnect(
&ctx,
protocol_conf.chain_id.as_ref(),
&ticker,
&mut wallet_connectin_type,
)
.await?
activate_with_walletconnect(&ctx, protocol_conf.chain_id.as_ref(), &ticker).await?
},
}
} else {
Expand All @@ -325,7 +317,10 @@ impl PlatformCoinWithTokensActivationOps for TendermintCoin {
let tendermint_private_key_policy =
tendermint_priv_key_policy(&conf, &ticker, private_key_policy, activation_request.path_to_address)?;

TendermintActivationPolicy::with_private_key_policy(tendermint_private_key_policy)
(
TendermintActivationPolicy::with_private_key_policy(tendermint_private_key_policy),
TendermintWalletConnectionType::Native,
)
};

TendermintCoin::init(
Expand All @@ -336,7 +331,7 @@ impl PlatformCoinWithTokensActivationOps for TendermintCoin {
activation_request.nodes,
activation_request.tx_history,
activation_policy,
Some(wallet_connectin_type),
Some(wallet_connection_type),
)
.await
}
Expand Down

0 comments on commit f5caa19

Please sign in to comment.