Page MenuHomePhabricator

[Cashtab] Validate agora accepts vs user balance
ClosedPublic

Authored by bytesofman on Mon, Mar 3, 19:04.

Details

Reviewers
emack
Group Reviewers
Restricted Project
Commits
rABCf07c7a1d0bbf: [Cashtab] Validate agora accepts vs user balance
Summary

Right now, Cashtab does not do this validation. So you can try to buy more than you can afford and expect an error at the tx building step.

This is lazy. We should validate for "can we afford this tx?" before we try to buy it.

We will improve this implementation going forward, but this is a key first step to supporting stuff like a "buy max" button.

The reason this was not implemented from the get go -- we need to calculate the actual price using agora methods after some validation is already done.

Test Plan

npm test

Diff Detail

Repository
rABC Bitcoin ABC
Branch
orderbook-validate-vs-balance
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 32573
Build 64634: Build Diffcashtab-tests
Build 64633: arc lint + arc unit

Event Timeline

Failed tests logs:

====== CashTab Unit Tests: <Agora /> We get expected error if we try to buy an offer we cannot afford ======
Error: Unable to find an element with the text: Execute this trade?. 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-keFjpB fuvsSf"
    >
      <section
        aria-atomic="false"
        aria-label="Notifications Alt+T"
        aria-live="polite"
        aria-relevant="additions text"
        class="Toastify"
      />
      <div
        class="sc-jWojfa gOMhPW"
      >
        <div
          class="sc-kVrTmx dSIcDd"
        >
          <div
            class="sc-ivVeuv hQBWoJ"
          >
            <img
              alt="cashtab"
              class="sc-cCbXAZ jOUSPN"
              src="test-file-stub"
            />
          </div>
          <div
            class="sc-cmIlrE ckvYmi"
          >
            <div
              class="sc-jkCMRl gxKbjs"
            >
              <select
                class="sc-crNyjn cynGtO"
                data-testid="wallet-select"
                id="wallets"
                name="wallets"
              >
                <option
                  class="sc-cpHetk jodErs"
                  value="Agora Partial Alpha"
                >
                  Agora Partial Alpha
                </option>
                <option
                  class="sc-cpHetk jodErs"
                  value="Agora Partial Beta"
                >
                  Agora Partial Beta
                </option>
              </select>
              <div
                class="sc-bqjOQT kauMuv"
              >
                <button
                  aria-label="Copy ecash:qqpmsv8yh8wwx3lnf92rrc0e6yq97j6zqs8av8vx8h"
                  class="sc-cJSrbW kZNvLw"
                >
                  <svg
                    title="copy-paste"
                  />
                </button>
                <div
                  class="sc-eerKOB cvXwwv"
                >
                  <div
                    class="sc-emmjRN bSWkUh"
                  >
                    <input
                      checked=""
                      class="sc-gFaPwZ iPJMNd"
                      id="show-hide-balance"
                      name="show-hide-balance"
                      title="show-hide-balance"
                      type="checkbox"
                    />
                    <label
                      class="sc-cpmLhU iUeRKn"
                      for="show-hide-balance"
                    >
                      <span
                        class="sc-dymIpo hGwQkt"
                        data-off=""
                        data-on=""
                      />
                      <span
                        class="sc-bnXvFD cpOMDW"
                      />
                    </label>
                  </div>
                </div>
              </div>
            </div>
            <div
              class="sc-gleUXh fSfkBQ"
              title="Wallet Info"
            >
              <div
                class="sc-nrwXf erXBln"
              >
                <div
                  class="sc-eitiEO isWDMZ"
                  title="Balance XEC"
                >
                  0.00
                   
                  XEC
                </div>
              </div>
              <div
                class="sc-bhlBdH kdHsOB"
                title="Balance in Local Currency"
              >
                $
                0.00
                 
                USD
              </div>
              <p
                class="sc-AnqlK fLVAuQ"
                title="Price in Local Currency"
              >
                1 
                XEC
                 = 
                0.00003000
                 
                USD
              </p>
            </div>
          </div>
          <div
            class="sc-dTLGrV eQoClh"
          >
            <div
              class="sc-fjhmcy ezvQuX"
            >
              <h2>
                Token Offers
              </h2>
              <div>
                Sort by:
                <div
                  class="sc-lnmtFM jhgFyV"
                  title="Sort by TokenId"
                >
                  TokenID
                </div>
                <div
                  class="sc-lnmtFM gKgeIQ"
                  disabled=""
                  title="Sort by Offer Count"
                >
                  Offers
                  <div>
                    <div
                      class="sc-jzJRlG eQTBdJ"
                      title="Loading OrderBook info..."
                    >
                      <div />
                      <div />
                      <div />
                      <div />
                    </div>
                  </div>
                </div>
                <span
                  class="sc-hwcHae deuxbw"
                  title="Toggle Active Offers"
                >
                  My Lis...
    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.js:999:26)

Each failure log is accessible here:
CashTab Unit Tests: <Agora /> We get expected error if we try to buy an offer we cannot afford

bytesofman published this revision for review.Mon, Mar 3, 19:24
bytesofman added inline comments.
cashtab/src/components/Agora/OrderBook/__tests__/index.test.tsx
557 ↗(On Diff #52892)

the txid is different because the mock wallet used in the test is different (utxo with more sats)

724 ↗(On Diff #52892)

we no longer test "we can't buy what we can't afford" -- because we now test a validation error and buy button disabled for this condition

892 ↗(On Diff #52892)

better ux vs "try and buy and get utxo error toast"

944 ↗(On Diff #52892)

no longer tested as we cannot try to buy what we can't afford, better UX

this is tested above

This revision is now accepted and ready to land.Tue, Mar 4, 00:26