Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Claim Collateral Fees Function #3611

Merged
merged 7 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions app/actions/AssetActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,35 @@ class AssetActions {
};
}

claimCollateralFees(account_id, asset, backingAsset, claimFeesAmountAsset) {
let tr = WalletApi.new_transaction();

tr.add_type_operation("asset_claim_fees", {
fee: {
amount: 0,
asset_id: 0
},
issuer: account_id,
amount_to_claim: {
asset_id: backingAsset.asset_id,
amount: claimFeesAmountAsset.getAmount()
},
extensions: {
claim_from_asset_id: asset.get("id")
}
});
return dispatch => {
return WalletDb.process_transaction(tr, null, true)
.then(() => {
dispatch(true);
})
.catch(error => {
console.log("----- claimFees error ----->", error);
dispatch(false);
});
};
}

assetGlobalSettle(asset, account_id, price) {
let tr = WalletApi.new_transaction();

Expand Down
135 changes: 133 additions & 2 deletions app/components/Account/FeePoolOperation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ class FeePoolOperation extends React.Component {
[key]: amount
});
}

onClaimCollateralInput(key, {amount}) {
this.state[key + "Asset"].setAmount({real: amount});
this.setState({
[key]: amount
});
}

onFundPool = () =>
AssetActions.fundPool(
Expand Down Expand Up @@ -68,9 +75,36 @@ class FeePoolOperation extends React.Component {
amount: 0,
precision: this.props.asset.get("precision"),
asset_id: this.props.asset.get("id")
}),
claimCollateralFeesAmount: 0,
claimCollateralFeesAmountAsset: new Asset({
amount: 0,
precision: this.props.asset.get("precision"),
asset_id: this.props.asset.get("id")
}),
backingAsset: new Asset({
amount: 0,
asset_id: this.props.asset.has("bitasset")
? this.props.asset.getIn([
"bitasset",
"options",
"short_backing_asset"
])
: "1.3.0"
})
});


onClaimCollateralFees() {
let account = ChainStore.getAccount(this.props.funderAccountName);
if (!account) return;
AssetActions.claimCollateralFees(
account.get("id"),
this.props.asset,
this.state.backingAsset,
this.state.claimCollateralFeesAmountAsset
);
}

onClaimFees() {
let account = ChainStore.getAccount(this.props.funderAccountName);
if (!account) return;
Expand Down Expand Up @@ -333,14 +367,111 @@ class FeePoolOperation extends React.Component {
);
}

renderClaimCollateralFees() {
const {props} = this;
const {claimCollateralFeesAmount} = this.state;
const {asset, getDynamicObject} = props;
let dynamicObject = getDynamicObject(
asset.get("dynamic_asset_data_id")
);
console.log(dynamicObject);
let backingAsset = this.props.asset.has("bitasset")
? this.props.asset.getIn([
"bitasset",
"options",
"short_backing_asset"
])
: "1.3.0";
let unclaimedCollateralBalance = dynamicObject
? dynamicObject.get("accumulated_collateral_fees")
: 0;
let validClaim =
claimCollateralFeesAmount > 0 &&
this.state.claimCollateralFeesAmountAsset.getAmount() <= unclaimedCollateralBalance;

let unclaimedCollateralBalanceText = (
<span
onClick={() => {
this.state.claimCollateralFeesAmountAsset.setAmount({
sats: dynamicObject.get("accumulated_collateral_fees")
});
this.setState({
claimCollateralFeesAmount: this.state.claimCollateralFeesAmountAsset.getAmount(
{
real: true
}
)
});
}}
>
<Translate component="span" content="transfer.available" />
:&nbsp;
<FormattedAsset
amount={unclaimedCollateralBalance}
asset={backingAsset}
/>
</span>
);
return (
<div>
<Translate
component="p"
content="explorer.asset.fee_pool.claim_text"
asset={backingAsset}
/>
<div style={{paddingBottom: "1rem"}}>
<Translate content="explorer.asset.fee_pool.unclaimed_issuer_income" />
:&nbsp;
{dynamicObject ? (
<FormattedAsset
amount={dynamicObject.get("accumulated_collateral_fees")}
asset={backingAsset}
/>
) : null}
</div>

<AmountSelector
label="transfer.amount"
display_balance={unclaimedCollateralBalanceText}
amount={claimCollateralFeesAmount}
onChange={this.onClaimCollateralInput.bind(this, "claimCollateralFeesAmount")}
asset={backingAsset}
assets={[backingAsset]}
placeholder="0.0"
tabIndex={1}
style={{width: "100%", paddingTop: 16}}
/>

<div style={{paddingTop: "1rem"}} className="button-group">
<button
className={classnames("button", {
disabled: !validClaim
})}
onClick={this.onClaimCollateralFees.bind(this)}
>
<Translate content="explorer.asset.fee_pool.claim_collateral_fees" />
</button>
<button
className="button outline"
onClick={this.reset.bind(this)}
>
<Translate content="account.perm.reset" />
</button>
</div>
</div>
);
}

render() {
if (this.props.type === "fund") {
return this.renderFundPool();
} else if (this.props.type === "claim") {
return this.renderClaimPool();
} else if (this.props.type === "claim_fees") {
return this.renderClaimFees();
}
} else if (this.props.type === "claim_collateral_fees") {
return this.renderClaimCollateralFees();
}
}
}

Expand Down
21 changes: 20 additions & 1 deletion app/components/Blockchain/Asset.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,25 @@ class Asset extends React.Component {
</Panel>
);
}

renderFeesCollateralClaiming(asset) {
let dynamic = this.props.getDynamicObject(asset.dynamic_asset_data_id);
if (dynamic) dynamic = dynamic.toJS();
return (
<Panel
header={
<Translate content="explorer.asset.fee_pool.accumulated_collateral_fees" />
}
>
<FeePoolOperation
asset={asset.symbol}
dynamic={dynamic}
funderAccountName={this.props.currentAccount}
hideBalance
type="claim_collateral_fees"
/>
</Panel>
);
}
// TODO: Blacklist Authorities: <Account list like Voting>
// TODO: Blacklist Market: Base/Market, Base/Market
renderPermissions(asset) {
Expand Down Expand Up @@ -2368,6 +2386,7 @@ class Asset extends React.Component {
{this.renderFeePoolFunding(asset)}
{this.renderFeePoolClaiming(asset)}
{this.renderFeesClaiming(asset)}
{this.renderFeesCollateralClaiming(asset)}
{this.renderAssetOwnerUpdate(asset)}
{"bitasset" in asset &&
!asset.bitasset.is_prediction_market &&
Expand Down