Skip to content

Commit

Permalink
Adding support for *default fee paying asset* in ApplicationApi (#3540)
Browse files Browse the repository at this point in the history
* Fixing bug in liquidity pools withdraw operation

User had reported that *feeAsset* is turning into *liquidity pool asset* while attempting to perform withdraw from a liquidity pool, seems bug is effecting objects.feeAsset.get("id") default object at liquidity pools withdraw *modal* which should show feeAsset as core asset.

* Use getFinalFeeAsset to determine FeeAsset in LP

* Update ApplicationApi.js

* Update ApplicationApi.js

* Update ApplicationApi.js

* Update ApplicationApi.js

* fix: honor given fee asset choices with getFinalFeeAsset as fallback

Co-authored-by: Stefan <toleantech@gmail.com>
  • Loading branch information
ioBanker and sschiessl-bcp committed Oct 31, 2022
1 parent dc258d4 commit 172f015
Showing 1 changed file with 135 additions and 30 deletions.
165 changes: 135 additions & 30 deletions app/api/ApplicationApi.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import WalletUnlockActions from "actions/WalletUnlockActions";

import accountUtils from "common/account_utils";
import WalletDb from "stores/WalletDb";
import {
Aes,
Expand Down Expand Up @@ -38,7 +38,10 @@ const ApplicationApi = {
tr.add_type_operation("account_create", {
fee: {
amount: 0,
asset_id: 0
asset_id: accountUtils.getFinalFeeAsset(
registrar,
"account_create"
)
},
registrar: chain_registrar.get("id"),
referrer: chain_referrer.get("id"),
Expand Down Expand Up @@ -118,11 +121,19 @@ const ApplicationApi = {
propose_account = null, // should be called memo_sender, but is not for compatibility reasons with transfer. Is set to "from_account" for non proposals
encrypt_memo = true,
optional_nonce = null,
fee_asset_id = "1.3.0",
fee_asset_id = null,
transactionBuilder = null
}) {
let unlock_promise = WalletUnlockActions.unlock();

if (!fee_asset_id) {
// use default fee asset selection if none given
fee_asset_id = accountUtils.getFinalFeeAsset(
from_account,
"transfer"
);
}

let memo_sender_account = propose_account || from_account;
return Promise.all([
FetchChain("getAccount", from_account),
Expand Down Expand Up @@ -170,8 +181,8 @@ const ApplicationApi = {
memo
)
: Buffer.isBuffer(memo)
? memo.toString("utf-8")
: memo
? memo.toString("utf-8")
: memo
};
}
}
Expand Down Expand Up @@ -238,7 +249,7 @@ const ApplicationApi = {
encrypt_memo = true,
optional_nonce = null,
propose_account = null,
fee_asset_id = "1.3.0",
fee_asset_id = null,
transactionBuilder = null
}) {
if (transactionBuilder == null) {
Expand Down Expand Up @@ -287,12 +298,6 @@ const ApplicationApi = {
},

transfer_list(list_of_transfers, proposal_fee = null) {
if (!proposal_fee) {
proposal_fee = "1.3.0";
}
if (typeof proposal_fee !== "string") {
proposal_fee = proposal_fee.get("id");
}
return WalletUnlockActions.unlock().then(() => {
let proposer = null;
let transfers = [];
Expand All @@ -309,6 +314,15 @@ const ApplicationApi = {
if (list_of_transfers[idx].propose_account) {
if (proposer == null) {
proposer = item.chain_propose_account;
if (!proposal_fee) {
proposal_fee = accountUtils.getFinalFeeAsset(
proposer,
"proposal_create"
);
}
if (typeof proposal_fee !== "string") {
proposal_fee = proposal_fee.get("id");
}
}
propose.push({op: item.transfer_op});
} else {
Expand Down Expand Up @@ -402,16 +416,19 @@ const ApplicationApi = {
memo
)
: Buffer.isBuffer(memo)
? memo.toString("utf-8")
: memo
? memo.toString("utf-8")
: memo
};
}

let tr = new TransactionBuilder();
tr.add_type_operation("asset_issue", {
fee: {
amount: 0,
asset_id: 0
asset_id: accountUtils.getFinalFeeAsset(
from_account,
"asset_issue"
)
},
issuer: from_account,
asset_to_issue: {
Expand Down Expand Up @@ -444,7 +461,10 @@ const ApplicationApi = {
tr.add_type_operation("worker_create", {
fee: {
amount: 0,
asset_id: 0
asset_id: accountUtils.getFinalFeeAsset(
account,
"worker_create"
)
},
owner,
work_begin_date: options.start,
Expand Down Expand Up @@ -513,7 +533,7 @@ const ApplicationApi = {
periodInSeconds,
periodsUntilExpiration,
periodStartTime = null,
feeAsset = "1.3.0",
feeAsset = null,
broadcast = true
) {
// default is now
Expand All @@ -527,6 +547,14 @@ const ApplicationApi = {
// account must be unlocked
await WalletUnlockActions.unlock();

if (!feeAsset) {
// use default fee asset selection if none given
feeAsset = accountUtils.getFinalFeeAsset(
from,
"withdraw_permission_create"
);
}

// ensure all arguments are chain objects
let objects = {
from: await this._ensureAccount(from),
Expand Down Expand Up @@ -591,7 +619,7 @@ const ApplicationApi = {
periodInSeconds,
periodsUntilExpiration,
periodStartTime = null,
feeAsset = "1.3.0",
feeAsset = null,
broadcast = true
) {
// default is now
Expand All @@ -605,6 +633,14 @@ const ApplicationApi = {
// account must be unlocked
await WalletUnlockActions.unlock();

if (!feeAsset) {
// use default fee asset selection if none given
feeAsset = accountUtils.getFinalFeeAsset(
from,
"withdraw_permission_update"
);
}

// ensure all arguments are chain objects
let objects = {
from: await this._ensureAccount(from),
Expand Down Expand Up @@ -662,12 +698,20 @@ const ApplicationApi = {
claimAsset,
claimAssetAmount,
memo = null,
feeAsset = "1.3.0",
feeAsset = null,
broadcast = true
) {
// account must be unlocked
await WalletUnlockActions.unlock();

if (!feeAsset) {
// use default fee asset selection if none given
feeAsset = accountUtils.getFinalFeeAsset(
from,
"withdraw_permission_claim"
);
}

// ensure all arguments are chain objects
let objects = {
from: await this._ensureAccount(from),
Expand Down Expand Up @@ -699,8 +743,8 @@ const ApplicationApi = {
memo
)
: Buffer.isBuffer(memo)
? memo.toString("utf-8")
: memo
? memo.toString("utf-8")
: memo
};
}
}
Expand Down Expand Up @@ -735,12 +779,20 @@ const ApplicationApi = {
withdrawPermissionId,
from,
to,
feeAsset = "1.3.0",
feeAsset = null,
broadcast = true
) {
// account must be unlocked
await WalletUnlockActions.unlock();

if (!feeAsset) {
// use default fee asset selection if none given
feeAsset = accountUtils.getFinalFeeAsset(
from,
"withdraw_permission_delete"
);
}

// ensure all arguments are chain objects
let objects = {
from: await this._ensureAccount(from),
Expand Down Expand Up @@ -775,12 +827,20 @@ const ApplicationApi = {
asset,
amount,
policy,
feeAsset = "1.3.0",
feeAsset = null,
broadcast = true
) {
// account must be unlocked
await WalletUnlockActions.unlock();

if (!feeAsset) {
// use default fee asset selection if none given
feeAsset = accountUtils.getFinalFeeAsset(
from,
"vesting_balance_create"
);
}

// ensure all arguments are chain objects
let objects = {
creator: await this._ensureAccount(creator),
Expand Down Expand Up @@ -819,12 +879,17 @@ const ApplicationApi = {
asset,
amount,
targetType = ChainTypes.ticket_type.lock_forever,
feeAsset = "1.3.0",
feeAsset = null,
broadcast = true
) {
// account must be unlocked
await WalletUnlockActions.unlock();

if (!feeAsset) {
// use default fee asset selection if none given
feeAsset = accountUtils.getFinalFeeAsset(from, "ticket_create");
}

// ensure all arguments are chain objects
let objects = {
account: await this._ensureAccount(account),
Expand All @@ -846,7 +911,7 @@ const ApplicationApi = {
},
extensions: {}
});
transactionBuilder.add_operation(op);
transactionBuilder.add_operation(op);
await WalletDb.process_transaction(transactionBuilder, null, broadcast);
if (!transactionBuilder.tr_buffer) {
throw "Something went finalization the transaction, this should not happen";
Expand All @@ -860,12 +925,20 @@ const ApplicationApi = {
shareAsset,
takerFeePercent,
withdrawalFeePercent,
feeAsset = "1.3.0",
feeAsset = null,
broadcast = true
) {
// account must be unlocked
await WalletUnlockActions.unlock();

if (!feeAsset) {
// use default fee asset selection if none given
feeAsset = accountUtils.getFinalFeeAsset(
from,
"liquidity_pool_create"
);
}

// ensure all arguments are chain objects
let objects = {
account: await this._ensureAccount(account),
Expand Down Expand Up @@ -903,12 +976,20 @@ const ApplicationApi = {
async liquidityPoolDelete(
account,
liquidityPoolId,
feeAsset = "1.3.0",
feeAsset = null,
broadcast = true
) {
// account must be unlocked
await WalletUnlockActions.unlock();

if (!feeAsset) {
// use default fee asset selection if none given
feeAsset = accountUtils.getFinalFeeAsset(
from,
"liquidity_pool_delete"
);
}

// ensure all arguments are chain objects
let objects = {
account: await this._ensureAccount(account),
Expand Down Expand Up @@ -943,12 +1024,20 @@ const ApplicationApi = {
assetB,
amountA,
amountB,
feeAsset = "1.3.0",
feeAsset = null,
broadcast = true
) {
// account must be unlocked
await WalletUnlockActions.unlock();

if (!feeAsset) {
// use default fee asset selection if none given
feeAsset = accountUtils.getFinalFeeAsset(
from,
"liquidity_pool_deposit"
);
}

// ensure all arguments are chain objects
let objects = {
account: await this._ensureAccount(account),
Expand Down Expand Up @@ -991,12 +1080,20 @@ const ApplicationApi = {
liquidityPoolId,
shareAsset,
shareAmount,
feeAsset = "1.3.0",
feeAsset = null,
broadcast = true
) {
// account must be unlocked
await WalletUnlockActions.unlock();

if (!feeAsset) {
// use default fee asset selection if none given
feeAsset = accountUtils.getFinalFeeAsset(
from,
"liquidity_pool_withdraw"
);
}

// ensure all arguments are chain objects
let objects = {
account: await this._ensureAccount(account),
Expand Down Expand Up @@ -1036,12 +1133,20 @@ const ApplicationApi = {
amountToSell,
receiveAsset,
minToReceive,
feeAsset = "1.3.0",
feeAsset = null,
broadcast = true
) {
// account must be unlocked
await WalletUnlockActions.unlock();

if (!feeAsset) {
// use default fee asset selection if none given
feeAsset = accountUtils.getFinalFeeAsset(
from,
"liquidity_pool_exchange"
);
}

// ensure all arguments are chain objects
let objects = {
account: await this._ensureAccount(account),
Expand Down

0 comments on commit 172f015

Please sign in to comment.