Skip to content

Commit

Permalink
chore: Execute a fund quote
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-stone committed Nov 18, 2024
1 parent 2b2ec63 commit a189a0d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/coinbase/fund_operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class << self
# @param asset_id [Symbol] The Asset ID of the Asset to send
# @return [FundOperation] The new pending FundOperation object
# @raise [Coinbase::ApiError] If the FundOperation fails
def create(wallet_id:, address_id:, amount:, asset_id:, network:)
def create(wallet_id:, address_id:, amount:, asset_id:, network:, quote: nil)
network = Coinbase::Network.from_id(network)
asset = network.get_asset(asset_id)

Expand All @@ -43,7 +43,8 @@ def create(wallet_id:, address_id:, amount:, asset_id:, network:)
{
amount: asset.to_atomic_amount(amount).to_i.to_s,
asset_id: asset.primary_denomination.to_s,
}
fund_quote_id: quote&.id
}.compact
)
end

Expand Down
20 changes: 20 additions & 0 deletions lib/coinbase/fund_quote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ def id
@model.fund_quote_id
end

# Creates a fund operation using the quote.
# @return [Coinbase::FundOperation] The FundOperation object
# @raise [Coinbase::ApiError] If the FundOperation fails
def execute!
FundOperation.create(
wallet_id: wallet_id,
address_id: address_id,
amount: amount.amount,
asset_id: asset.asset_id,
network: network.id,
quote: self
)
end

# Returns the Network of the FundOperatoin.
# @return [Coinbase::Network] The Network
def network
Expand Down Expand Up @@ -131,5 +145,11 @@ def to_s
def inspect
to_s
end

private

def fund_api
@fund_api ||= Coinbase::Client::FundApi.new(Coinbase.configuration.api_client)
end
end
end

0 comments on commit a189a0d

Please sign in to comment.