Skip to content

Commit 5355ad1

Browse files
committed
fixed eosjs, added shopping demo
1 parent 58f6afe commit 5355ad1

6 files changed

+129
-39
lines changed

package-lock.json

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"license": "ISC",
1212
"dependencies": {
1313
"dotenv-webpack": "^1.5.4",
14-
"eosjs": "^6.1.4",
14+
"eosjs": "^6.1.5",
1515
"eosjs-ecc": "^2.0.1",
1616
"vue": "^2.5.13",
1717
"vue-router": "^3.0.1",

src/views/GettingStarted.vue

+24-20
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,13 @@
9090
</h1></figure>
9191
<p>
9292
<span>
93-
This account was created on our network, staked for use, and has a significant amount of
94-
EOS tokens.
93+
This account was created on our network, staked for use, and has enough EOS tokens to do all of these demos many times over.
9594
</span>
9695
<br><br>
9796

9897
<b>Account Name: </b> <span>{{accountName}}</span>
9998
<br><br>
100-
<b>Private Key: </b> <span>{{privateKey}}</span>
99+
<b>Private Key: </b> <textarea spellcheck="false" class="private-key" v-model="privateKey"></textarea>
101100
<br><br>
102101
<b>Public Key: </b> <span>{{publicKey}}</span>
103102
</p>
@@ -150,9 +149,9 @@
150149
</p>
151150
<br>
152151
<section class="bordered">
153-
<button disabled style="width:150px; margin-top:0;">Add Network</button>
152+
<button v-on:click="addNetwork" style="width:150px; margin-top:0;">Add Network</button>
154153
<br>
155-
<span>This feature is not yet enabled.</span>
154+
<span>Nothing will happen if it already exists.</span>
156155
</section>
157156
<br><br><br>
158157
<p>
@@ -237,13 +236,9 @@
237236
const publicKey = ecc.privateToPublic(privateKey);
238237
const accountName = this.randomAccountName();
239238
240-
console.log('account', accountName);
241-
console.log(publicKey)
242-
243239
const stakerName = process.env.ACCOUNT_NAME;
244240
const keyProvider = process.env.PRIVATE_KEY;
245241
const httpEndpoint = `http://${process.env.NETWORK_HOST}:${process.env.NETWORK_PORT}`;
246-
console.log(httpEndpoint);
247242
248243
let eos = Eos.Localnet({httpEndpoint, keyProvider});
249244
@@ -255,20 +250,23 @@
255250
recovery: stakerName,
256251
deposit: `1 EOS`
257252
}).then(account => {
258-
console.log('account', account);
259-
eos.transfer(accountName, stakerName, 10, '').then(trx => {
260-
this.privateKey = privateKey;
261-
this.publicKey = publicKey;
262-
this.accountName = accountName;
263-
this.generatingAccount = false;
264-
});
253+
setTimeout(() => {
254+
eos.transfer(stakerName, accountName, 1000000, '').then(trx => {
255+
this.privateKey = privateKey;
256+
this.publicKey = publicKey;
257+
this.accountName = accountName;
258+
this.generatingAccount = false;
259+
});
260+
}, 500);
265261
}).catch(e => {
266-
console.log("Error", e)
267-
// TODO: Recurse, probably existing name or invalid character.
268-
this.generatingAccount = false;
262+
// Recursing, probably existing name or invalid character.
263+
this.createAccount();
269264
})
270265
})
271266
},
267+
addNetwork(){
268+
this.scatter.suggestNetwork();
269+
},
272270
...mapActions([
273271
274272
])
@@ -277,5 +275,11 @@
277275
</script>
278276

279277
<style lang="scss">
280-
278+
.private-key {
279+
width:100%;
280+
height:40px;
281+
outline:0;
282+
border:0;
283+
resize:none;
284+
}
281285
</style>

src/views/Shopping.vue

+61-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<section class="panel">
1414

15-
<section class="box">
15+
<section class="box" v-if="!identity">
1616
<figure class="header">
1717
<h1>
1818
You don’t have an account here yet!
@@ -30,6 +30,25 @@
3030
<button v-on:click="requestIdentity">Provide Identity</button>
3131
</section>
3232

33+
<section class="box" v-else>
34+
<figure class="header">
35+
<h1>
36+
You have linked your Identity with this application!
37+
</h1>
38+
</figure>
39+
<p>
40+
There is now a permission in place which allows this application to automatically retrieve your up to date
41+
Identity each time you visit it. This means you can update your Identity at the source ( Scatter ) and have it updated
42+
to each and every application it has permissions for once you re-visit it without having to deal with updating information on multiple
43+
applications.
44+
<br><br>
45+
Imagine what would happen if you moved houses and had to update your shipping information on every shopping
46+
website you've ever used.
47+
</p>
48+
49+
<button v-on:click="requestIdentity">Provide Identity</button>
50+
</section>
51+
3352

3453
<section class="info">
3554
<h1>Signing up with an application easily</h1>
@@ -52,15 +71,17 @@
5271
request it and you give it permission to access it.
5372
</b>
5473
</p>
55-
<p class="dev-link">I'm a developer, show me how this is done!</p>
74+
<a href="https://github.com/EOSEssentials/Scatter#requesting-an-identity" target="_blank">
75+
<p class="dev-link">I'm a developer, show me how this is done!</p>
76+
</a>
5677
</section>
5778
</section>
5879

5980
<hr>
6081

6182
<section class="panel">
6283

63-
<section class="box unpadded">
84+
<section class="box unpadded" v-if="!bought">
6485
<figure class="image">
6586

6687
</figure>
@@ -85,6 +106,29 @@
85106
</section>
86107
</section>
87108

109+
<section class="box" v-else>
110+
<figure class="header">
111+
<h1>
112+
You've purchased an Item.
113+
</h1>
114+
</figure>
115+
<p>
116+
Wasn't that simple? You've not only just paid for the item using <b>10 EOS</b>, but you've also supplied
117+
some shipping information all in one click.
118+
<br><br>
119+
<b>Let's look at some of the information:</b>
120+
</p>
121+
<br>
122+
<p>
123+
124+
<u>Transaction ID</u>: <b>{{transaction.transaction_id}}</b><br><br>
125+
<u>Personal Information</u>: <b>{{getPersonalInfo(transaction.returnedFields)}}</b><br><br>
126+
<u>Shipping Information</u>: <b>{{getShippingInfo(transaction.returnedFields)}}</b><br><br>
127+
</p>
128+
129+
<button v-if="!!identity" v-on:click="purchaseItem">Buy Again!</button>
130+
</section>
131+
88132

89133
<section class="info">
90134
<h1>Buying an item that needs to be shipped</h1>
@@ -102,7 +146,9 @@
102146
We’re simply going to bundle the transfering of funds and personal information into one easy to approve action
103147
which is completely transparent to the only person that you actually care about in this exchange. <b>You.</b>
104148
</p>
105-
<p class="dev-link">I'm a developer, show me how this is done!</p>
149+
<a href="https://github.com/EOSEssentials/Scatter#requesting-a-signature" target="_blank">
150+
<p class="dev-link">I'm a developer, show me how this is done!</p>
151+
</a>
106152
</section>
107153
</section>
108154

@@ -122,7 +168,8 @@
122168
123169
export default {
124170
data(){ return {
125-
171+
bought:false,
172+
transaction:{}
126173
}},
127174
computed: {
128175
...mapState([
@@ -140,14 +187,20 @@
140187
});
141188
},
142189
purchaseItem(){
143-
console.log(this.identity);
144-
const requiredFields = ['account', 'firstname', 'lastname', 'country', 'address','phone', 'zipcode', 'city'];
190+
const requiredFields = ['account', 'firstname', 'lastname', 'country', 'address', 'city'];
145191
this.eos.transfer(this.identity.account.name, 'inita', 10, '', {requiredFields}).then(transaction => {
146-
192+
this.bought = true;
193+
this.transaction = transaction;
147194
}).catch(e => {
148195
console.log('error', e)
149196
})
150197
},
198+
getPersonalInfo(fields){
199+
return `${fields.firstname} ${fields.lastname}`
200+
},
201+
getShippingInfo(fields){
202+
return `${fields.address}, ${fields.city}, ${fields.country.name}`
203+
},
151204
...mapActions([
152205
Actions.SET_IDENTITY
153206
])

tests/eosjs.spec.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const assert = require('assert')
2+
const Eos = require('eosjs');
3+
4+
describe('eosjs', () => {
5+
6+
const initaPrivate = '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3';
7+
const initaPublic = 'EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV';
8+
const keyProvider = initaPrivate;
9+
const eos = Eos.Localnet({httpEndpoint: 'http://192.168.56.101:8888', keyProvider});
10+
11+
function randomAccountName(){
12+
const size = Math.random() * 8 + 2;
13+
let text = "";
14+
const possible = "abcdefghij12345.";
15+
for(let i=0; i<size; i++) text += possible.charAt(Math.floor(Math.random() * possible.length));
16+
return text;
17+
}
18+
19+
it('should be able to create new accounts', done => {
20+
const newAccountName = randomAccountName();
21+
console.log('newAccountName', newAccountName)
22+
eos.newaccount({
23+
creator: 'inita',
24+
name: newAccountName,
25+
owner: initaPublic,
26+
active: initaPublic,
27+
recovery: 'inita',
28+
deposit: '1 EOS'
29+
}).then(account => {
30+
console.log(account);
31+
done();
32+
})
33+
});
34+
35+
});

webpack.config.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ module.exports = {
3232
},
3333
resolve: {
3434
alias: {
35-
vue: vueAlias,
36-
'extension-streams': 'extension-streams/dist/index.js',
37-
'aes-oop': 'aes-oop/dist/AES.js',
35+
vue: vueAlias
3836
},
3937
modules: [ path.join(__dirname, "node_modules") ]
4038
},

0 commit comments

Comments
 (0)