-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make payout process more transparent (#2230)
* In progress * Genericize the components a little more * Animated icon fix * No manual * our -> on our * Commas * Proposed refactor
- Loading branch information
Cory McDonald
authored
Sep 23, 2019
1 parent
e764140
commit 3dac216
Showing
6 changed files
with
185 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
module PayoutHelper | ||
|
||
PREPARING = I18n.t('.publishers.payout_status.statuses.preparing') | ||
REVIEWING = I18n.t('.publishers.payout_status.statuses.reviewing') | ||
IN_PROGRESS = I18n.t('.publishers.payout_status.statuses.in_progress') | ||
DONE = I18n.t('.publishers.payout_status.statuses.done') | ||
|
||
def icon_class(statuses, current, index) | ||
selected = index <= statuses.find_index(current) | ||
|
||
return 'inactive' unless selected | ||
return "animated" if statuses[index] == current && current != I18n.t(".publishers.payout_status.statuses.done") | ||
|
||
"active" | ||
end | ||
|
||
def current_status_and_percent(report_created_at) | ||
status = nil | ||
progress_percentage = nil | ||
|
||
status = DONE if !Rails.cache.fetch('payout_in_progress') | ||
days_ago = (Date.today - report_created_at.to_date).to_i if status.blank? | ||
|
||
if days_ago < 3 | ||
status = PREPARING | ||
progress_percentage = days_ago / 3.to_f | ||
elsif days_ago < 7 | ||
status = REVIEWING | ||
progress_percentage = ((days_ago - 3.to_f) / 4) | ||
elsif days_ago < 11 | ||
status = IN_PROGRESS | ||
progress_percentage = (((days_ago - 7.to_f) / 4)) | ||
else | ||
progress_percentage = 1 | ||
status = DONE | ||
end | ||
|
||
[status, progress_percentage] | ||
end | ||
|
||
def percent_complete(created, selected_status, index) | ||
statuses = I18n.t(".publishers.payout_status.statuses").values | ||
selected = index <= statuses.find_index(selected_status) | ||
|
||
return 0 unless selected | ||
return current_status_and_percent(created).second if selected_status == statuses[index] | ||
100 | ||
end | ||
|
||
def payout_warning(payout_report) | ||
found_payout = payout_report.potential_payments.where(publisher: current_publisher).first | ||
|
||
return I18n.t('.publishers.payout_status.information.not_found') if found_payout.blank? | ||
|
||
if found_payout.uphold_status.blank? | ||
I18n.t('.publishers.payout_status.information.connect_uphold') | ||
elsif found_payout.reauthorization_needed | ||
I18n.t('.publishers.payout_status.information.reauthorize_uphold') | ||
elsif found_payout.uphold_member.blank? | ||
I18n.t('.publishers.payout_status.information.kyc_required') | ||
end | ||
end | ||
|
||
def payout_amount(payout_report) | ||
amount = payout_report.potential_payments. | ||
where(publisher: current_publisher). | ||
select(&:amount). | ||
map { |x| x.amount.to_d }. | ||
sum | ||
|
||
(amount / 1E18).round(2) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
.dashboard-panel--wrapper | ||
.dashboard-panel--header= t('.heading') | ||
div | ||
.d-flex | ||
= t('.amount') | ||
small * | ||
h4.font-weight-light | ||
span= payout_amount(payout_report) | ||
small.font-weight-light= " BAT" | ||
|
||
- payout_warning = payout_warning(payout_report) | ||
- if payout_warning | ||
.alert.alert-warning | ||
= payout_warning | ||
.font-weight-bold=t('.information.no_payment') | ||
|
||
- if payout_warning.blank? | ||
/ We're going to do some magic to make the user feel like things are actually happening | ||
.d-flex.my-3 | ||
- statuses = t('.statuses').values | ||
- current = current_status_and_percent(payout_report.created_at)[0] | ||
- statuses.each_with_index do |status, index| | ||
- last = index == (statuses.size - 1) | ||
- selected = status == current | ||
.payout-progress class=(last ? "" : "flex-grow-1") | ||
.icon class=icon_class(statuses, current, index) | ||
.px-2 class=(selected ? "" : "d-sm-block d-none") | ||
= status | ||
- unless last | ||
progress.connector value=percent_complete(payout_report.created_at, current, index) class=icon_class(statuses, current, index) | ||
|
||
.pt-2 | ||
= t('.description') | ||
|
||
|
||
.mt-4 | ||
small=t('.amount_description', time: payout_report.created_at.strftime("%Y-%m-%d")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters