Skip to content

Commit

Permalink
link scatter
Browse files Browse the repository at this point in the history
  • Loading branch information
bkawk committed Nov 18, 2018
1 parent e0ba082 commit 0225381
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 24 deletions.
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
});
}
</script>

<script src="https://cdn.scattercdn.com/file/scatter-cdn/js/latest/scatterjs-core.min.js"></script>
<script src="https://cdn.scattercdn.com/file/scatter-cdn/js/latest/scatterjs-plugin-eosjs.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/eos.min.js"></script>
<script src="node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
<script type="module" src="src/worbli-portal.js"></script>
<style>
Expand Down
83 changes: 60 additions & 23 deletions src/routes/dashboard/sharedrop-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,6 @@ class SharedropRoute extends PolymerElement {
</div>
</div>
<div class="main">
<h1>Claim Sharedrop</h1>
Expand All @@ -286,11 +283,13 @@ class SharedropRoute extends PolymerElement {
</div>
</div>
<div class="footer">
<button type="button" on-click="_saveProfile">Sign with Scatter</button>
<template is="dom-if" if="{{!scatterConnected}}">
<button type="button" on-click="_connectScatter">Login to Worbli with Scatter</button>
</template>
<template is="dom-if" if="{{scatterConnected}}">
<button type="button" on-click="_signScatter">Sign Transaction with Scatter</button>
</template>
</div>
<!-- </template> -->
</div>
Expand Down Expand Up @@ -322,6 +321,16 @@ class SharedropRoute extends PolymerElement {
showIframe: {
type: Boolean,
value: false,
},
scatterConnected: {
type: Boolean,
value: false,
},
eos: {
type: Object,
},
scatter: {
type: Object,
}
};
}
Expand All @@ -346,6 +355,7 @@ class SharedropRoute extends PolymerElement {
localStorage.removeItem("token");
this.set('route.path', '/')
} else {
localStorage.setItem('security_code', response.security_code);
this.onfido_status = response.onfido_status;
if(this.onfido_status === 'started'){
this.started = true;
Expand All @@ -358,22 +368,49 @@ class SharedropRoute extends PolymerElement {
}
}

_connectScatter(){
let scatter, eos;
const network = {
blockchain:'eos',
protocol:'https',
host:'nodes.get-scatter.com',
port:443,
chainId:'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906',
}
const options = {expireInSeconds:60};
const reqFields = {accounts:[network]};
ScatterJS.plugins(new ScatterEOS());
ScatterJS.scatter.connect("worbli")
.then(connected => {
if (!connected) return false;
scatter = ScatterJS.scatter;
scatter.getIdentity(reqFields)
.then(() => {
eos = scatter.eos(network, Eos, options)
this.scatterConnected = true;
this.eos = eos;
this.scatter = scatter;
})
.catch((error) => {
alert('Scatter not found, Open it and try again');
});
})
.catch(error => console.log(error));
}


_save(data){
const token = localStorage.getItem("token");
const url = `${this.apiPath}/user/profile/`;
fetch(url, {
method: 'POST',
body: JSON.stringify(data),
headers:{'Content-Type': 'application/json', 'Authorization': `Bearer ${token}`}
})
.then((response) => {return response.json()})
.then((response) => {
this.set('route.path', '/dashboard/review/')
})
.catch(error => console.log('Error:', error));
}

_signScatter(){
const account = this.scatter.identity.accounts.find(x => x.blockchain === 'eos');
const options = { authorization:[`${account.name}@${account.authority}`]};
const contractAccount = 'worbliworbli';
const functionName = 'reg';
const owner = account.name;
const securitycode = localStorage.getItem("security_code");
const args = {owner, securitycode}
this.eos.transaction([contractAccount], sendTx => {
sendTx[contractAccount][functionName](args, options)
})
.then(trx => console.log('trx', trx))
.catch(err => console.error(err));
}

} window.customElements.define('sharedrop-route', SharedropRoute);

0 comments on commit 0225381

Please sign in to comment.