Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Arbitration & Transaction Fixes #528

Merged
merged 9 commits into from
Sep 20, 2018
90 changes: 57 additions & 33 deletions src/components/arbitration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
}
}

Expand Down Expand Up @@ -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 (
<div className="purchase-detail">
Expand Down Expand Up @@ -260,7 +264,7 @@ class Arbitration extends Component {
</div>
</div>
<div className="row">
<div className="col-12 col-lg-8">
<div className="col-12 col-lg-6">
{listing.id && (
<Fragment>
<h2>Listing Details</h2>
Expand Down Expand Up @@ -294,43 +298,63 @@ class Arbitration extends Component {
))}
</div>
</div>
</div>
<div className="row">
{seller.address &&
<div className="col-12 col-md-6">
<UserCard
title="Seller"
listingId={listing.id}
purchaseId={purchase.id}
userAddress={seller.address}
/>
<div className="col-12 col-lg-6">
<h2>Conversation</h2>
{!!participantsMessages.length &&
<div className="conversation-container">
<Conversation
id={sellerConversationId}
messages={messages.filter(({ content, conversationId }) => content && conversationId === sellerConversationId).sort((a, b) => (a.index < b.index ? -1 : 1))}
id={participantsConversationId}
messages={participantsMessages}
/>
</div>
<button className="btn btn-lg btn-info mt-4" onClick={this.handleRuling}>Rule In Favor Of Seller</button>
</div>
}
{buyer.address &&
<div className="col-12 col-md-6">
<UserCard
title="Buyer"
listingId={listing.id}
purchaseId={purchase.id}
userAddress={buyer.address}
/>
<div className="conversation-container">
<Conversation
id={origin.messaging.generateRoomId(web3Account, buyer.address)}
messages={messages.filter(({ content, conversationId }) => content && conversationId === buyerConversationId).sort((a, b) => (a.index < b.index ? -1 : 1))}
}
{!participantsMessages.length &&
<p>None exists between these two parties 🤐</p>
}
</div>
</div>
<hr />
{purchase.status !== 'disputed' &&
<h2>This transaction is not in disputed status.</h2>
}
{purchase.status === 'disputed' &&
<div className="row">
{seller.address &&
<div className="col-12 col-md-6">
<UserCard
title="Seller"
listingId={listing.id}
purchaseId={purchase.id}
userAddress={seller.address}
/>
<div className="conversation-container">
<Conversation
id={sellerConversationId}
messages={messages.filter(({ content, conversationId }) => content && conversationId === sellerConversationId).sort((a, b) => (a.index < b.index ? -1 : 1))}
/>
</div>
<button className="btn btn-lg btn-info mt-4" onClick={this.handleRuling}>Rule In Favor Of Seller</button>
</div>
<button className="btn btn-lg btn-info mt-4" onClick={this.handleRuling}>Rule In Favor Of Buyer</button>
</div>
}
</div>
}
{buyer.address &&
<div className="col-12 col-md-6">
<UserCard
title="Buyer"
listingId={listing.id}
purchaseId={purchase.id}
userAddress={buyer.address}
/>
<div className="conversation-container">
<Conversation
id={origin.messaging.generateRoomId(web3Account, buyer.address)}
messages={messages.filter(({ content, conversationId }) => content && conversationId === buyerConversationId).sort((a, b) => (a.index < b.index ? -1 : 1))}
/>
</div>
<button className="btn btn-lg btn-info mt-4" onClick={this.handleRuling}>Rule In Favor Of Buyer</button>
</div>
}
</div>
}
</div>
{processing && (
<Modal backdrop="static" isOpen={true}>
Expand Down
21 changes: 14 additions & 7 deletions src/components/dropdowns/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/listing-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ class ListingCreate extends Component {
</div>
)}
{step >= this.STEP.PREVIEW && (
<div className="col-md-6 col-lg-5 listing-preview">
<div className="col-md-7 col-lg-8 listing-preview">
<label className="create-step">
<FormattedMessage
id={'listing-create.stepNumberLabel'}
Expand Down Expand Up @@ -672,7 +672,7 @@ class ListingCreate extends Component {
</div>
</div>
)}
<div className="pt-xs-4 pt-sm-4 col-md-5 offset-md-1 col-lg-4 offset-lg-3">
<div className={`pt-xs-4 pt-sm-4 col-md-5 col-lg-4${step >= this.STEP.PREVIEW ? '' : ' offset-md-1 offset-lg-3'}`}>
<WalletCard
wallet={wallet}
withBalanceTooltip={!this.props.wallet.ognBalance}
Expand Down
18 changes: 13 additions & 5 deletions src/components/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -91,12 +93,18 @@ class Messages extends Component {
}
}

const mapStateToProps = state => {
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)
})

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
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/messaging-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions src/components/my-listing-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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({
Expand Down
17 changes: 17 additions & 0 deletions src/components/my-listings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand Down Expand Up @@ -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 = (() => {
Expand Down Expand Up @@ -260,6 +276,7 @@ class MyListings extends Component {
listing={l}
handleProcessing={this.handleProcessing}
handleUpdate={this.handleUpdate}
onClose={() => this.refreshListing(l.id)}
/>
))}
</div>
Expand Down
7 changes: 4 additions & 3 deletions src/components/purchase-detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -454,6 +453,8 @@ class PurchaseDetail extends Component {
listing
})

onSuccess && onSuccess()

this.setState({ processing: false })
} catch (error) {
this.setState({ processing: false })
Expand Down
22 changes: 13 additions & 9 deletions src/components/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/utils/boostUtils.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down