Page MenuHomePhabricator

[Cashtab] Improve price precision for Agora spot prices
ClosedPublic

Authored by bytesofman on Tue, Dec 31, 19:23.

Details

Reviewers
emack
Group Reviewers
Restricted Project
Commits
rABC90306ee11482: [Cashtab] Improve price precision for Agora spot prices
Summary

Improve how we calculate and present spot prices for Agora offers in fiat and XEC

We want to render with appropriate significant figures. Because Agora offers may have very small unit prices, render with at least 4 places of precision, if applicable. (For example this is not applicable if we render the smallest unit price, 1 nanosatoshi, which is pointless to render with 3 more decimal places).

We render xec or fiat values greater than 1 with 2 decimal places (XEC has 2 places, this is a common decimal for fiat currencies...mb the only one).

We split out the logic for getting a formatted XEC price so that we can appropriately distinguish appropriate significant figures for XEC and fiat. Also we can directly call to get XEC prices, instead of force-calling getFormattedFiatPrice with null to mimic a failed API call as was done in some locations.

Update tests to confirm new expected behavior.

Test Plan

npm test

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Failed tests logs:

====== CashTab Unit Tests: <Token /> available actions rendered We can list an SLP1 fungible token ======
TestingLibraryElementError: Unable to find an element with the text: 0.50 XEC ($0.000015 USD) per token. 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-eitiEO jtKsEs"
    >
      <div
        class="Toastify"
      />
      <div
        class="sc-bhlBdH kUtPuC"
      >
        <div
          class="sc-AnqlK jwdJGM"
        >
          <div
            class="sc-hycgNl fMlaSZ"
          >
            <img
              alt="cashtab"
              class="sc-chAAoq dvNFPG"
              src="test-file-stub"
            />
          </div>
          <div
            class="sc-cCbXAZ hWVbsV"
          >
            <div
              class="sc-gGCbJM jirjPV"
            >
              <select
                class="sc-lcpuFF fKLrbw"
                data-testid="wallet-select"
                id="wallets"
                name="wallets"
              >
                <option
                  class="sc-bqjOQT hQomri"
                  value="Token Test"
                >
                  Token Test
                </option>
              </select>
              <div
                class="sc-ciodno khxwxx"
              >
                <button
                  aria-label="Copy ecash:qqq9f9z3uhpzkxrgdjkd7dxuuey7tmpmugpmnw0kue"
                  class="sc-ksYbfQ ikvLXx"
                >
                  <svg
                    title="copy-paste"
                  />
                </button>
                <div
                  class="sc-emmjRN fIvjCD"
                >
                  <div
                    class="sc-cpmLhU kUbYwU"
                  >
                    <input
                      checked=""
                      class="sc-fhYwyz jqalqV"
                      id="show-hide-balance"
                      name="show-hide-balance"
                      title="show-hide-balance"
                      type="checkbox"
                    />
                    <label
                      class="sc-dymIpo naeFY"
                      for="show-hide-balance"
                    >
                      <span
                        class="sc-bnXvFD ygHZL"
                        data-off=""
                        data-on=""
                      />
                      <span
                        class="sc-gFaPwZ gQTsnN"
                      />
                    </label>
                  </div>
                </div>
              </div>
            </div>
            <div
              class="sc-fHSTwm exyNVL"
              title="Wallet Info"
            >
              <div
                class="sc-jkCMRl bMctXd"
                title="Balance in XEC"
              >
                9,970.81
                 
                XEC
                 
              </div>
              <div
                class="sc-crNyjn hVKMSK"
                title="Balance in Local Currency"
              >
                $
                0.30
                 
                USD
              </div>
              <p
                class="sc-cpHetk cyTyLD"
                title="Price in Local Currency"
              >
                1 
                XEC
                 = 
                0.00003000
                 
                USD
              </p>
            </div>
          </div>
          <div
            class="sc-jvEmr ePAtrN"
          >
            <div
              class="sc-giadOv fyRAOR"
            >
              <div
                class="sc-hIVACf kTXUZl"
              >
                111.000000000
                 
                Vespene Gas (VSP)
              </div>
              <div
                class="sc-qrIAp heBwb"
                title="Token Stats"
              >
                <div
                  class="sc-ipZHIp dIEugn"
                >
                  <button
                    class="sc-hmXxxW eOeYde"
                  >
                    <img
                      alt="icon for 20a0b9337a78603c6681ed2bc541593375535dcd9979196620ce71f233f2f6f8"
                      height="128"
                      src="https://icons.etokens.cash/128/20a0b9337a78603c6681ed2bc541593375535dcd9979196620ce71f233f2f6f8.png"
                      width="128"
                    />
                  </button>
                </div>
                <div
                  class="sc-ipZHIp dIEugn"
                >
                  <div
                    class="sc-bmyXtO dKilMS"
                  >
                    <div
                      class="sc-dEoRIm bMPee"
                    >
                      Type:
                    </div>
                    <div
                      class="sc-ipZHIp dIEugn"
                    >
                      <div
                        class="sc-ipXKqB sjWry"
                      >
                        SLP
                         
                        <button
             ...
    at Object.getElementError (/work/cashtab/node_modules/@testing-library/dom/dist/config.js:37:19)
    at /work/cashtab/node_modules/@testing-library/dom/dist/query-helpers.js:76:38
    at /work/cashtab/node_modules/@testing-library/dom/dist/query-helpers.js:52:17
    at /work/cashtab/node_modules/@testing-library/dom/dist/query-helpers.js:95:19
    at Object.getByText (/work/cashtab/src/components/Etokens/__tests__/TokenActions.test.js:308:20)
====== CashTab Unit Tests: <Token /> available actions rendered We can list an ALP fungible token ======
TestingLibraryElementError: Unable to find an element with the text: 33.00 XEC ($0.00099 USD) per token. 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-eitiEO jtKsEs"
    >
      <div
        class="Toastify"
      />
      <div
        class="sc-bhlBdH kUtPuC"
      >
        <div
          class="sc-AnqlK jwdJGM"
        >
          <div
            class="sc-hycgNl fMlaSZ"
          >
            <img
              alt="cashtab"
              class="sc-chAAoq dvNFPG"
              src="test-file-stub"
            />
          </div>
          <div
            class="sc-cCbXAZ hWVbsV"
          >
            <div
              class="sc-gGCbJM jirjPV"
            >
              <select
                class="sc-lcpuFF fKLrbw"
                data-testid="wallet-select"
                id="wallets"
                name="wallets"
              >
                <option
                  class="sc-bqjOQT hQomri"
                  value="Token Test"
                >
                  Token Test
                </option>
              </select>
              <div
                class="sc-ciodno khxwxx"
              >
                <button
                  aria-label="Copy ecash:qqq9f9z3uhpzkxrgdjkd7dxuuey7tmpmugpmnw0kue"
                  class="sc-ksYbfQ ikvLXx"
                >
                  <svg
                    title="copy-paste"
                  />
                </button>
                <div
                  class="sc-emmjRN fIvjCD"
                >
                  <div
                    class="sc-cpmLhU kUbYwU"
                  >
                    <input
                      checked=""
                      class="sc-fhYwyz jqalqV"
                      id="show-hide-balance"
                      name="show-hide-balance"
                      title="show-hide-balance"
                      type="checkbox"
                    />
                    <label
                      class="sc-dymIpo naeFY"
                      for="show-hide-balance"
                    >
                      <span
                        class="sc-bnXvFD ygHZL"
                        data-off=""
                        data-on=""
                      />
                      <span
                        class="sc-gFaPwZ gQTsnN"
                      />
                    </label>
                  </div>
                </div>
              </div>
            </div>
            <div
              class="sc-fHSTwm exyNVL"
              title="Wallet Info"
            >
              <div
                class="sc-jkCMRl bMctXd"
                title="Balance in XEC"
              >
                9,970.81
                 
                XEC
                 
              </div>
              <div
                class="sc-crNyjn hVKMSK"
                title="Balance in Local Currency"
              >
                $
                0.30
                 
                USD
              </div>
              <p
                class="sc-cpHetk cyTyLD"
                title="Price in Local Currency"
              >
                1 
                XEC
                 = 
                0.00003000
                 
                USD
              </p>
            </div>
          </div>
          <div
            class="sc-jvEmr ePAtrN"
          >
            <div
              class="sc-giadOv fyRAOR"
            >
              <div
                class="sc-hIVACf kTXUZl"
              >
                100.0000
                 
                Test CRD (tCRD)
              </div>
              <div
                class="sc-qrIAp heBwb"
                title="Token Stats"
              >
                <div
                  class="sc-ipZHIp dIEugn"
                >
                  <button
                    class="sc-hmXxxW eOeYde"
                  >
                    <img
                      alt="icon for 7cd7cd7c54167d306e770f972b564584c44cb412ee45839b4b97bb6e724c8849"
                      height="128"
                      src="https://icons.etokens.cash/128/7cd7cd7c54167d306e770f972b564584c44cb412ee45839b4b97bb6e724c8849.png"
                      width="128"
                    />
                  </button>
                </div>
                <div
                  class="sc-ipZHIp dIEugn"
                >
                  <div
                    class="sc-bmyXtO dKilMS"
                  >
                    <div
                      class="sc-dEoRIm bMPee"
                    >
                      Type:
                    </div>
                    <div
                      class="sc-ipZHIp dIEugn"
                    >
                      <div
                        class="sc-ipXKqB sjWry"
                      >
                        ALP
                         
                        <button
                    ...
    at Object.getElementError (/work/cashtab/node_modules/@testing-library/dom/dist/config.js:37:19)
    at /work/cashtab/node_modules/@testing-library/dom/dist/query-helpers.js:76:38
    at /work/cashtab/node_modules/@testing-library/dom/dist/query-helpers.js:52:17
    at /work/cashtab/node_modules/@testing-library/dom/dist/query-helpers.js:95:19
    at Object.getByText (/work/cashtab/src/components/Etokens/__tests__/TokenActions.test.js:1771:20)

Each failure log is accessible here:
CashTab Unit Tests: <Token /> available actions rendered We can list an SLP1 fungible token
CashTab Unit Tests: <Token /> available actions rendered We can list an ALP fungible token

correct preview implementation on token screen, update tests, clean up and clarify comments about precision levels

emack added a subscriber: emack.
emack added inline comments.
cashtab/src/formatting/fixtures/vectors.js
161 ↗(On Diff #51882)
This revision is now accepted and ready to land.Wed, Jan 1, 00:00