Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
lightning-bits
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bitsoko services
lightning-bits
Commits
1e312620
Unverified
Commit
1e312620
authored
Aug 27, 2019
by
Tankred Hase
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement fee selection in payment action
parent
967e6cb9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
9 deletions
+54
-9
payment.js
src/action/payment.js
+43
-7
config.js
src/config.js
+3
-1
store.js
src/store.js
+8
-1
No files found.
src/action/payment.js
View file @
1e312620
...
...
@@ -7,9 +7,18 @@ import {
PREFIX_REGEX
,
PAYMENT_TIMEOUT
,
POLL_STORE_TIMEOUT
,
SEND_TARGET_CONF
,
LOW_TARGET_CONF
,
MED_TARGET_CONF
,
HIGH_TARGET_CONF
,
}
from
'../config'
;
import
{
toSatoshis
,
toAmount
,
isLnUri
,
isAddress
,
nap
}
from
'../helper'
;
import
{
toSatoshis
,
toAmount
,
toAmountLabel
,
isLnUri
,
isAddress
,
nap
,
}
from
'../helper'
;
import
*
as
log
from
'./log'
;
class
PaymentAction
{
...
...
@@ -105,6 +114,7 @@ class PaymentAction {
init
()
{
this
.
_store
.
payment
.
address
=
''
;
this
.
_store
.
payment
.
amount
=
''
;
this
.
_store
.
payment
.
targetConf
=
MED_TARGET_CONF
;
this
.
_store
.
payment
.
fee
=
''
;
this
.
_store
.
payment
.
note
=
''
;
this
.
_store
.
payment
.
useScanner
=
false
;
...
...
@@ -223,14 +233,40 @@ class PaymentAction {
* @return {Promise<undefined>}
*/
async
estimateFee
()
{
const
{
payment
}
=
this
.
_store
;
payment
.
feeEstimates
=
[];
await
this
.
_fetchEstimate
(
LOW_TARGET_CONF
,
'Low'
);
await
this
.
_fetchEstimate
(
MED_TARGET_CONF
,
'Med'
);
await
this
.
_fetchEstimate
(
HIGH_TARGET_CONF
,
'High'
);
payment
.
fee
=
payment
.
feeEstimates
[
1
].
fee
;
}
async
_fetchEstimate
(
targetConf
,
prio
)
{
const
{
payment
,
settings
}
=
this
.
_store
;
const
AddrToAmount
=
{};
AddrToAmount
[
payment
.
address
]
=
toSatoshis
(
payment
.
amount
,
settings
);
const
{
feeSat
}
=
await
this
.
_grpc
.
sendCommand
(
'estimateFee'
,
{
AddrToAmount
,
targetConf
:
SEND_TARGET_CONF
,
const
{
feeSat
,
feerateSatPerByte
}
=
await
this
.
_grpc
.
sendCommand
(
'estimateFee'
,
{
AddrToAmount
,
targetConf
,
}
);
payment
.
feeEstimates
.
push
({
targetConf
,
prio
,
satPerByte
:
feerateSatPerByte
,
fee
:
toAmount
(
feeSat
,
settings
),
feeLabel
:
toAmountLabel
(
feeSat
,
settings
),
});
payment
.
fee
=
toAmount
(
feeSat
,
settings
);
}
setTargetConf
({
targetConf
})
{
const
{
payment
}
=
this
.
_store
;
payment
.
targetConf
=
targetConf
;
payment
.
fee
=
payment
.
feeEstimates
.
find
(
e
=>
e
.
targetConf
===
targetConf
).
fee
;
}
/**
...
...
@@ -286,7 +322,7 @@ class PaymentAction {
await
this
.
_grpc
.
sendCommand
(
'sendCoins'
,
{
addr
:
payment
.
address
,
amount
,
targetConf
:
SEND_TARGET_CONF
,
targetConf
:
payment
.
targetConf
,
sendAll
:
payment
.
sendAll
,
});
}
...
...
src/config.js
View file @
1e312620
...
...
@@ -24,7 +24,9 @@ module.exports.PREFIX_URI = `${prefixName}:`;
module
.
exports
.
PREFIX_REGEX
=
/^
[
a-zA-Z
]
*:/
;
module
.
exports
.
DEFAULT_ROUTE
=
'Welcome'
;
module
.
exports
.
SEND_TARGET_CONF
=
6
;
module
.
exports
.
LOW_TARGET_CONF
=
26
;
module
.
exports
.
MED_TARGET_CONF
=
16
;
module
.
exports
.
HIGH_TARGET_CONF
=
4
;
module
.
exports
.
PIN_LENGTH
=
6
;
module
.
exports
.
MIN_PASSWORD_LENGTH
=
8
;
module
.
exports
.
STRONG_PASSWORD_LENGTH
=
12
;
...
...
src/store.js
View file @
1e312620
...
...
@@ -14,7 +14,12 @@ import ComputedPayment from './computed/payment';
import
ComputedNotification
from
'./computed/notification'
;
import
ComputedSetting
from
'./computed/setting'
;
import
ComputedSeed
from
'./computed/seed'
;
import
{
DEFAULT_ROUTE
,
DEFAULT_UNIT
,
DEFAULT_FIAT
}
from
'./config'
;
import
{
DEFAULT_ROUTE
,
DEFAULT_UNIT
,
DEFAULT_FIAT
,
MED_TARGET_CONF
,
}
from
'./config'
;
export
class
Store
{
constructor
()
{
...
...
@@ -69,6 +74,8 @@ export class Store {
payment
:
{
address
:
''
,
amount
:
''
,
targetConf
:
MED_TARGET_CONF
,
feeEstimates
:
[],
fee
:
''
,
note
:
''
,
sendAll
:
false
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment