-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDepositRequestsList.hs
executable file
·114 lines (103 loc) · 4.17 KB
/
DepositRequestsList.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeFamilies #-}
module Handler.Operator.DepositRequestsList where
import Import as I hiding ( on, (==.) )
import Local.Persist.Currency ( currencySymbol )
import Local.Persist.TransferMethod ( tmTShort )
import Local.Persist.Wallet ( DepositRequestStatus (..) )
import Utils.Common ( selectLocale )
import Utils.Deposit
import Utils.Money
import Utils.Render
import Utils.Time
import Database.Esqueleto as E
import Database.Persist.Sql ( fromSqlKey )
getOperatorDepositRequestsListR :: Handler Html
getOperatorDepositRequestsListR = do
requireOperatorId
loc <- selectLocale
tzo <- timezoneOffsetFromCookie
let reqDateT = renderTimeDateCol loc tzo . depositRequestCreated
renderUrl <- getUrlRender
list <- runDB selectData
let reactBuild =
#ifdef DEVELOPMENT
"development"
#else
"production.min"
#endif
defaultLayout $ do
addScriptRemote $
"https://unpkg.com/react@16/umd/react." <> reactBuild <> ".js"
addScriptRemote $
"https://unpkg.com/react-dom@16/umd/react-dom."
<> reactBuild
<> ".js"
$(widgetFile "operator/common")
$(widgetFile "operator/request-list-common")
$(widgetFile "operator/deposit-requests-list")
addScriptAttrs (StaticR js_bundle_js) []
where
selectData = select $ from $ \(depReq `LeftOuterJoin` addr, wlt, usr) -> do
on (addr ?. DepositPayerDeposit ==. just (depReq ^. DepositRequestId))
where_ (
(depReq ^. DepositRequestStatus ==. val ClientConfirmed)
&&. (depReq ^. DepositRequestArchived ==. val False)
&&. (depReq ^. DepositRequestUserId ==. usr ^. UserId)
&&. (depReq ^. DepositRequestCurrency ==. wlt ^. UserWalletCurrency)
&&. (wlt ^. UserWalletUserId ==. usr ^. UserId) )
orderBy [ asc (depReq ^. DepositRequestCreated) ]
return (depReq, wlt, usr, addr)
renderSums :: DepositRequest -> Html
renderSums req@DepositRequest{..} =
let iC = currencySymbol depositRequestCurrency
tC = currencySymbol depositRequestTargetCurrency
ratio = 1
ratioT = renderRequestRatio req
reqAmt = depositRequestCentsAmount
reqAmtT = cents2dblT reqAmt
feeAmt = calcFeeCents (selectDepositFee depositRequestCurrency) reqAmt
feeAmtT = cents2dblT feeAmt
depAmt = multiplyCents ratio (reqAmt - feeAmt)
depAmtT = cents2dblT depAmt
in [shamlet|
<b>#{reqAmtT} #{iC} #
<small>(-#{feeAmtT} #{iC})
<br>
<small>
#{depAmtT} #{tC} #
<small>(x#{ratioT})
|]
renderRequestRatio :: DepositRequest -> Html
renderRequestRatio DepositRequest{..} =
let ratio = 1 -- selectRatio depositRequestCurrency depositRequestTargetCurrency
ratioT = cents2dblT . truncCoins2Cents $ ratio
in [shamlet|#{ratioT}|]
renderMethodUser :: DepositRequest -> Entity User -> Html
renderMethodUser req (Entity userId user) = [shamlet|
#{tmTShort (depositRequestTransferMethod req)}
<br>
<small>
<a
.user-profile-link
target=_blank
href="/operator/user-history/#{fromSqlKey userId}">
#{userIdent user}|]
renderRequestExpectedTotal :: DepositRequest -> Html
renderRequestExpectedTotal DepositRequest{..} = [shamlet|#{cents2dblT total}|]
where
total =
multiplyCents
depositRequestExpectedConversionRatio
(depositRequestCentsAmount - depositRequestExpectedFeeCents)
renderReqFeeAsPct :: DepositRequest -> Html
renderReqFeeAsPct DepositRequest{..} = renderFeeAsPct fee
where
fee = selectDepositFee depositRequestCurrency
renderReqFeeAsDbl :: DepositRequest -> Html
renderReqFeeAsDbl DepositRequest{..} = renderFeeAsDbl fee
where
fee = selectDepositFee depositRequestCurrency