Skip to content
This repository was archived by the owner on Dec 19, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/popup/pages/Cabinet/CyberDCabinet/CyberDCabinet.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ <h2>
</h2>
</div>

<router-link :to="{name: 'cabinet-cyberd-save-and-link', query: {linkKeywords: true}}" tag="button">Link</router-link>
<router-link :to="{name: 'cabinet-cyberd-save-and-link', query: {linkKeywords: true, from: 'cabinet-cyberd'}}" tag="button">Link</router-link>
<router-link :to="{name: 'cabinet-cyberd-transfer', query: {from: 'cabinet-cyberd'}}" tag="button">Send CYB</router-link>

<div style="margin-top: 40px;">
<button style="padding: 30px;" @click="downloadPage" :disabled="peersError || peersLoading">Download page to IPFS</button>
Expand Down
40 changes: 24 additions & 16 deletions src/popup/pages/Cabinet/CyberDCabinet/LinkContent/LinkContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,33 @@ export default {
async link() {
const keywordHashes = await addIpfsContentArray(this.resultKeywords);

const results = await pIteration.mapSeries(keywordHashes, async keywordHash => {
return CyberD.link(
{
address: this.currentAccount.address,
privateKey: await AppWallet.decryptByPassword(this.currentAccount.encryptedPrivateKey),
},
keywordHash,
this.resultContentHash
);
});
try {
const results = await pIteration.mapSeries(keywordHashes, async keywordHash => {
return CyberD.link(
{
address: this.currentAccount.address,
privateKey: await AppWallet.decryptByPassword(this.currentAccount.encryptedPrivateKey),
},
keywordHash,
this.resultContentHash
);
});

console.log('link results', results);
console.log('link results', results);

this.$notify({
type: 'success',
text: 'Successfully linked',
});
this.$notify({
type: 'success',
text: 'Successfully linked',
});

this.$router.push({ name: 'cabinet-cyberd' });
this.$router.push({ name: 'cabinet-cyberd' });
} catch (e) {
this.$notify({
type: 'error',
title: e && e.message ? e.message : e || 'Unknown error',
text: e && e.data ? e.data : '',
});
}
},
},
computed: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,36 @@ export default {
mimeType: this.$route.query.mimeType,
});

if (this.linkKeywords) {
const keywordHashes = await addIpfsContentArray(this.resultKeywords);
try {
if (this.linkKeywords) {
const keywordHashes = await addIpfsContentArray(this.resultKeywords);

const results = await pIteration.mapSeries(keywordHashes, async keywordHash => {
return CyberD.link(
{
address: this.currentAccount.address,
privateKey: await AppWallet.decryptByPassword(this.currentAccount.encryptedPrivateKey),
},
keywordHash,
this.resultContentHash
);
});

console.log('link results', results);
}
const results = await pIteration.mapSeries(keywordHashes, async keywordHash => {
return CyberD.link(
{
address: this.currentAccount.address,
privateKey: await AppWallet.decryptByPassword(this.currentAccount.encryptedPrivateKey),
},
keywordHash,
this.resultContentHash
);
});

this.$notify({
type: 'success',
text: this.linkKeywords ? 'Successfully saved and linked' : 'Successfully saved',
});
console.log('link results', results);
}

this.$router.push({ name: 'cabinet-cyberd' });
this.$notify({
type: 'success',
text: this.linkKeywords ? 'Successfully saved and linked' : 'Successfully saved',
});
this.$router.push({ name: 'cabinet-cyberd' });
} catch (e) {
this.$notify({
type: 'error',
title: e && e.message ? e.message : e || 'Unknown error',
text: e && e.data ? e.data : '',
});
}
},
},
computed: {
Expand Down
31 changes: 31 additions & 0 deletions src/popup/pages/Cabinet/CyberDCabinet/TransferCyb/TransferCyb.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<div id="import-account" class="padding-container">
<div class="back" v-if="$route.query.from" style="margin-left: 0">
<router-link :to="{name: $route.query.from}">< Back</router-link>
</div>

<h2>Send CYB</h2>

<div>
<h3>To address:</h3>
<input v-model="addressTo" />
</div>

<div>
<h3>Amount: (GCYB)</h3>
<input type="number" v-model="amount" />
</div>

<!--<div>-->
<!--<md-checkbox v-model="saveToGeesome">Save to personal channel in GeeSome</md-checkbox>-->
<!--<div v-if="saveToGeesome">-->
<!--<h3>Content name</h3>-->
<!--<input type="text" v-model="inputKeywordsStr"/>-->
<!--</div>-->
<!--&lt;!&ndash;<h3>Keywords:</h3>&ndash;&gt;-->
<!--&lt;!&ndash;<div>{{keywordsStr}}</div>&ndash;&gt;-->
<!--</div>-->

<div class="button-container">
<button @click="transfer()" :disabled="disableTransfer">{{'Send'}}</button>
</div>
</div>
52 changes: 52 additions & 0 deletions src/popup/pages/Cabinet/CyberDCabinet/TransferCyb/TransferCyb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { AppWallet, StorageVars } from '../../../../../services/data';
import { CyberD } from '../../../../../services/cyberd';
import ContentDetails from '../../../../directives/ContentDetails/ContentDetails';

export default {
template: require('./TransferCyb.html'),
components: { ContentDetails },
created() {
this.inputKeywordsStr = this.keywordsStr;
},
methods: {
async transfer() {
try {
const result = await CyberD.transfer(
{
address: this.currentAccount.address,
privateKey: await AppWallet.decryptByPassword(this.currentAccount.encryptedPrivateKey),
},
this.addressTo,
this.amount
);
console.log('transfer result', result);
this.$notify({
type: 'success',
text: 'Successfully transfered',
});

this.$router.push({ name: 'cabinet-cyberd' });
} catch (e) {
this.$notify({
type: 'error',
title: e && e.message ? e.message : e || 'Unknown error',
text: e && e.data ? e.data : '',
});
}
},
},
computed: {
currentAccount() {
return this.$store.state[StorageVars.Account];
},
disableTransfer() {
return !this.addressTo || !this.amount;
},
},
data() {
return {
addressTo: '',
amount: null,
};
},
};
6 changes: 6 additions & 0 deletions src/popup/router/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import LinkContent from '../pages/Cabinet/CyberDCabinet/LinkContent/LinkContent'
import Backup from '../pages/Cabinet/Backup/Backup';
import AskRestoreBackup from '../pages/NewWallet/AskRestoreBackup/AskRestoreBackup';
import LogIn from '../pages/NewWallet/LogIn/LogIn';
import TransferCyb from '../pages/Cabinet/CyberDCabinet/TransferCyb/TransferCyb';

export default [
{
Expand Down Expand Up @@ -48,6 +49,11 @@ export default [
name: 'cabinet-cyberd-link',
component: LinkContent,
},
{
path: '/cyberd/transfer',
name: 'cabinet-cyberd-transfer',
component: TransferCyb,
},
{
path: '/cyberd/save-and-link',
name: 'cabinet-cyberd-save-and-link',
Expand Down
71 changes: 69 additions & 2 deletions src/services/cyberd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import EthData from '@galtproject/frontend-core/libs/EthData';

const cyberjsBuilder = require('@litvintech/cyberjs/builder');
const cyberjsCodec = require('@litvintech/cyberjs/codec');
const cyberjsConstants = require('@litvintech/cyberjs/constants');
const axios = require('axios');
const node = 'http://88.198.36.117:26657';
const indexedNode = 'http://88.198.36.117:26657';
Expand Down Expand Up @@ -100,7 +101,73 @@ export class CyberD {
method: 'get',
url: `${node}/submit_signed_link?data="${signedSendHex}"`,
})
.then(response => response.data)
.catch(error => console.error('Cannot send', error));
.then(res => {
if (!res.data) {
throw new Error('Empty data');
}
if (res.data.error) {
throw res.data.error;
}
return res.data;
})
.catch(error => {
console.error('Link error', error);
throw error;
});
}

static async transfer(txOptions, addressTo, gAmount) {
const chainId = await this.getNetworkId();
const addressInfo = await axios({
method: 'get',
url: `${node}/account?address="${txOptions.address}"`,
});

if (!addressInfo.data.result) {
return console.error('error: addressInfo.data.result undefined');
}
const account = addressInfo.data.result.account;
if (!account) {
return console.error('error: addressInfo.data.result.account undefined');
}

const acc = {
address: account.address,
chain_id: chainId,
account_number: parseInt(account.account_number, 10),
sequence: parseInt(account.sequence, 10),
};

const amount = parseFloat(gAmount) * 10 ** 9;

const sendRequest = {
acc,
amount,
from: account.address,
// to: cyberjsCodec.bech32.toBech32(cyberjsConstants.CyberdNetConfig.PREFIX_BECH32_ACCADDR, addressTo),
to: addressTo,
type: 'send',
};

const txRequest = cyberjsBuilder.buildAndSignTxRequest(sendRequest, txOptions.privateKey, chainId);
const signedSendHex = cyberjsCodec.hex.stringToHex(JSON.stringify(txRequest));

return axios({
method: 'get',
url: `${node}/submit_signed_send?data="${signedSendHex}"`,
})
.then(res => {
if (!res.data) {
throw new Error('Empty data');
}
if (res.data.error) {
throw res.data.error;
}
return res.data;
})
.catch(error => {
console.error('Transfer error', error);
throw error;
});
}
}