New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor method names and where asset, balance, and import logic lives #41
Conversation
This migrates the get_balance* calls to balance* to be more inline with standard ruby method naming, i.e. the method name should reflect what is being returned v.s. what the method is doing.
This removes the reference to the unused FaucetLimitReached error and updates docs to refer to the correct FaucetLimitReachedError
This enables you to import a wallet with the export data directly.
This migrates the balance map parsing off of the top-level Coinbase class and onto the Coinbase::BalanceMap class as a class method. This also exposes a `Coinbase::Balance` object for simple parsing of Coinbase::Client::Balances.
when :eth | ||
amount / BigDecimal(Coinbase::WEI_PER_ETHER.to_s) | ||
when :gwei | ||
amount / BigDecimal(Coinbase::GWEI_PER_ETHER.to_s) | ||
when :usdc | ||
amount / BigDecimal(Coinbase::ATOMIC_UNITS_PER_USDC.to_s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was not handling weth
properly here. Moving this logic to Coinbase::Asset
will allow us to more easily support more assets until we push this to the backend.
@@ -84,54 +117,31 @@ def default_address | |||
# Returns the Address with the given ID. | |||
# @param address_id [String] The ID of the Address to retrieve | |||
# @return [Address] The Address | |||
def get_address(address_id) | |||
def address(address_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one feels a bit weird to me since we're already exposing addresses
.
In what flow will someone have an on-chain address string that is associated with a wallet, where they already have the wallet in memory, and do not have a reference to the address object?
I suspect it might be more likely that they have an address
without a wallet and want to be able to search for it and return it if the user/project owns the wallet and address?
# frozen_string_literal: true | ||
|
||
module Coinbase | ||
# A representation of an Balance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of a Balance
or of an Asset Balance
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the difference in your opinion there? We can clarify it is an amount of a specific asset?
This makes it so that our fetches of the resource ID doesn't stutter with the class name. ```ruby wallet = Wallet.import(...) puts wallet.id ```
This consolidates the transforms around assets and balances to their respective classes, and moves them out of wallet and address. This also adds testing and fixes the handling for fetching balances of `weth` using `get_address_balance` and `get_wallet_balance` which was not handled properly. The `list_address_balances` and `list_wallet_balances` handling properly handled `weth`.
This makes it so that we return address.transfers instead of address.list_transfer_ids.
08cc6a5
to
7634f72
Compare
@@ -35,45 +35,32 @@ def wallet_id | |||
|
|||
# Returns the Address ID. | |||
# @return [String] The Address ID | |||
def address_id | |||
def id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we do the same for transfer_id?
@@ -15,7 +15,7 @@ def initialize(model) | |||
|
|||
# Returns the User ID. | |||
# @return [String] the User ID | |||
def user_id | |||
def id | |||
@model.id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also update reference in to_s
@@ -163,7 +163,7 @@ The below code demonstrates how to re-instantiate a Wallet from the data export. | |||
```ruby | |||
# The Wallet can be re-instantiated using the exported data. | |||
# w4 will be equivalent to w3. | |||
w4 = u.import_wallet(data) | |||
w4 = Coinbase::Wallet.import(data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update line 174 to w5 = wallets[w3.id]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make the README / example something that is actually evaluated?
This updates all model's fields and adds specs that test the inspect function to ensure we're evaluating those functions in test.
What changed? Why?
This renames some methods to be more idiomatic, e.g.
address.list_balances
=>address.balances
.This also moves the responsibility of some logic into the class that best represents the domain of that behavior.
user.import_wallet
=>Coinbase::Wallet.import
(the helper still exists, but logic belongs to Wallet).Coinbase.to_balance_map
=>Coinbase::BalanceMap.from_balances
Asset
.address.list_transfer_ids
=>address.transfers
.user.user_id
=>user.id
wallet.wallet_id
=>wallet.id
address.address_id
=>address.id
TODO:
whole
oratomic
units will allow us to not have to do any of this logic client side.Wallet.new
so we can leverage wallets in a state where we do not need a seed to be imported.Qualified Impact
This contains some breaking changes from v0.0.3.