Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #875 from swarmcity/S01E05-live
Browse files Browse the repository at this point in the history
Resolve
  • Loading branch information
xardass authored Dec 1, 2018
2 parents 40f5a65 + c41a508 commit 68546d3
Show file tree
Hide file tree
Showing 23 changed files with 802 additions and 223 deletions.
40 changes: 40 additions & 0 deletions src/data/data-simpledeal.html
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,39 @@
return hash
}

async function resolveItemAsync({ maintainer, item, hashtagAddress, seekerPercentage }) {
const seekerFraction = item.value * 2 * seekerPercentage;
console.log(seekerFraction);

// 1. Encode the raw resolveItem
const simpleDealContract = new _web3.eth.Contract(simpleDeal.abi, hashtagAddress);
const rawResolveItem = simpleDealContract.methods.resolveItem(
item.hash,
seekerFraction,
).encodeABI();

// 2. Get user's nonce
const nonce = await _web3.eth.getTransactionCount(maintainer.address);

// 3. Generate tx object, sign and serialize
const tx = new Tx({
nonce: _web3.utils.toHex(nonce),
from: maintainer.address,
gasPrice: 1000000000,
gasLimit: 3000000,
to: hashtagAddress,
data: rawResolveItem,
chainId: 42,
});
tx.sign(new Buffer(maintainer.privateKey, 'hex'));
const serializedTx = tx.serialize();

// 4. Send transaction, await receipt.
// Extra line for clarity
const hash = await sendSignedTransaction('0x' + serializedTx.toString('hex'))
return hash
}

async function cancelItemAsync({ seeker, itemHash, hashtagAddress }) {
// 1. Encode the raw cancelItem
const simpleDealContract = new _web3.eth.Contract(simpleDeal.abi, hashtagAddress);
Expand Down Expand Up @@ -356,6 +389,13 @@
return disputeItemAsync(args)
}

/**
* Resolve
*/
resolveItem(args) {
return resolveItemAsync(args)
}

/**
* Cancel
*/
Expand Down
184 changes: 93 additions & 91 deletions src/displays/display-backup.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,110 +80,110 @@
<div class="downloadbtn" on-click="_download">{{localize('download my file')}}</div>
</template>

</dom-if>
</div>
</dom-if>
</div>
</template>
<script>
class MyDisplayBackup extends new ReduxMixin(Polymer.mixinBehaviors([
Polymer.AppLocalizeBehavior,
],
Polymer.AppLocalizeBehavior,
],
Polymer.Element
)) {
static get is() {
return 'display-backup';
}
static get properties() {
return {
/**
* Language is the user selected language
* @type {String}
*/
language: {
type: String,
statePath: 'language',
},
/**
* Path is the current or requested path
* @type {String}
*/
path: {
type: String,
notify: true,
},
/**
* toggles the unlock display
* @type {Boolean}
*/
toggleUnlock: {
type: Boolean,
notify: true,
},
/**
* contains the qrCodePrivateKey
* @type {String}
*/
qrCodePrivateKey: {
type: String,
observer: '_print',
notify: true,
},
/**
* contains the qrCodePublicKey
* @type {String}
*/
qrCodePublicKey: {
type: String,
observer: '_print',
notify: true,
},
/**
* contains the private key
* @type {String}
*/
privateKey: {
type: String,
observer: '_print',
},
/**
* contains the osType
* @type {String}
*/
osType: {
type: String,
notify: true,
},
showJsonButton: {
type: Boolean,
value: true,
},
};
}
/**
* Fired when the component is connected
*/
return {
/**
* Language is the user selected language
* @type {String}
*/
language: {
type: String,
statePath: 'language',
},
/**
* Path is the current or requested path
* @type {String}
*/
path: {
type: String,
notify: true,
},
/**
* toggles the unlock display
* @type {Boolean}
*/
toggleUnlock: {
type: Boolean,
notify: true,
},
/**
* contains the qrCodePrivateKey
* @type {String}
*/
qrCodePrivateKey: {
type: String,
observer: '_print',
notify: true,
},
/**
* contains the qrCodePublicKey
* @type {String}
*/
qrCodePublicKey: {
type: String,
observer: '_print',
notify: true,
},
/**
* contains the private key
* @type {String}
*/
privateKey: {
type: String,
observer: '_print',
},
/**
* contains the osType
* @type {String}
*/
osType: {
type: String,
notify: true,
},
showJsonButton: {
type: Boolean,
value: true,
},
};
}
/**
* Fired when the component is connected
*/
connectedCallback() {
super.connectedCallback();
this._isShowDownload();
this.loadResources(this.resolveUrl('../text-translations.json'));
let storage = JSON.parse(localStorage.getItem('SwarmCity'));
this.publicKey = storage.keyStore.address;
}
/**
* toggles the password unlock display
*/
super.connectedCallback();
this._isShowDownload();
this.loadResources(this.resolveUrl('../text-translations.json'));
let storage = JSON.parse(localStorage.getItem('SwarmCity'));
this.publicKey = storage.keyStore.address;
}
/**
* toggles the password unlock display
*/
_unlock() {
this.qrCodePublicKey = null;
this.qrCodePrivateKey = null;
this.$.unlock._getPrivateKey().then(res => {
try {
const { privateKey, address, publicKey, qrCodePrivateKey, qrCodePublicKey } = res;
try {
const { privateKey, address, publicKey, qrCodePrivateKey, qrCodePublicKey } = res;
if (!privateKey) {
throw Error("Missing address");
throw Error("Missing address");
}
this.privateKey = privateKey;
this.qrCodePublicKey = qrCodePublicKey;
this.qrCodePrivateKey = qrCodePrivateKey;
} catch (e) {
} catch (e) {
console.error("Error showing keys (catch block): ", e.stack);
}
});
Expand Down Expand Up @@ -298,9 +298,10 @@
}
}
}
/**
* downloads account info, after success routs to download-success
*/
}
/**
* downloads account info, after success routs to download-success
*/
_download() {
let storage = JSON.parse(localStorage.getItem('SwarmCity'));
const filename = 'SwarmCity - UTC KeyStore';
Expand All @@ -321,9 +322,10 @@
} else {
this.path = 'download-success-profile/';
}
/**
* check for operating system for enable/disable the download backup file link
*/
}
/**
* check for operating system for enable/disable the download backup file link
*/
_isShowDownload() {
let userAgent = window.navigator.userAgent;
let platform = window.navigator.platform;
Expand Down
6 changes: 3 additions & 3 deletions src/displays/display-unlock.html
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,9 @@
this.disableScroll();
window.scrollTo(0, 0);
this.error = '';
setTimeout(() => {
this.$$('#input').focus();
}, 1);
// setTimeout(() => {
// this.$$('#input').focus();
// }, 1);
this.$.container.classList.remove('hidden');
if (this.blue) {
this.$.container.classList.add('blue');
Expand Down
99 changes: 99 additions & 0 deletions src/pages/chat/chat-conflict-resolve.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<!--
@license
Copyright (c) 2018 Swarm City
This code may only be used under the license found at https://github.com/swarmcity/license
-->
<link rel="import" href="../../../bower_components/polymer/polymer-element.html" />

<!-- Displays and shared styles only -->
<link rel="import" href="../../shared-styles.html" />

<dom-module id="chat-conflict-resolve">
<template>
<style include="shared-styles">
:host {
display: block;
}

.container {
margin-top: 20px;
}

.date {
@apply --layout-horizontal;
@apply --layout-center-justified;
@apply --smallest-light;
color: var(--sc-grey3b);
}

.text {
@apply --layout-horizontal;
@apply --layout-center-justified;
@apply --small-light;
margin: 5px 0 10px 0;
padding: 10px 20px;
box-sizing: border-box;
text-align: center;
background-color: var(--sc-grey1b);
}

.red {
color: var(--sc-red);
}
</style>
<div class="container">
<div class="date">[[_formatDate(message.time)]]</div>
<div class="text">
The conflict is resolved by the hashtag maintainer.
[[item.seekerUsername]] has been paid [[_seekerPayout(item.itemValue, message)]] SWT
and [[_getProviderUsername(item)]] has been paid [[_providerPayout(item.itemValue, message)]] SWT.
</div>
</div>
</template>
<script>
class MyChatConflictResolve extends (new ReduxMixin(
Polymer.mixinBehaviors([Polymer.AppLocalizeBehavior], Polymer.Element)
)) {
static get is() {
return "chat-conflict-resolve";
}
static get properties() {
return {
message: Object,
item: Object,
};
}

/**
* formats epoch
* @param {DateTime} dateTime epoch in javascript milliseconds
* @return {string} formatted date string
*/
_formatDate(dateTime) {
let milliseconds = dateTime * 1000;
if (webpack.moment().valueOf() - milliseconds < 86400000) {
return webpack.moment(milliseconds).fromNow();
} else {
return webpack.moment(milliseconds).format("DD MMM YYYY - HH:mm");
}
}
_seekerPayout(wei, message) {
if (message && message.seekerPercentage) return ((wei * message.seekerPercentage) / 1e18).toFixed(2);
if (message && message.message.seekerPercentage) return ((wei * message.seekerPercentage) / 1e18).toFixed(2);

}

_providerPayout(wei, message) {
if (message && message.seekerPercentage) return ((wei - (wei * message.seekerPercentage)) / 1e18).toFixed(2);
if (message && message.message.seekerPercentage) return ((wei - (wei * message.seekerPercentage)) / 1e18).toFixed(2);

}
_getProviderUsername(item) {
if (item && item.replies) {
return item.replies[item.providerAddress].username
}
}
}
window.customElements.define(MyChatConflictResolve.is, MyChatConflictResolve);
</script>
</dom-module>
Loading

0 comments on commit 68546d3

Please sign in to comment.