mirror of
https://github.com/logos-blockchain/lez-programs.git
synced 2026-07-21 06:19:32 +00:00
fix(amm): read selected holdings once
This commit is contained in:
parent
43cdc0dced
commit
9b25a7224a
@ -509,24 +509,28 @@ void NewPositionRuntime::buildQuoteInputAsync(
|
||||
QVector<WalletAccountRead> fixedReads) mutable {
|
||||
if (!guard)
|
||||
return;
|
||||
QStringList selectedIds;
|
||||
for (const QString& key : {
|
||||
QStringLiteral("holdingAId"),
|
||||
QStringLiteral("holdingBId"),
|
||||
QStringLiteral("lpHoldingId") }) {
|
||||
const QString id = accountIdHex(
|
||||
requestObject.value(key).toString());
|
||||
if (!id.isEmpty() && !selectedIds.contains(id))
|
||||
selectedIds.append(id);
|
||||
}
|
||||
QStringList walletIds = guard->m_walletPublicAccountIds;
|
||||
for (const QString& id : selectedIds)
|
||||
walletIds.removeAll(id);
|
||||
guard->m_sequencer->readAccounts(
|
||||
guard->m_walletPublicAccountIds, false,
|
||||
walletIds, false,
|
||||
[guard, requestObject, network, walletOpen, config, pair,
|
||||
selectedIds = std::move(selectedIds),
|
||||
fixedReads = std::move(fixedReads),
|
||||
callback = std::move(callback)](
|
||||
QVector<WalletAccountRead> walletReads) mutable {
|
||||
if (!guard)
|
||||
return;
|
||||
QStringList selectedIds;
|
||||
for (const QString& key : {
|
||||
QStringLiteral("holdingAId"),
|
||||
QStringLiteral("holdingBId"),
|
||||
QStringLiteral("lpHoldingId") }) {
|
||||
const QString id = accountIdHex(
|
||||
requestObject.value(key).toString());
|
||||
if (!id.isEmpty() && !selectedIds.contains(id))
|
||||
selectedIds.append(id);
|
||||
}
|
||||
auto finish = [requestObject, network, walletOpen, config,
|
||||
fixedReads = std::move(fixedReads),
|
||||
walletReads = std::move(walletReads),
|
||||
|
||||
@ -744,6 +744,36 @@ int main(int argc, char** argv)
|
||||
"forced context should reread config and wallet holding"))
|
||||
return 1;
|
||||
|
||||
FakeWallet selectedWallet;
|
||||
NewPositionRuntime selectedRuntime(
|
||||
&selectedWallet, &refreshClient, &sequencer);
|
||||
const QString selectedAccountHex = QStringLiteral(
|
||||
"000102030405060708090a0b0c0d0e0f"
|
||||
"101112131415161718191a1b1c1d1e1f");
|
||||
WalletAccount selectedAccount;
|
||||
selectedAccount.address = selectedAccountHex;
|
||||
selectedAccount.isPublic = true;
|
||||
selectedRuntime.setWalletAccounts({ selectedAccount });
|
||||
QVariantMap selectedRequest = request;
|
||||
selectedRequest.insert(
|
||||
QStringLiteral("holdingAId"),
|
||||
QStringLiteral("1thX6LZfHDZZKUs92febYZhYRcXddmzfzF2NvTkPNE"));
|
||||
const int requestsBeforeSelectedQuote = server.requestCount();
|
||||
const int normalizationsBeforeSelectedQuote =
|
||||
refreshClient.normalizedAccountIds.count(selectedAccountHex);
|
||||
QVariantMap selectedQuote;
|
||||
selectedRuntime.quoteAsync(
|
||||
selectedRequest, readyNetwork(), true, false,
|
||||
[&](QVariantMap result) { selectedQuote = std::move(result); });
|
||||
if (!expect(waitForCondition([&]() { return !selectedQuote.isEmpty(); }),
|
||||
"selected-holding quote should complete"))
|
||||
return 1;
|
||||
if (!expect(server.requestCount() == requestsBeforeSelectedQuote + 1
|
||||
&& refreshClient.normalizedAccountIds.count(selectedAccountHex)
|
||||
== normalizationsBeforeSelectedQuote + 1,
|
||||
"selected holding should be read once per cold quote"))
|
||||
return 1;
|
||||
|
||||
server.failNextRequest();
|
||||
QVector<WalletAccountRead> failedRefresh;
|
||||
if (!expect(waitForAccounts(sequencer, { holding.address }, true,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user