Fix change profile name default (#2013)

* Fix default value for change profile name

* Partially fix set sell price dialog

* Fix itest in progress

* Fix get sell price
This commit is contained in:
Jonathan Zernik 2022-03-17 23:24:50 -07:00 committed by GitHub
parent a8ba458fad
commit fbc66c9813
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 58 additions and 182 deletions

View file

@ -46,7 +46,7 @@ const Nav = ({history}) => {
const [modalOpen, setModalOpen] = useState(false)
const [sellPriceModalOpen, setSellPriceModalOpen] = useState(false)
const [styleBody, setStyleBody] = useState(false)
const [newSellPriceMsat, setNewSellPriceMsat] = useState('')
const [newSellPriceMsat, setNewSellPriceMsat] = useState(0)
const session = true;
const sellPrice = useSelector(selectSellPriceInfo);
@ -114,6 +114,7 @@ const Nav = ({history}) => {
sellPriceMsat: newSellPriceMsat,
}
dispatch(setSellPrice(newSellPriceMsat));
setNewSellPriceMsat(0);
toggleSellPriceModal()
}
@ -253,11 +254,14 @@ const Nav = ({history}) => {
</div>
{sellPrice &&
<div className="modal-body">
<div className="edit-input-wrap">
Current Sell Price: {sellPrice.getPriceMsat() / 1000} sats
</div>
<form className="edit-form">
<div className="edit-input-wrap">
<div className="edit-input-content">
<label>Sell Price (msats)</label>
<input defaultValue={sellPrice.getPriceMsatIsSet() ? sellPrice.getPriceMsat() : sellPrice.getDefaultPriceMsat()} onChange={(e)=>setNewSellPriceMsat(e.target.value)} type="text" name="sellPrice" className="edit-input"/>
<label>New Sell Price (msats)</label>
<input value={newSellPriceMsat} onChange={(e)=>setNewSellPriceMsat(e.target.value)} type="text" name="sellPrice" className="edit-input"/>
</div>
</div>
</form>

View file

@ -243,6 +243,7 @@ const Profile = (props) => {
const handleMenuClick = (e) => { e.stopPropagation() }
console.log(user && user.getProfileName());
return(
<div>
@ -408,25 +409,14 @@ const Profile = (props) => {
</div>
</div>
</div>
{user ?
<form className="edit-form">
<div className="edit-input-wrap">
<div className="edit-input-content">
<label>Name</label>
<input defaultValue={user.getProfileName()} onChange={(e)=>setName(e.target.value)} type="text" name="name" className="edit-input"/>
</div>
</div>
</form> :
<form className="create-form">
<div className="create-input-wrap">
<div className="create-input-content">
<label>Name</label>
<input defaultValue={''} onChange={(e)=>setName(e.target.value)} type="text" name="name" className="edit-input"/>
</div>
</div>
</form>
}
</div>
</div>
</div>

View file

@ -180,30 +180,3 @@ def random_image():
@pytest.fixture
def random_image_base64_string(random_image):
yield bytes_to_base64_string(random_image)
# @pytest.fixture
# def connected_peer_id(other_admin_stub):
# # Add the main node as a peer
# create_peer_response = other_admin_stub.CreatePeer(
# squeak_admin_pb2.CreatePeerRequest(
# peer_name="test_peer",
# host="squeaknode",
# port=8774,
# )
# )
# peer_id = create_peer_response.peer_id
# # Set the peer to be downloading
# other_admin_stub.SetPeerDownloading(
# squeak_admin_pb2.SetPeerDownloadingRequest(
# peer_id=peer_id,
# downloading=True,
# )
# )
# yield peer_id
# # Delete the peer
# other_admin_stub.DeletePeer(
# squeak_admin_pb2.DeletePeerRequest(
# peer_id=peer_id,
# )
# )

View file

@ -70,23 +70,17 @@ def test_get_sell_price(admin_stub):
# Get the sell price
price = get_sell_price(admin_stub)
assert price.price_msat == 0
assert not price.price_msat_is_set
assert price.default_price_msat == 1000000
assert price.price_msat == 1000000
set_sell_price(admin_stub, 98765)
price = get_sell_price(admin_stub)
assert price.price_msat == 98765
assert price.price_msat_is_set
assert price.default_price_msat == 1000000
clear_sell_price(admin_stub)
price = get_sell_price(admin_stub)
assert price.price_msat == 0
assert not price.price_msat_is_set
assert price.default_price_msat == 1000000
assert price.price_msat == 1000000
def test_get_external_address(admin_stub):

View file

@ -1299,12 +1299,6 @@ message GetSellPriceRequest {
message GetSellPriceReply {
/// The price in msats
int64 price_msat = 1;
/// Price is set
bool price_msat_is_set = 2;
/// The default price in msats
int64 default_price_msat = 3;
}
message TwitterAccount {

View file

@ -1015,16 +1015,9 @@ class SqueakAdminServerHandler(object):
def handle_get_sell_price(self, request):
logger.info("Handle get sell price")
sell_price_msat = self.squeak_controller.get_sell_price_msat()
price_msat_is_set = sell_price_msat is not None
default_sell_price_msat = self.squeak_controller.get_default_sell_price_msat()
logger.info("sell price: {}".format(sell_price_msat))
logger.info("price_msat_is_set: {}".format(price_msat_is_set))
logger.info("default_sell_price_msat: {}".format(
default_sell_price_msat))
return squeak_admin_pb2.GetSellPriceReply(
price_msat=sell_price_msat,
price_msat_is_set=price_msat_is_set,
default_price_msat=default_sell_price_msat,
)
def handle_add_twitter_account(self, request):

View file

@ -1,60 +0,0 @@
# MIT License
#
# Copyright (c) 2020 Jonathan Zernik
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import logging
from typing import Optional
from squeaknode.config.config import SqueaknodeConfig
from squeaknode.core.peer_address import PeerAddress
from squeaknode.core.squeak_peer import SqueakPeer
from squeaknode.node.node_settings import NodeSettings
from squeaknode.node.squeak_store import SqueakStore
logger = logging.getLogger(__name__)
class PricePolicy:
def __init__(self, squeak_store: SqueakStore, config: SqueaknodeConfig, node_settings: NodeSettings):
# self.squeak_db = squeak_db
self.squeak_store = squeak_store
self.config = config
self.node_settings = node_settings
def get_price(self) -> int:
"""Get the price to sell this squeak to this peer.
"""
sell_price_msat = self.get_sell_price_msat()
if sell_price_msat is None:
return self.get_default_price()
return sell_price_msat
def get_peer(self, peer_address: PeerAddress) -> Optional[SqueakPeer]:
# return self.squeak_db.get_peer_by_address(peer_address)
return self.squeak_store.get_peer_by_address(peer_address)
def get_default_price(self) -> int:
return self.config.node.price_msat
def get_sell_price_msat(self) -> Optional[int]:
return self.node_settings.get_sell_price_msat()

View file

@ -30,6 +30,8 @@ from squeak.core.keys import SqueakPublicKey
from squeaknode.client.network_controller import NetworkController
from squeaknode.core.download_result import DownloadResult
from squeaknode.core.lightning_address import LightningAddressHostPort
from squeaknode.core.offer import Offer
from squeaknode.core.peer_address import Network
from squeaknode.core.peer_address import PeerAddress
from squeaknode.core.received_offer import ReceivedOffer
@ -129,6 +131,20 @@ class SqueakController:
)
return sent_payment_id
def get_packaged_offer(
self,
squeak_hash: bytes,
peer_address: PeerAddress,
price_msat: int,
lnd_external_address: Optional[LightningAddressHostPort],
) -> Optional[Offer]:
return self.squeak_store.get_packaged_offer(
squeak_hash,
peer_address,
price_msat,
lnd_external_address,
)
def decrypt_private_squeak(
self,
squeak_hash: bytes,
@ -144,8 +160,8 @@ class SqueakController:
def get_squeak(self, squeak_hash: bytes) -> Optional[CSqueak]:
return self.squeak_store.get_squeak(squeak_hash)
# def get_squeak_secret_key(self, squeak_hash: bytes) -> Optional[bytes]:
# return self.squeak_store.get_squeak_secret_key(squeak_hash)
def get_squeak_secret_key(self, squeak_hash: bytes) -> Optional[bytes]:
return self.squeak_store.get_squeak_secret_key(squeak_hash)
def delete_squeak(self, squeak_hash: bytes) -> None:
self.squeak_store.delete_squeak(squeak_hash)
@ -295,6 +311,20 @@ class SqueakController:
) -> List[SqueakEntry]:
return self.squeak_store.get_liked_squeak_entries(limit, last_entry)
def lookup_squeaks(
self,
public_keys: List[SqueakPublicKey],
min_block: Optional[int],
max_block: Optional[int],
reply_to_hash: Optional[bytes],
) -> List[bytes]:
return self.squeak_store.lookup_squeaks(
public_keys,
min_block,
max_block,
reply_to_hash,
)
def get_squeak_entries_for_public_key(
self,
public_key: SqueakPublicKey,
@ -423,8 +453,11 @@ class SqueakController:
def clear_sell_price_msat(self) -> None:
self.node_settings.clear_sell_price_msat()
def get_sell_price_msat(self) -> Optional[int]:
return self.node_settings.get_sell_price_msat()
def get_sell_price_msat(self) -> int:
configured_price = self.node_settings.get_sell_price_msat()
if configured_price is None:
return self.config.node.price_msat
return configured_price
def get_default_sell_price_msat(self) -> int:
return self.config.node.price_msat

View file

@ -180,7 +180,7 @@ class SqueakNode:
def create_peer_handler(self):
self.peer_handler = SqueakPeerServerHandler(
self.squeak_store,
self.squeak_controller,
self.node_settings,
self.config,
)

View file

@ -221,6 +221,7 @@ class SqueakStore:
self.save_sent_offer(sent_offer)
return sent_offer
# TODO: remove this method. Do this logic in squeakcontroller.
def get_packaged_offer(
self,
squeak_hash: bytes,

View file

@ -29,8 +29,7 @@ from squeaknode.core.lightning_address import LightningAddressHostPort
from squeaknode.core.offer import Offer
from squeaknode.core.peer_address import Network
from squeaknode.core.peer_address import PeerAddress
from squeaknode.node.price_policy import PricePolicy
from squeaknode.node.squeak_store import SqueakStore
from squeaknode.node.squeak_controller import SqueakController
logger = logging.getLogger(__name__)
@ -48,18 +47,18 @@ class SqueakPeerServerHandler(object):
def __init__(
self,
squeak_store: SqueakStore,
squeak_controller: SqueakController,
node_settings,
config,
):
self.squeak_store = squeak_store
self.squeak_controller = squeak_controller
self.node_settings = node_settings
self.config = config
def handle_get_squeak_bytes(self, squeak_hash_str) -> Optional[bytes]:
squeak_hash = bytes.fromhex(squeak_hash_str)
logger.info("Handle get squeak for hash: {}".format(squeak_hash_str))
squeak = self.squeak_store.get_squeak(squeak_hash)
squeak = self.squeak_controller.get_squeak(squeak_hash)
if not squeak:
raise NotFoundError()
return squeak.serialize()
@ -71,7 +70,7 @@ class SqueakPeerServerHandler(object):
price_msat = self.get_price_for_squeak()
if price_msat > 0:
raise PaymentRequiredError()
secret_key = self.squeak_store.get_squeak_secret_key(squeak_hash)
secret_key = self.squeak_controller.get_squeak_secret_key(squeak_hash)
if not secret_key:
raise NotFoundError()
return secret_key
@ -89,7 +88,7 @@ class SqueakPeerServerHandler(object):
price_msat = self.get_price_for_squeak()
if price_msat == 0:
raise NotFoundError()
# TODO: lnd_external_address should be configured inside SqueakStore.
# TODO: lnd_external_address should be configured inside SqueakStore/SqueakController.
lnd_external_address: Optional[LightningAddressHostPort] = None
if self.config.lnd.external_host:
lnd_external_address = LightningAddressHostPort(
@ -97,7 +96,7 @@ class SqueakPeerServerHandler(object):
port=self.config.lnd.port,
)
logger.info(lnd_external_address)
offer = self.squeak_store.get_packaged_offer(
offer = self.squeak_controller.get_packaged_offer(
squeak_hash,
client_addr,
price_msat,
@ -117,10 +116,9 @@ class SqueakPeerServerHandler(object):
SqueakPublicKey.from_bytes(bytes.fromhex(pubkey_str))
for pubkey_str in pubkey_strs
]
# Add separate endpoint for replies.
# reply_to_hash = interest.hashReplySqk if interest.hashReplySqk != EMPTY_HASH else None
return self.squeak_store.lookup_squeaks(
return self.squeak_controller.lookup_squeaks(
pubkeys,
min_block,
max_block,
@ -128,9 +126,4 @@ class SqueakPeerServerHandler(object):
)
def get_price_for_squeak(self) -> int:
price_policy = PricePolicy(
self.squeak_store,
self.config,
self.node_settings,
)
return price_policy.get_price()
return self.squeak_controller.get_sell_price_msat()

View file

@ -1,39 +0,0 @@
# MIT License
#
# Copyright (c) 2020 Jonathan Zernik
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import mock
import pytest
from squeaknode.node.price_policy import PricePolicy
@pytest.fixture()
def price_policy():
yield PricePolicy(None, None, None)
def test_get_price(price_policy, user_config):
with mock.patch.object(price_policy, 'get_peer', autospec=True) as mock_get_peer, \
mock.patch.object(price_policy, 'get_sell_price_msat', autospec=True) as mock_get_sell_price_msat:
mock_get_peer.return_value = None
mock_get_sell_price_msat.return_value = 555
assert price_policy.get_price() == 555