Improve channel item component (#304)

* Improve channel item component

* Fix clearing offers for squeak on squeak download
This commit is contained in:
Jonathan Zernik 2020-10-18 21:37:42 -04:00 committed by GitHub
parent 3b284ab699
commit a28e04b106
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 18 deletions

View file

@ -95,7 +95,7 @@ export default function BuyOfferDetailItem({
<Typography
size="md"
>
Expires: {moment(expireTime*1000).fromNow()}
Expires: {moment(expireTime*1000).fromNow()} ({expireTime})
</Typography>
</Box>
)

View file

@ -65,10 +65,25 @@ export default function ChannelItem({
function ChannelContent() {
return (
<Typography
size="md"
style={{whiteSpace: 'pre-line', overflow: "hidden", textOverflow: "ellipsis", height: '6rem'}}
>{channel.getCapacity()}
<Typography component="div">
<Box fontSize="h3.fontSize" m={1}>
Open Channel
</Box>
<Box m={1}>
Capacity: {channel.getCapacity()}
</Box>
<Box m={1}>
Local Balance: {channel.getLocalBalance()}
</Box>
<Box m={1}>
Remote Balance: {channel.getRemoteBalance()}
</Box>
<Box m={1}>
Pubkey: {channel.getRemotePubkey()}
</Box>
<Box m={1}>
Channel Point: {channel.getChannelPoint()}
</Box>
</Typography>
)
}
@ -90,18 +105,6 @@ export default function ChannelItem({
{ChannelContent()}
</Grid>
</Grid>
<Grid
container
direction="row"
justify="flex-start"
alignItems="flex-start"
>
<Grid item>
<Box color="secondary.main" fontWeight="fontWeightBold">
{channel.getChannelPoint()}
</Box>
</Grid>
</Grid>
</Box>
)
}

View file

@ -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(

View file

@ -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]