web icon indicating copy to clipboard operation
web copied to clipboard

ChainAdapters: Add isAccountTypeRequired() to API

Open asamere opened this issue 3 years ago • 1 comments

Overview

By adding an isAccountTypeRequired() function to the ChainAdapter interface we will be able to avoid ChainNamespace switching in web (chain type/family/whatever). In general we should avoid any switching on chain implementations in the UI layer.

In web code we go from:

if (CHAIN_NAMESPACE.Utxo === asset.chainId && !accountType) return { ... }

to:

if (chainAdapter.isAccountTypeRequired() && !accountType) return

References and additional details

ReceiveInfo.tsx is a place to look

Acceptance Criteria

  • the ChainAdapters interface exposes a new function with signature isAccountTypeRequired() bool
  • all ChainAdapters implement the new function
    • utxo adapters return true
    • others return false

Need By Date

No response

Screenshots/Mockups

No response

Estimated effort

No response

asamere avatar Sep 06 '22 20:09 asamere

What about making consumers aware of the exact account type with a generic e.g ChainNamespace, so that the presence of accountType can be inferred by the compiler instead of needing runtime checks?

See e.g GetAddressInput for UTXOs:

https://github.com/shapeshift/lib/blob/cfd28ee08c22be19069c5b88d025deb5fc699cef/packages/chain-adapters/src/utxo/types.ts#L19-L21

It wrongly has accountType as optional, but suppose it was required, we should just be able to narrow types down to this specific GetAddressInput

gomesalexandre avatar Sep 27 '22 20:09 gomesalexandre

closing this as the type system enforces this for the UtxoBaseAdapter https://github.com/shapeshift/lib/blob/main/packages/chain-adapters/src/utxo/UtxoBaseAdapter.ts#L229 and it's not an ergonomic issue

0xdef1cafe avatar Nov 07 '22 18:11 0xdef1cafe