From 63844bef8a8b2b8ee93a9684b073decc395e559d Mon Sep 17 00:00:00 2001 From: Micah Alcorn Date: Wed, 19 Sep 2018 08:35:15 -0700 Subject: [PATCH 1/7] Wire up offer rejection --- src/components/purchase-detail.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/components/purchase-detail.js b/src/components/purchase-detail.js index 2b49d05f495f..5113d2bd5b53 100644 --- a/src/components/purchase-detail.js +++ b/src/components/purchase-detail.js @@ -423,11 +423,10 @@ class PurchaseDetail extends Component { } async rejectOffer() { - this.toggleModal('rejection') - alert('To Do') + this.withdrawOffer(() => this.toggleModal('rejection')) } - async withdrawOffer() { + async withdrawOffer(onSuccess) { const { offerId } = this.props const { purchase, listing } = this.state const offer = purchase @@ -454,6 +453,8 @@ class PurchaseDetail extends Component { listing }) + onSuccess && onSuccess() + this.setState({ processing: false }) } catch (error) { this.setState({ processing: false }) From 1f8379507587f3ba2aa91b4a69deb1fcd7b003ae Mon Sep 17 00:00:00 2001 From: Micah Alcorn Date: Wed, 19 Sep 2018 10:23:22 -0700 Subject: [PATCH 2/7] Make listing card reactive and handle confirmation --- src/components/my-listing-card.js | 10 ++++++++-- src/components/my-listings.js | 17 +++++++++++++++++ src/components/transaction.js | 22 +++++++++++++--------- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/components/my-listing-card.js b/src/components/my-listing-card.js index 82796182c5eb..6ec07c678c06 100644 --- a/src/components/my-listing-card.js +++ b/src/components/my-listing-card.js @@ -35,7 +35,7 @@ class MyListingCard extends Component { } async closeListing() { - const { intl, listing, handleProcessing, updateTransaction } = this.props + const { intl, listing, handleProcessing, onClose, updateTransaction } = this.props const { address } = listing const prompt = confirm( intl.formatMessage(this.intlMessages.confirmCloseListing) @@ -54,7 +54,13 @@ class MyListingCard extends Component { } = await origin.marketplace.withdrawListing( this.props.listing.id, {}, - updateTransaction + (confirmationCount, transactionReceipt) => { + // Having a transaction receipt doesn't guarantee that the listing status will have changed. + // Let's relentlessly retrieve the data so that we are sure to get it. - Micah + onClose && onClose() + + updateTransaction(confirmationCount, transactionReceipt) + } ) this.props.upsertTransaction({ diff --git a/src/components/my-listings.js b/src/components/my-listings.js index c887f7f30fd8..4b91af1aca87 100644 --- a/src/components/my-listings.js +++ b/src/components/my-listings.js @@ -16,6 +16,7 @@ class MyListings extends Component { this.handleProcessing = this.handleProcessing.bind(this) this.handleUpdate = this.handleUpdate.bind(this) + this.refreshListing = this.refreshListing.bind(this) this.state = { filter: 'all', listings: [], @@ -77,6 +78,21 @@ class MyListings extends Component { } } + async refreshListing(id) { + try { + const listing = await getListing(id) + + this.setState({ + listings: [ + ...this.state.listings.filter(l => l.id !== id), + listing + ] + }) + } catch (error) { + console.error(`Error refreshing listing: ${id}`) + } + } + render() { const { filter, listings, loading, processing } = this.state const filteredListings = (() => { @@ -260,6 +276,7 @@ class MyListings extends Component { listing={l} handleProcessing={this.handleProcessing} handleUpdate={this.handleUpdate} + onClose={() => this.refreshListing(l.id)} /> ))} diff --git a/src/components/transaction.js b/src/components/transaction.js index c78369a234f0..6e0374396d98 100644 --- a/src/components/transaction.js +++ b/src/components/transaction.js @@ -58,32 +58,36 @@ class Transaction extends Component { const { seller } = listing switch (transactionTypeKey) { - case 'acceptOffer': + case 'createListing': + fromAddress = seller + break + case 'closeListing': fromAddress = seller - toAddress = buyer break case 'makeOffer': fromAddress = buyer toAddress = seller break - case 'closeListing': + case 'acceptOffer': fromAddress = seller + toAddress = buyer + break + case 'initiateDispute': + fromAddress = web3Account + toAddress = web3Account === seller ? buyer : seller break case 'completePurchase': fromAddress = buyer toAddress = seller break - case 'createListing': - fromAddress = seller + case 'withdrawOffer': + fromAddress = web3Account + toAddress = web3Account === seller ? buyer : seller break case 'reviewSale': fromAddress = seller toAddress = buyer break - case 'initiateDispute': - fromAddress = web3Account - toAddress = web3Account === seller ? buyer : seller - break } const truncatedFrom = fromAddress From 61e7b695b98b629c60e2db468c8d057432291eb3 Mon Sep 17 00:00:00 2001 From: Micah Alcorn Date: Wed, 19 Sep 2018 10:24:46 -0700 Subject: [PATCH 3/7] Lower boost range and default --- src/utils/boostUtils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/boostUtils.js b/src/utils/boostUtils.js index 86f4d8323fa7..ff20b7dfbc26 100644 --- a/src/utils/boostUtils.js +++ b/src/utils/boostUtils.js @@ -1,6 +1,6 @@ -export const defaultBoostValue = 500 +export const defaultBoostValue = 50 export const minBoostValue = 0 -export const maxBoostValue = 1000 +export const maxBoostValue = 100 const range = maxBoostValue - minBoostValue export const boostLevels = { From 770e3a961a0fb8e2ed1e6a3e0b670434d20fb98e Mon Sep 17 00:00:00 2001 From: Micah Alcorn Date: Wed, 19 Sep 2018 10:26:37 -0700 Subject: [PATCH 4/7] Expand preview column --- src/components/listing-create.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/listing-create.js b/src/components/listing-create.js index 01808b69f981..4f077bd12947 100644 --- a/src/components/listing-create.js +++ b/src/components/listing-create.js @@ -522,7 +522,7 @@ class ListingCreate extends Component { )} {step >= this.STEP.PREVIEW && ( -
+
)} -
+
= this.STEP.PREVIEW ? '' : ' offset-md-1 offset-lg-3'}`}> Date: Wed, 19 Sep 2018 11:27:19 -0700 Subject: [PATCH 5/7] Repair keys key --- src/components/messaging-provider.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/messaging-provider.js b/src/components/messaging-provider.js index 5965a673d4d5..dd46fe03aa93 100644 --- a/src/components/messaging-provider.js +++ b/src/components/messaging-provider.js @@ -76,9 +76,9 @@ class MessagingProvider extends Component { // detect new decrypted messages origin.messaging.events.on('msg', obj => { if (obj.decryption) { - const { roomId, sharedKeys } = obj.decryption + const { roomId, keys } = obj.decryption - origin.messaging.initRoom(roomId, sharedKeys) + origin.messaging.initRoom(roomId, keys) } this.props.addMessage(obj) From 1710e5f1a148faeb68e1c56bdf96a90510040b8a Mon Sep 17 00:00:00 2001 From: Micah Alcorn Date: Wed, 19 Sep 2018 14:43:02 -0700 Subject: [PATCH 6/7] Repair and add participants' conversation --- src/components/arbitration.js | 90 ++++++++++++++++++++++------------- src/components/messages.js | 17 +++++-- 2 files changed, 69 insertions(+), 38 deletions(-) diff --git a/src/components/arbitration.js b/src/components/arbitration.js index bbc4c3167c41..8b06640c7408 100644 --- a/src/components/arbitration.js +++ b/src/components/arbitration.js @@ -95,10 +95,12 @@ class Arbitration extends Component { } validateUser() { - const { web3Account } = this.props + const { history, offerId, web3Account } = this.props if (web3Account && this.props.web3Account.toUpperCase() !== ARBITRATOR_ETH_ADDRESS.toUpperCase()) { alert(`⚠️ Warning:\nCurrent account (${this.props.web3Account}) is not equal to the ARBITRATOR_ACCOUNT environment variable (${ARBITRATOR_ETH_ADDRESS})`) + + history.push(`/purchases/${offerId}`) } } @@ -145,6 +147,8 @@ class Arbitration extends Component { const buyerConversationId = buyer.address && origin.messaging.generateRoomId(web3Account, buyer.address) const sellerConversationId = seller.address && origin.messaging.generateRoomId(web3Account, seller.address) + const participantsConversationId = buyer.address && seller.address && origin.messaging.generateRoomId(buyer.address, seller.address) + const participantsMessages = participantsConversationId ? messages.filter(({ content, conversationId }) => content && conversationId === participantsConversationId).sort((a, b) => (a.index < b.index ? -1 : 1)) : [] return (
@@ -260,7 +264,7 @@ class Arbitration extends Component {
-
+
{listing.id && (

Listing Details

@@ -294,43 +298,63 @@ class Arbitration extends Component { ))}
-
-
- {seller.address && -
- +
+

Conversation

+ {!!participantsMessages.length &&
content && conversationId === sellerConversationId).sort((a, b) => (a.index < b.index ? -1 : 1))} + id={participantsConversationId} + messages={participantsMessages} />
- -
- } - {buyer.address && -
- -
- content && conversationId === buyerConversationId).sort((a, b) => (a.index < b.index ? -1 : 1))} + } + {!participantsMessages.length && +

None exists between these two parties 🤐

+ } +
+
+
+ {purchase.status !== 'disputed' && +

This transaction is not in disputed status.

+ } + {purchase.status === 'disputed' && +
+ {seller.address && +
+ +
+ content && conversationId === sellerConversationId).sort((a, b) => (a.index < b.index ? -1 : 1))} + /> +
+
- -
- } -
+ } + {buyer.address && +
+ +
+ content && conversationId === buyerConversationId).sort((a, b) => (a.index < b.index ? -1 : 1))} + /> +
+ +
+ } +
+ }
{processing && ( diff --git a/src/components/messages.js b/src/components/messages.js index 3999aad40679..f15aac06e02d 100644 --- a/src/components/messages.js +++ b/src/components/messages.js @@ -7,6 +7,8 @@ import Conversation from 'components/conversation' import groupByArray from 'utils/groupByArray' +import origin from '../services/origin' + class Messages extends Component { constructor(props) { super(props) @@ -91,12 +93,17 @@ class Messages extends Component { } } -const mapStateToProps = state => { +const mapStateToProps = ({ app, messages, messagingEnabled }) => { + const { web3Account } = app.web3 + const filteredMessages = messages.filter(({ content, conversationId }) => { + return content && origin.messaging.getRecipients(conversationId).includes(web3Account) + }) + return { - conversations: groupByArray(state.messages, 'conversationId'), - messages: state.messages.filter(m => m.content), - messagingEnabled: state.app.messagingEnabled, - web3Account: state.app.web3.account + conversations: groupByArray(filteredMessages, 'conversationId'), + messages: filteredMessages, + messagingEnabled, + web3Account } } From 77f1d854593a0057a8ec0e93ea4cc873d92478ca Mon Sep 17 00:00:00 2001 From: Micah Alcorn Date: Wed, 19 Sep 2018 17:29:43 -0700 Subject: [PATCH 7/7] Repair and use consistent filters --- src/components/dropdowns/messages.js | 21 ++++++++++++++------- src/components/messages.js | 5 +++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/components/dropdowns/messages.js b/src/components/dropdowns/messages.js index 93ce8abca2bd..8f96b1f44283 100644 --- a/src/components/dropdowns/messages.js +++ b/src/components/dropdowns/messages.js @@ -12,6 +12,8 @@ import ConversationListItem from 'components/conversation-list-item' import groupByArray from 'utils/groupByArray' +import origin from '../../services/origin' + class MessagesDropdown extends Component { constructor(props) { super(props) @@ -164,14 +166,19 @@ class MessagesDropdown extends Component { } } -const mapStateToProps = state => { +const mapStateToProps = ({ app, messages }) => { + const { messagingDismissed, messagingEnabled, web3 } = app + const web3Account = web3.account + const filteredMessages = messages.filter(({ content, conversationId, senderAddress, status }) => { + return content && status === 'unread' && senderAddress !== web3Account && origin.messaging.getRecipients(conversationId).includes(web3Account) + }) + return { - messagingDismissed: state.app.messagingDismissed, - messagingEnabled: state.app.messagingEnabled, - messages: state.messages.filter(({ content, senderAddress, status }) => { - return content && status === 'unread' && senderAddress !== state.app.web3.account - }), - web3Account: state.app.web3.account + conversations: groupByArray(filteredMessages, 'conversationId'), + messages: filteredMessages, + messagingDismissed, + messagingEnabled, + web3Account } } diff --git a/src/components/messages.js b/src/components/messages.js index f15aac06e02d..5eaf0a246fa3 100644 --- a/src/components/messages.js +++ b/src/components/messages.js @@ -93,8 +93,9 @@ class Messages extends Component { } } -const mapStateToProps = ({ app, messages, messagingEnabled }) => { - const { web3Account } = app.web3 +const mapStateToProps = ({ app, messages }) => { + const { messagingEnabled, web3 } = app + const web3Account = web3.account const filteredMessages = messages.filter(({ content, conversationId }) => { return content && origin.messaging.getRecipients(conversationId).includes(web3Account) })