Page MenuHomePhabricator

[Cashtab] Account for tx fees when calculating agora buy max
AbandonedPublicDraft

Authored by bytesofman on Jul 17 2025, 12:43.

Details

Reviewers
None
Group Reviewers
Restricted Project
Summary

Use available methods to determine fees and account for this when determining the user's max buy. We have received user reports of errors trying to max buy due to insufficient utxos, which was expected based on the introduction of this feature.

We may have another issue in the future -- that is, user's max buying only to realize they have no XEC left to do any other token txs, including sell. So we may want to do something like "max buy always leaves the user 5,000 XEC" ... this though is complicated as well, because what about the user who does not have that much XEC but still wants to buy tokens? Will need to see how this plays out in reality before optimizing there.

For now, there's nothing wrong with getting the exact fees, and it is one of the major advantages of XEC over say ETH or even SOL, where users will always have annoying token/L1 dust in a wallet forever since fees are always guesstimated.

Test Plan

npm test

Diff Detail

Repository
rABC Bitcoin ABC
Branch
agora-max-calcfee
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 33903
Build 67276: Build Diffcashtab-tests · ecash-agora-tests · ecash-agora-integration-tests
Build 67275: arc lint + arc unit

Event Timeline

Failed tests logs:

====== CashTab Unit Tests: <Agora /> On token server API fail, we fall back to locally maintained blacklist. A blacklisted offer does not render in all offers, but will render in My offers ======
Error: No token mock for 0387947fd575db4fb19a3e322f635dec37fd192b5941625b66bc4b2c3008cbf0, but we have it in the wallet. Please add this TokenMock.
    at prepareMockedChronikCallsForWallet (/work/cashtab/src/test/index.tsx:123:19)
    at prepareMockedChronikCallsForWallet (/work/cashtab/src/test/index.tsx:187:9)
    at Object.<anonymous> (/work/cashtab/src/components/Agora/__tests__/index.test.tsx:645:31)
====== CashTab Unit Tests: <Agora /> We can see multiple offers, some we made, others we did not, and we can cancel an offer ======
Error: No token mock for 0387947fd575db4fb19a3e322f635dec37fd192b5941625b66bc4b2c3008cbf0, but we have it in the wallet. Please add this TokenMock.
    at prepareMockedChronikCallsForWallet (/work/cashtab/src/test/index.tsx:123:19)
    at prepareMockedChronikCallsForWallet (/work/cashtab/src/test/index.tsx:187:9)
    at Object.<anonymous> (/work/cashtab/src/components/Agora/__tests__/index.test.tsx:807:31)

Each failure log is accessible here:
CashTab Unit Tests: <Agora /> On token server API fail, we fall back to locally maintained blacklist. A blacklisted offer does not render in all offers, but will render in My offers
CashTab Unit Tests: <Agora /> We can see multiple offers, some we made, others we did not, and we can cancel an offer

Failed tests logs:

====== CashTab Unit Tests: <Agora /> We can see multiple offers, some we made, others we did not, and we can cancel an offer ======
Error: Unable to find an element with the text: 100,000.00 XEC. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.

Ignored nodes: comments, script, style
<body>
  <div>
    <div
      class="sc-epGmkI gEcelO"
    >
      <section
        aria-atomic="false"
        aria-label="Notifications Alt+T"
        aria-live="polite"
        aria-relevant="additions text"
        class="Toastify"
      />
      <div
        class="sc-dphlzf kWTBLl"
      >
        <div
          class="sc-fCPvlr jjqlGS"
        >
          <div
            class="sc-cmIlrE erdidG"
            title="Wallet Info"
          >
            <div
              class="sc-gleUXh eqThuU"
            >
              <img
                alt="cashtab"
                src="test-file-stub"
              />
              <div
                class="sc-bNQFlB iWAswN"
                title="Price in Local Currency mobile"
              >
                1 
                XEC
                 = 
                0.00003000
                 
                USD
              </div>
            </div>
            <div
              class="sc-doWzTn cwxplc"
            >
              <div
                class="sc-dBaXSw YgqsB"
                title="Price in Local Currency"
              >
                1 
                XEC
                 = 
                0.00003000
                 
                USD
              </div>
              <div
                class="sc-dRCTWM fkOZJx"
              >
                <label
                  class="sc-dPNhBE bHLtba"
                >
                  <input
                    checked=""
                    class="sc-kkwfeq bizqnG"
                    type="checkbox"
                  />
                  <div
                    class="sc-izvnbC cWRmnN"
                  >
                    <img
                      alt="toggle icon"
                      src="test-file-stub"
                    />
                  </div>
                </label>
                <button
                  aria-label="Copy ecash:qreq3mm4avxaw782g4qvhktx4qcv0w2tkqj3j5jaad"
                  class="sc-dNLxif cAFGSA"
                >
                  <svg
                    title="copy-paste"
                  />
                </button>
                <select
                  class="sc-cgHJcJ hQnlum"
                  data-testid="wallet-select"
                  id="wallets"
                  name="wallets"
                >
                  <option
                    class="sc-hizQCF bqpbnS"
                    value="Agora Partial Beta"
                  >
                    Agora Partial Beta
                  </option>
                  <option
                    class="sc-hizQCF bqpbnS"
                    value="Agora Partial Alpha"
                  >
                    Agora Partial Alpha
                  </option>
                </select>
              </div>
            </div>
            <div
              class="sc-hARARD eVwYut"
            >
              <div
                class="sc-ccLTTT bPnMjq"
              >
                <div
                  class="sc-hlILIN ldlUir"
                >
                  <img
                    alt="eCash"
                    class="sc-jQMNup kNOJiJ"
                    src="test-file-stub"
                  />
                  <div
                    class="sc-bJHhxl hcFRXF"
                  >
                    eCash
                  </div>
                  <div
                    class="sc-TuwoP gKAyt"
                    title="Balance XEC"
                  >
                    10,000,000.00
                     
                    XEC
                  </div>
                  <div
                    class="sc-fQkuQJ idpvOV"
                    title="Balance XEC Fiat"
                  >
                    $
                    300.00
                     
                    USD
                  </div>
                </div>
                <div
                  class="sc-hlILIN cHZcbF"
                >
                  <img
                    alt="eCash Staking"
                    class="sc-jQMNup kNOJiJ"
                    src="test-file-stub"
                  />
                  <div
                    class="sc-bJHhxl hjJCEK"
                  >
                    Staking
                  </div>
                  <div
                    class="sc-TuwoP eUItcw"
                    title="Balance XECX"
                  >
                    0.00
                     
                    <a
                      href="#/token/c67bf5c2b6d91cfb46a5c1772582eff80d88686887be10aa63b0945479cf4ed4"
                    >
                      XECX
                    </a>
                  </div>
                  <div
                    class="sc-fQkuQJ idpvOV"
                    title="Balance XECX Fiat"
                  >
              ...
    at waitForWrapper (/work/cashtab/node_modules/@testing-library/dom/dist/wait-for.js:163:27)
    at /work/cashtab/node_modules/@testing-library/dom/dist/query-helpers.js:86:33
    at Object.findByText (/work/cashtab/src/components/Agora/__tests__/index.test.tsx:1030:29)
    at runNextTicks (node:internal/process/task_queues:60:5)
    at listOnTimeout (node:internal/timers:545:9)
    at processTimers (node:internal/timers:519:7)

Each failure log is accessible here:
CashTab Unit Tests: <Agora /> We can see multiple offers, some we made, others we did not, and we can cancel an offer

account for dust, patch ecash-agora

Failed tests logs:

====== CashTab Unit Tests: <Agora /> We can see multiple offers, some we made, others we did not, and we can cancel an offer ======
Error: Unable to find an element with the text: 100,000.00 XEC. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.

Ignored nodes: comments, script, style
<body>
  <div>
    <div
      class="sc-epGmkI gEcelO"
    >
      <section
        aria-atomic="false"
        aria-label="Notifications Alt+T"
        aria-live="polite"
        aria-relevant="additions text"
        class="Toastify"
      />
      <div
        class="sc-dphlzf kWTBLl"
      >
        <div
          class="sc-fCPvlr jjqlGS"
        >
          <div
            class="sc-cmIlrE erdidG"
            title="Wallet Info"
          >
            <div
              class="sc-gleUXh eqThuU"
            >
              <img
                alt="cashtab"
                src="test-file-stub"
              />
              <div
                class="sc-bNQFlB iWAswN"
                title="Price in Local Currency mobile"
              >
                1 
                XEC
                 = 
                0.00003000
                 
                USD
              </div>
            </div>
            <div
              class="sc-doWzTn cwxplc"
            >
              <div
                class="sc-dBaXSw YgqsB"
                title="Price in Local Currency"
              >
                1 
                XEC
                 = 
                0.00003000
                 
                USD
              </div>
              <div
                class="sc-dRCTWM fkOZJx"
              >
                <label
                  class="sc-dPNhBE bHLtba"
                >
                  <input
                    checked=""
                    class="sc-kkwfeq bizqnG"
                    type="checkbox"
                  />
                  <div
                    class="sc-izvnbC cWRmnN"
                  >
                    <img
                      alt="toggle icon"
                      src="test-file-stub"
                    />
                  </div>
                </label>
                <button
                  aria-label="Copy ecash:qreq3mm4avxaw782g4qvhktx4qcv0w2tkqj3j5jaad"
                  class="sc-dNLxif cAFGSA"
                >
                  <svg
                    title="copy-paste"
                  />
                </button>
                <select
                  class="sc-cgHJcJ hQnlum"
                  data-testid="wallet-select"
                  id="wallets"
                  name="wallets"
                >
                  <option
                    class="sc-hizQCF bqpbnS"
                    value="Agora Partial Beta"
                  >
                    Agora Partial Beta
                  </option>
                  <option
                    class="sc-hizQCF bqpbnS"
                    value="Agora Partial Alpha"
                  >
                    Agora Partial Alpha
                  </option>
                </select>
              </div>
            </div>
            <div
              class="sc-hARARD eVwYut"
            >
              <div
                class="sc-ccLTTT bPnMjq"
              >
                <div
                  class="sc-hlILIN ldlUir"
                >
                  <img
                    alt="eCash"
                    class="sc-jQMNup kNOJiJ"
                    src="test-file-stub"
                  />
                  <div
                    class="sc-bJHhxl hcFRXF"
                  >
                    eCash
                  </div>
                  <div
                    class="sc-TuwoP gKAyt"
                    title="Balance XEC"
                  >
                    10,000,000.00
                     
                    XEC
                  </div>
                  <div
                    class="sc-fQkuQJ idpvOV"
                    title="Balance XEC Fiat"
                  >
                    $
                    300.00
                     
                    USD
                  </div>
                </div>
                <div
                  class="sc-hlILIN cHZcbF"
                >
                  <img
                    alt="eCash Staking"
                    class="sc-jQMNup kNOJiJ"
                    src="test-file-stub"
                  />
                  <div
                    class="sc-bJHhxl hjJCEK"
                  >
                    Staking
                  </div>
                  <div
                    class="sc-TuwoP eUItcw"
                    title="Balance XECX"
                  >
                    0.01
                     
                    <a
                      href="#/token/c67bf5c2b6d91cfb46a5c1772582eff80d88686887be10aa63b0945479cf4ed4"
                    >
                      XECX
                    </a>
                  </div>
                  <div
                    class="sc-fQkuQJ idpvOV"
                    title="Balance XECX Fiat"
                  >
              ...
    at waitForWrapper (/work/cashtab/node_modules/@testing-library/dom/dist/wait-for.js:163:27)
    at /work/cashtab/node_modules/@testing-library/dom/dist/query-helpers.js:86:33
    at Object.findByText (/work/cashtab/src/components/Agora/__tests__/index.test.tsx:1030:29)
    at runNextTicks (node:internal/process/task_queues:60:5)
    at listOnTimeout (node:internal/timers:545:9)
    at processTimers (node:internal/timers:519:7)

Each failure log is accessible here:
CashTab Unit Tests: <Agora /> We can see multiple offers, some we made, others we did not, and we can cancel an offer

patch test (has been flaky for awhile, prob this is why)

this is still an open problem but should be handled in ecash-wallet.