Skip to content

Commit

Permalink
feat: force bond in the claim and stake flow (#1370)
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszjasiuk authored Dec 4, 2024
1 parent 269335a commit a640415
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions apps/namadillo/src/atoms/staking/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ export const createClaimAndStakeTx = async (
props: ClaimRewardsProps | BondProps
): Promise<TxMsgValue> => {
if ("amount" in props) {
// We have to force it in case: current balance < rewards to claim
// This will still log the error msg in the terminal, unfortunately we can't do much about it
wrapperTxProps.force = true;
return tx.buildBond(wrapperTxProps, props as BondProps);
} else {
return tx.buildClaimRewards(wrapperTxProps, props as ClaimRewardsProps);
Expand Down
8 changes: 7 additions & 1 deletion packages/shared/lib/src/sdk/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct WrapperTxMsg {
chain_id: String,
public_key: Option<String>,
memo: Option<String>,
force: Option<bool>,
}

impl WrapperTxMsg {
Expand All @@ -48,6 +49,7 @@ impl WrapperTxMsg {
chain_id: String,
public_key: Option<String>,
memo: Option<String>,
force: Option<bool>,
) -> WrapperTxMsg {
WrapperTxMsg {
token,
Expand All @@ -56,6 +58,7 @@ impl WrapperTxMsg {
chain_id,
public_key,
memo,
force,
}
}
}
Expand Down Expand Up @@ -884,6 +887,7 @@ fn tx_msg_into_args(tx_msg: &[u8]) -> Result<args::Tx, JsError> {
chain_id,
public_key,
memo,
force,
} = tx_msg;

let token = Address::from_str(&token)?;
Expand Down Expand Up @@ -911,12 +915,14 @@ fn tx_msg_into_args(tx_msg: &[u8]) -> Result<args::Tx, JsError> {

let memo = memo.map(|v| v.as_bytes().to_vec());

let force = force.unwrap_or(false);

let args = args::Tx {
dry_run: false,
dry_run_wrapper: false,
dump_tx: false,
dump_wrapper_tx: false,
force: false,
force,
broadcast_only: false,
ledger_address,
wallet_alias_force: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/lib/src/sdk/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl TxDetails {
let token = wrapper.fee.token.to_string();

let wrapper_tx =
WrapperTxMsg::new(token, fee_amount, gas_limit, chain_id, None, None);
WrapperTxMsg::new(token, fee_amount, gas_limit, chain_id, None, None, None);
let mut commitments: Vec<Commitment> = vec![];
let wasm_hashes: Vec<WasmHash> = wasm_hashes.into_serde().unwrap();

Expand Down
3 changes: 3 additions & 0 deletions packages/types/src/tx/schema/wrapperTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export class WrapperTxMsgValue {
@field({ type: option("string") })
memo?: string;

@field({ type: option("bool") })
force?: boolean;

constructor(data: WrapperTxProps) {
Object.assign(this, data);
}
Expand Down

1 comment on commit a640415

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.