paxful_engine-rails 0.1.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e703f7e6fbaf90b7f85cdb26beaf05aa92590fb7f42145c3177870ddffae27c
4
- data.tar.gz: e6029b79a03f1acfee4310b6ae788710836c995dfb0a6a9a51bd2c2ebf448174
3
+ metadata.gz: fb90688726d3d85a6c9f1b0e243955f3977f11483d41886b0ccf43b15dcc4b6e
4
+ data.tar.gz: 16de8f670bfdb81d21d3bc0b0e1ff94bb4f7ca0811c0d91d3b714b6ceb0f73d0
5
5
  SHA512:
6
- metadata.gz: 65344157341d2356b8efde3f789a0a2561cbf4283c252888bd826465d7b64df2e92587061913ef2c302ed5d5e0131b9031f9752caa70031b5cce9fc901f22791
7
- data.tar.gz: bed2766b448c783a849a78f6fc069c8f1c0d3822981bbf63a0aa7ffad78ed4c179cc84b0a82e6a84ad57c70605aa55fa1cba5ba30110b1191dadb1e1a5ce517f
6
+ metadata.gz: b64b219d335b96a57d8419730947f12e1723f9a88e70d9019f9c4f6d763e94406e87d571fef4be875242d0440459322d4d7e14a2db3be481470ef3e8b0b606c1
7
+ data.tar.gz: 914858b8aeb7cc2d15260d8e62d2971aff81cda741bc176c69fc62c6c184d21bb38093c68d6544134054651e64b0324988b1f5bf76144a8758b5aec776cf6dd7
data/README.md CHANGED
@@ -34,7 +34,8 @@ Create an initializer in your Rails application:
34
34
  PaxfulEngine.configure do |c|
35
35
  c.paxful_key = "your paxful key"
36
36
  c.paxful_secret = "your paxful secret"
37
- c.on_sync_callback = "YourCallback"
37
+ c.on_sync_callback = "SyncCallback"
38
+ c.on_failure_callback = "FailureCallback"
38
39
  end
39
40
  ```
40
41
 
@@ -45,7 +46,7 @@ It accepts a `Trade` as its only argument.
45
46
 
46
47
  ```
47
48
  # example
48
- class YourCallback
49
+ class SyncCallback
49
50
 
50
51
  def self.call(trade)
51
52
  # do anything you want with this record
@@ -54,6 +55,39 @@ class YourCallback
54
55
  end
55
56
  ```
56
57
 
58
+ #### c.on_failure_callback
59
+
60
+ An object that responds to `call` that gets executed when a trade cannot be created.
61
+
62
+ It accepts two arguments:
63
+ - exception
64
+ - payload
65
+
66
+ ```
67
+ # example
68
+ class FailureCallback
69
+
70
+ def self.call(e, payload)
71
+ # log somewhere...
72
+ end
73
+
74
+ end
75
+ ```
76
+
77
+ ### Usage
78
+
79
+ Add this to your scheduler somewhere:
80
+ ```
81
+ # sidekiq_cron.yml
82
+ refresh_paxful_order_book:
83
+ cron: "*/2 * * * * Asia/Singapore" # runs every 2 minutes
84
+ class: "PaxfulEngine::SyncOrderBookJob"
85
+ ```
86
+
87
+ From the host app:
88
+ - Check list of trades at `/paxful_engine/trades`.
89
+ - Details per trade at `/paxful_engine/trades/:id`.
90
+
57
91
  ### Development
58
92
 
59
93
  ```
@@ -0,0 +1,13 @@
1
+ module PaxfulEngine
2
+ class TradesController < ApplicationController
3
+
4
+ def index
5
+ @trades = Trade.all
6
+ end
7
+
8
+ def show
9
+ @trade = Trade.find(params[:id])
10
+ end
11
+
12
+ end
13
+ end
@@ -1,4 +1,10 @@
1
1
  module PaxfulEngine
2
2
  module ApplicationHelper
3
+
4
+ def highlight_status(trade)
5
+ status = trade.status.downcase
6
+ status == "successful" ? "text-success" : "text-danger"
7
+ end
8
+
3
9
  end
4
10
  end
@@ -17,5 +17,17 @@ module PaxfulEngine
17
17
  presence: true
18
18
  )
19
19
 
20
+ def successful?
21
+ status.downcase == "successful"
22
+ end
23
+
24
+ def buy?
25
+ offer_type.downcase == "buy"
26
+ end
27
+
28
+ def sell?
29
+ offer_type.downcase == "sell"
30
+ end
31
+
20
32
  end
21
33
  end
@@ -24,6 +24,12 @@ module PaxfulEngine
24
24
  end
25
25
 
26
26
  trade
27
+
28
+ rescue => exception
29
+ if PaxfulEngine.configuration.on_failure_callback.present?
30
+ callback = PaxfulEngine.configuration.on_failure_callback
31
+ callback.constantize.(exception, payload)
32
+ end
27
33
  end
28
34
 
29
35
  end
@@ -1,15 +1,22 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
- <title>Paxful engine</title>
4
+ <title>Paxful Engine</title>
5
5
  <%= csrf_meta_tags %>
6
6
  <%= csp_meta_tag %>
7
7
 
8
- <%= stylesheet_link_tag "paxful_engine/application", media: "all" %>
8
+ <%= stylesheet_link_tag "paxful_engine/application", media: "all" %>
9
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
9
10
  </head>
10
11
  <body>
11
12
 
12
- <%= yield %>
13
+ <nav class="navbar navbar-dark bg-dark">
14
+ <%= link_to "Paxful Trades", paxful_engine.trades_path, class: "navbar-brand" %>
15
+ </nav>
16
+
17
+ <div class="mt-4 mb-4 container-fluid">
18
+ <%= yield %>
19
+ </div>
13
20
 
14
21
  </body>
15
22
  </html>
@@ -0,0 +1,39 @@
1
+ <span class="font-weight-bold"> Found <%= pluralize(@trades.count, "trade") %></span>
2
+ <hr />
3
+
4
+ <div class="table-responsive">
5
+ <table class="table table-striped table-bordered">
6
+ <thead>
7
+ <tr>
8
+ <th scope="col">Created</th>
9
+ <th scope="col">Trade hash</th>
10
+ <th scope="col">Type</th>
11
+ <th scope="col">Status</th>
12
+ <th scope="col">Seller</th>
13
+ <th scope="col">Buyer</th>
14
+ <th scope="col"></th>
15
+ </tr>
16
+ </thead>
17
+ <tbody>
18
+ <% if @trades.empty? %>
19
+ <tr>
20
+ <td colspan="7"> No trades found </td>
21
+ </tr>
22
+ <% end %>
23
+
24
+ <% @trades.each do |trade| %>
25
+ <tr scope="row">
26
+ <td> <%= trade.created_at.strftime("%m/%d/%Y %I:%M%p") %> </td>
27
+ <td> <%= trade.trade_hash %> </td>
28
+ <td> <%= trade.offer_type.upcase %> </td>
29
+ <td>
30
+ <span class="<%= highlight_status(trade) %>"> <%= trade.status.upcase %> </span>
31
+ </td>
32
+ <td> <%= trade.seller %> </td>
33
+ <td> <%= trade.buyer %> </td>
34
+ <td> <%= link_to "Check trade details", paxful_engine.trade_path(trade) %> </td>
35
+ </tr>
36
+ <% end %>
37
+ </tbody>
38
+ </table>
39
+ </div>
@@ -0,0 +1,46 @@
1
+ <%= link_to "Back", paxful_engine.trades_path, class: "btn btn-primary" %>
2
+
3
+ <div class="row">
4
+ <div class="col-sm-4">
5
+ <div class="card mt-4">
6
+ <h5 class="card-header">Trade details (<%= @trade.trade_hash %>)</h5>
7
+ <div class="card-body">
8
+ <div>
9
+ <div> <strong>Seller:</strong> <%= @trade.seller %> </div>
10
+ <div> <strong>Buyer:</strong> <%= @trade.buyer %> </div>
11
+ <div> <strong>Type:</strong> <%= @trade.offer_type.upcase %> </div>
12
+ </div>
13
+
14
+ <hr />
15
+
16
+ <div>
17
+ <div>
18
+ <strong>Fiat Requested:</strong>
19
+ <%= number_to_currency(@trade.fiat_amount_requested, unit: "#{@trade.fiat_currency_code} ") %>
20
+ </div>
21
+ <div>
22
+ <strong>Crypto Requested:</strong>
23
+ <%= number_to_currency(@trade.crypto_amount_requested, unit: "#{@trade.crypto_currency_code} ") %>
24
+ (in sats)
25
+ </div>
26
+ </div>
27
+
28
+ <hr />
29
+
30
+ <div>
31
+ <div> <strong>Started at:</strong> <%= @trade.started_at.strftime("%m/%d/%Y %I:%M%p") %> </div>
32
+ <div> <strong>Ended at:</strong> <%= @trade.ended_at.strftime("%m/%d/%Y %I:%M%p") %> </div>
33
+ <div> <strong>Completed at:</strong> <%= @trade.completed_at&.strftime("%m/%d/%Y %I:%M%p") %> </div>
34
+ </div>
35
+
36
+ <hr />
37
+
38
+ <div>
39
+ <strong>Status:</strong>
40
+ <span class="<%= highlight_status(@trade) %>"> <%= @trade.status.upcase %> </span>
41
+ </div>
42
+ <div> <strong>Payment Method:</strong> <%= @trade.payment_method_name %> </div>
43
+ </div>
44
+ </div>
45
+ </div>
46
+ </div>
@@ -1,2 +1,3 @@
1
1
  PaxfulEngine::Engine.routes.draw do
2
+ resources :trades, only: [:index, :show]
2
3
  end
@@ -12,6 +12,7 @@ module PaxfulEngine
12
12
  has :paxful_key, classes: [NilClass, String]
13
13
  has :paxful_secret, classes: [NilClass, String]
14
14
  has :on_sync_callback
15
+ has :on_failure_callback
15
16
  end
16
17
 
17
18
  end
@@ -1,3 +1,3 @@
1
1
  module PaxfulEngine
2
- VERSION = '0.1.0'
2
+ VERSION = '0.5.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paxful_engine-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Chavez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-20 00:00:00.000000000 Z
11
+ date: 2020-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_config
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '2.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: factory_bot
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: pry
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -163,6 +177,7 @@ files:
163
177
  - app/assets/config/paxful_engine_manifest.js
164
178
  - app/assets/stylesheets/paxful_engine/application.css
165
179
  - app/controllers/paxful_engine/application_controller.rb
180
+ - app/controllers/paxful_engine/trades_controller.rb
166
181
  - app/helpers/paxful_engine/application_helper.rb
167
182
  - app/jobs/paxful_engine/application_job.rb
168
183
  - app/jobs/paxful_engine/enqueue_create_trade_job.rb
@@ -172,6 +187,8 @@ files:
172
187
  - app/models/paxful_engine/trade.rb
173
188
  - app/services/paxful_engine/create_trade.rb
174
189
  - app/views/layouts/paxful_engine/application.html.erb
190
+ - app/views/paxful_engine/trades/index.html.erb
191
+ - app/views/paxful_engine/trades/show.html.erb
175
192
  - config/routes.rb
176
193
  - db/migrate/20201018043517_create_paxful_engine_trades.rb
177
194
  - lib/paxful_engine-rails.rb