Skip to content

Commit

Permalink
Dynamic models, controllers, routes, and code itself for currencies (c…
Browse files Browse the repository at this point in the history
…loses openware#646)
  • Loading branch information
yivo committed Mar 15, 2018
1 parent 058b38e commit a2db46e
Show file tree
Hide file tree
Showing 149 changed files with 642 additions and 1,918 deletions.
Expand Up @@ -15,8 +15,7 @@ app.controller 'DepositHistoryController', ($scope, $stateParams, $http) ->
$scope.$apply()

@cancelDeposit = (deposit) ->
deposit_channel = DepositChannel.findBy('currency', deposit.currency)
$http.delete("/deposits/#{deposit_channel.resource_name}/#{deposit.id}")
$http.delete("/deposits/#{$stateParams.currency}/#{deposit.id}")
.error (responseText) ->
$.publish 'flash', { message: responseText }

Expand Down
@@ -1,6 +1,7 @@
app.controller 'DepositsController', ['$scope', '$stateParams', '$http', '$filter', '$gon', 'ngDialog', ($scope, $stateParams, $http, $filter, $gon, ngDialog) ->
@deposit = {}
$scope.currency = $stateParams.currency
$scope.currencyTranslationLocals = currency: $stateParams.currency.toUpperCase()
$scope.current_user = current_user = $gon.user
$scope.name = current_user.name
$scope.bank_details_html = $gon.bank_details_html
Expand Down
Expand Up @@ -18,8 +18,7 @@ app.controller 'WithdrawHistoryController', ($scope, $stateParams, $http) ->
['submitting', 'submitted', 'accepted'].indexOf(state) > -1

@cancelWithdraw = (withdraw) ->
withdraw_channel = WithdrawChannel.findBy('currency', withdraw.currency)
$http.delete("/withdraws/#{withdraw_channel.resource_name}/#{withdraw.id}")
$http.delete("/withdraws/#{$stateParams.currency}/#{withdraw.id}")
.success ->
location.reload()
.error (responseText) ->
Expand Down
Expand Up @@ -7,6 +7,7 @@ app.controller 'WithdrawsController', ['$scope', '$stateParams', '$http', '$gon'
return false

$scope.currency = currency = $stateParams.currency
$scope.currencyTranslationLocals = currency: currency.toUpperCase()
$scope.current_user = current_user = $gon.user
$scope.account = Account.findBy('currency', $scope.currency)
$scope.balance = $scope.account.balance
Expand Down Expand Up @@ -43,13 +44,11 @@ app.controller 'WithdrawsController', ['$scope', '$stateParams', '$http', '$gon'

@withdraw = {}
@createWithdraw = (currency) ->
withdraw_channel = WithdrawChannel.findBy('currency', currency)
account = withdraw_channel.account()
data = { withdraw: { member_id: current_user.id, currency: currency, sum: @withdraw.sum, destination_id: _selectedFundSourceId } }

$('.form-submit > input').attr('disabled', 'disabled')

$http.post("/withdraws/#{withdraw_channel.resource_name}", data)
$http.post("/withdraws/#{currency}", data)
.success ->
location.reload()
.error (responseText) ->
Expand Down
@@ -1,5 +1,5 @@
class DepositChannel extends PeatioModel.Model
@configure 'DepositChannel', 'key', 'currency', 'min_confirm', 'max_confirm', 'bank_accounts', 'resource_name'
@configure 'DepositChannel', 'currency', 'min_confirm', 'max_confirm'

@initData: (records) ->
PeatioModel.Ajax.disable ->
Expand Down
9 changes: 1 addition & 8 deletions app/assets/javascripts/funds/models/withdraw.js.coffee
Expand Up @@ -14,13 +14,6 @@ class Withdraw extends PeatioModel.Model
afterScope: ->
"#{@pathName()}"

pathName: ->
switch @currency
when gon.fiat_currency then 'banks'
when 'btc' then 'satoshis'
when 'xrp' then 'ripples'
when 'ltc' then 'litoshis'
when 'bch' then 'bitcoin_cash'
when 'dash' then 'duffs'
pathName: -> @currency

window.Withdraw = Withdraw
@@ -1,5 +1,5 @@
class WithdrawChannel extends PeatioModel.Model
@configure 'WithdrawChannel', 'key', 'currency', 'resource_name'
@configure 'WithdrawChannel', 'currency'

@initData: (records) ->
PeatioModel.Ajax.disable ->
Expand Down
6 changes: 0 additions & 6 deletions app/assets/stylesheets/features/funds.scss
Expand Up @@ -88,12 +88,6 @@
padding: 3px 10px;
border-radius: 3px;
background-color: #333;
&.label-fiat {
background-color: #EC6060;
}
&.label-btc {
background-color: #DDCD1B;
}
}
.currency-left {
text-align: center;
Expand Down
6 changes: 1 addition & 5 deletions app/assets/stylesheets/market.scss
Expand Up @@ -624,11 +624,7 @@ header {
tr { display: none; }
&.all { tr { display: block; } }
&.fiat { tr.quote-fiat { display: block; } }
&.btc { tr.quote-btc { display: block; } }
&.xrp { tr.quote-xrp { display: block; } }
&.bch { tr.quote-bch { display: block; } }
&.ltc { tr.quote-ltc { display: block; } }
&.dash { tr.quote-dash { display: block; } }
&.coin { tr.quote-coin { display: block; } }
}
}
}
Expand Down
60 changes: 0 additions & 60 deletions app/controllers/admin/deposits/banks_controller.rb

This file was deleted.

15 changes: 9 additions & 6 deletions app/controllers/admin/deposits/base_controller.rb
@@ -1,13 +1,16 @@
require_dependency 'admin/base_controller'

module Admin
module Deposits
class BaseController < ::Admin::BaseController
def channel
@channel ||= DepositChannel.find_by_key(self.controller_name.singularize)
end
class BaseController < BaseController

protected

def kls
channel.kls
def currency
Currency.where(type: self.class.name.demodulize.underscore.gsub(/_controller\z/, '').singularize)
.find_by_code!(params[:currency])
end
helper_method :currency
end
end
end
7 changes: 0 additions & 7 deletions app/controllers/admin/deposits/bitcoin_cash_controller.rb

This file was deleted.

20 changes: 7 additions & 13 deletions app/controllers/admin/deposits/coins_controller.rb
Expand Up @@ -4,25 +4,19 @@ module Admin
module Deposits
class CoinsController < BaseController
def index
@deposits = deposit_model.includes(:member)
.where('created_at > ?', 1.year.ago)
.order(id: :desc)
.page(params[:page])
.per(20)
@deposits = ::Deposits::Coin.where(currency: currency)
.includes(:member)
.where('created_at > ?', 1.year.ago)
.order(id: :desc)
.page(params[:page])
.per(20)
end

def update
deposit = deposit_model.find(params[:id])
deposit = ::Deposits::Coin.where(currency: currency).find(params[:id])
deposit.accept! if deposit.may_accept?
redirect_to :back, notice: t('admin.deposits.coins.update.notice')
end

private

def deposit_model
"::Deposits::#{self.class.name.demodulize.gsub(/Controller\z/, '').singularize}".constantize
end
helper_method :deposit_model
end
end
end
7 changes: 0 additions & 7 deletions app/controllers/admin/deposits/duffs_controller.rb

This file was deleted.

7 changes: 0 additions & 7 deletions app/controllers/admin/deposits/ethereums_controller.rb

This file was deleted.

54 changes: 54 additions & 0 deletions app/controllers/admin/deposits/fiats_controller.rb
@@ -0,0 +1,54 @@
require_dependency 'admin/deposits/base_controller'

module Admin
module Deposits
class FiatsController < BaseController
def index
q = ::Deposits::Fiat.where(currency: currency)
@latest_deposits = q.includes(:member).where('created_at <= ?', 1.day.ago).order('id DESC')
@all_deposits = q.includes(:member).where('created_at > ?', 1.day.ago).order('id DESC')
end

def new
@deposit = ::Deposits::Fiat.new
end

def show
@deposit = ::Deposits::Fiat.where(currency: currency).find(params[:id])
flash.now[:notice] = t('.notice') if @deposit.aasm_state.accepted?
end

def create
@deposit = ::Deposits::Fiat.new(deposit_params)
if @deposit.save
redirect_to admin_deposit_index_url(params[:currency])
else
flash[:alert] = @deposit.errors.full_messages.first
render :new
end
end

def update
@deposit = ::Deposits::Fiat.where(currency: currency).find(params[:id])
params = self.params.require(:deposits_fiat).permit(:txid)

if params[:txid].blank?
flash[:alert] = 'Transaction ID is blank!'
return redirect_to :back
end

@deposit.charge!(params[:txid])
redirect_to :back
end

private

def deposit_params
params.require(:deposits_fiat).slice(:sn, :amount, :fund_uid, :fund_extra, :currency)
.merge(currency: currency)
.permit!
end
end
end
end

7 changes: 0 additions & 7 deletions app/controllers/admin/deposits/litoshis_controller.rb

This file was deleted.

7 changes: 0 additions & 7 deletions app/controllers/admin/deposits/ripples_controller.rb

This file was deleted.

7 changes: 0 additions & 7 deletions app/controllers/admin/deposits/satoshis_controller.rb

This file was deleted.

40 changes: 0 additions & 40 deletions app/controllers/admin/deposits_controller.rb

This file was deleted.

0 comments on commit a2db46e

Please sign in to comment.