From a28e04b106d74f8ae6fa574a90fec96ed6789407 Mon Sep 17 00:00:00 2001 From: Jonathan Zernik Date: Sun, 18 Oct 2020 21:37:42 -0400 Subject: [PATCH] Improve channel item component (#304) * Improve channel item component * Fix clearing offers for squeak on squeak download --- .../BuyOfferDetailItem/BuyOfferDetailItem.js | 2 +- .../src/components/ChannelItem/ChannelItem.js | 35 ++++++++++--------- squeakserver/db/squeak_db.py | 15 +++++++- squeakserver/node/peer_download.py | 6 ++++ 4 files changed, 40 insertions(+), 18 deletions(-) diff --git a/frontend/squeak-node-frontend/src/components/BuyOfferDetailItem/BuyOfferDetailItem.js b/frontend/squeak-node-frontend/src/components/BuyOfferDetailItem/BuyOfferDetailItem.js index ff088e1e..58d870a1 100644 --- a/frontend/squeak-node-frontend/src/components/BuyOfferDetailItem/BuyOfferDetailItem.js +++ b/frontend/squeak-node-frontend/src/components/BuyOfferDetailItem/BuyOfferDetailItem.js @@ -95,7 +95,7 @@ export default function BuyOfferDetailItem({ - Expires: {moment(expireTime*1000).fromNow()} + Expires: {moment(expireTime*1000).fromNow()} ({expireTime}) ) diff --git a/frontend/squeak-node-frontend/src/components/ChannelItem/ChannelItem.js b/frontend/squeak-node-frontend/src/components/ChannelItem/ChannelItem.js index ac3271d4..d1143b8c 100644 --- a/frontend/squeak-node-frontend/src/components/ChannelItem/ChannelItem.js +++ b/frontend/squeak-node-frontend/src/components/ChannelItem/ChannelItem.js @@ -65,10 +65,25 @@ export default function ChannelItem({ function ChannelContent() { return ( - {channel.getCapacity()} + + + Open Channel + + + Capacity: {channel.getCapacity()} + + + Local Balance: {channel.getLocalBalance()} + + + Remote Balance: {channel.getRemoteBalance()} + + + Pubkey: {channel.getRemotePubkey()} + + + Channel Point: {channel.getChannelPoint()} + ) } @@ -90,18 +105,6 @@ export default function ChannelItem({ {ChannelContent()} - - - - {channel.getChannelPoint()} - - - ) } diff --git a/squeakserver/db/squeak_db.py b/squeakserver/db/squeak_db.py index edb116a0..3a33536d 100644 --- a/squeakserver/db/squeak_db.py +++ b/squeakserver/db/squeak_db.py @@ -901,7 +901,9 @@ class SqueakDb: def get_offers(self, squeak_hash): """ Get offers for a squeak hash. """ - s = select([self.offers]).where(self.offers.c.squeak_hash == squeak_hash) + s = select([self.offers]).where( + self.offers.c.squeak_hash == squeak_hash + ) with self.get_connection() as connection: result = connection.execute(s) rows = result.fetchall() @@ -987,6 +989,17 @@ class SqueakDb: # rows = curs.fetchall() # return len(rows) + def delete_offers_for_squeak(self, squeak_hash): + """ Delete all offers for a squeak hash. """ + squeak_hash_str = squeak_hash.hex() + s = self.offers.delete().where( + self.offers.c.squeak_hash == squeak_hash_str + ) + with self.get_connection() as connection: + res = connection.execute(s) + deleted_offers = res.rowcount + return deleted_offers + def insert_sent_payment(self, sent_payment): """ Insert a new sent payment. """ ins = self.sent_payments.insert().values( diff --git a/squeakserver/node/peer_download.py b/squeakserver/node/peer_download.py index 83b5eac1..f285d13c 100644 --- a/squeakserver/node/peer_download.py +++ b/squeakserver/node/peer_download.py @@ -74,6 +74,7 @@ class PeerDownload: if self.stopped(): return self._download_squeak(hash) + self._clear_offers(hash) if self.stopped(): return @@ -129,6 +130,11 @@ class PeerDownload: squeak = self.peer_client.get_squeak(squeak_hash) self._save_squeak(squeak) + def _clear_offers(self, squeak_hash): + logger.info("Deleting all offers for squeak: {}".format(squeak_hash.hex())) + num_deleted_offers = self.postgres_db.delete_offers_for_squeak(squeak_hash) + logger.info("Deleted number of offers : {}".format(num_deleted_offers)) + def _get_followed_addresses(self): followed_profiles = self.postgres_db.get_following_profiles() return [profile.address for profile in followed_profiles]