@@ -11,15 +11,31 @@ $(document).ready(function() {
1111
1212 $ ( "#blockchain button.set" ) . click ( function ( ) {
1313 var value = parseInt ( $ ( "#blockchain input.text" ) . val ( ) , 10 ) ;
14- SimpleStorage . set ( value ) ;
15- addToLog ( "#blockchain" , "SimpleStorage.set(" + value + ")" ) ;
14+
15+ // If web3.js 1.0 is being used
16+ if ( EmbarkJS . isNewWeb3 ( ) ) {
17+ SimpleStorage . methods . set ( value ) . send ( { from : web3 . eth . defaultAccount } ) ;
18+ addToLog ( "#blockchain" , "SimpleStorage.methods.set(value).send({from: web3.eth.defaultAccount})" ) ;
19+ } else {
20+ SimpleStorage . set ( value ) ;
21+ addToLog ( "#blockchain" , "SimpleStorage.set(" + value + ")" ) ;
22+ }
23+
1624 } ) ;
1725
1826 $ ( "#blockchain button.get" ) . click ( function ( ) {
19- SimpleStorage . get ( ) . then ( function ( value ) {
20- $ ( "#blockchain .value" ) . html ( value . toNumber ( ) ) ;
21- } ) ;
22- addToLog ( "#blockchain" , "SimpleStorage.get()" ) ;
27+ // If web3.js 1.0 is being used
28+ if ( EmbarkJS . isNewWeb3 ( ) ) {
29+ SimpleStorage . methods . get ( ) . call ( function ( err , value ) {
30+ $ ( "#blockchain .value" ) . html ( value ) ;
31+ } ) ;
32+ addToLog ( "#blockchain" , "SimpleStorage.methods.get(console.log)" ) ;
33+ } else {
34+ SimpleStorage . get ( ) . then ( function ( value ) {
35+ $ ( "#blockchain .value" ) . html ( value . toNumber ( ) ) ;
36+ } ) ;
37+ addToLog ( "#blockchain" , "SimpleStorage.get()" ) ;
38+ }
2339 } ) ;
2440
2541} ) ;
@@ -32,28 +48,18 @@ $(document).ready(function() {
3248 //EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'});
3349
3450 $ ( "#storage .error" ) . hide ( ) ;
35- EmbarkJS . Storage . setProvider ( 'ipfs' )
51+ EmbarkJS . Storage . ipfsConnection . ping ( )
3652 . then ( function ( ) {
37- console . log ( 'Provider set to IPFS' ) ;
38- EmbarkJS . Storage . ipfsConnection . ping ( )
39- . then ( function ( ) {
40- $ ( "#status-storage" ) . addClass ( 'status-online' ) ;
41- $ ( "#storage-controls" ) . show ( ) ;
42- } )
43- . catch ( function ( err ) {
44- if ( err ) {
45- console . log ( "IPFS Connection Error => " + err . message ) ;
46- $ ( "#storage .error" ) . show ( ) ;
47- $ ( "#status-storage" ) . addClass ( 'status-offline' ) ;
48- $ ( "#storage-controls" ) . hide ( ) ;
49- }
50- } ) ;
53+ $ ( "#status-storage" ) . addClass ( 'status-online' ) ;
54+ $ ( "#storage-controls" ) . show ( ) ;
5155 } )
52- . catch ( function ( err ) {
53- console . log ( 'Failed to set IPFS as Provider:' , err . message ) ;
54- $ ( "#storage .error" ) . show ( ) ;
55- $ ( "#status-storage" ) . addClass ( 'status-offline' ) ;
56- $ ( "#storage-controls" ) . hide ( ) ;
56+ . catch ( function ( err ) {
57+ if ( err ) {
58+ console . log ( "IPFS Connection Error => " + err . message ) ;
59+ $ ( "#storage .error" ) . show ( ) ;
60+ $ ( "#status-storage" ) . addClass ( 'status-offline' ) ;
61+ $ ( "#storage-controls" ) . hide ( ) ;
62+ }
5763 } ) ;
5864
5965 $ ( "#storage button.setIpfsText" ) . click ( function ( ) {
@@ -114,20 +120,19 @@ $(document).ready(function() {
114120$ ( document ) . ready ( function ( ) {
115121
116122 $ ( "#communication .error" ) . hide ( ) ;
117- web3 . version . getWhisper ( function ( err , version ) {
118- if ( err ) {
119- $ ( "#communication .error" ) . show ( ) ;
120- $ ( "#communication-controls" ) . hide ( ) ;
121- $ ( "#status-communication" ) . addClass ( 'status-offline' ) ;
122- } else if ( version >= 5 ) {
123- $ ( "#communication .errorVersion" ) . show ( ) ;
124- $ ( "#communication-controls" ) . hide ( ) ;
125- $ ( "#status-communication" ) . addClass ( 'status-offline' ) ;
126- } else {
127- EmbarkJS . Messages . setProvider ( 'whisper' ) ;
128- $ ( "#status-communication" ) . addClass ( 'status-online' ) ;
129- }
130- } ) ;
123+ $ ( "#communication .errorVersion" ) . hide ( ) ;
124+ if ( EmbarkJS . Messages . providerName === 'whisper' ) {
125+ EmbarkJS . Messages . getWhisperVersion ( function ( err , version ) {
126+ if ( err ) {
127+ $ ( "#communication .error" ) . show ( ) ;
128+ $ ( "#communication-controls" ) . hide ( ) ;
129+ $ ( "#status-communication" ) . addClass ( 'status-offline' ) ;
130+ } else {
131+ EmbarkJS . Messages . setProvider ( 'whisper' ) ;
132+ $ ( "#status-communication" ) . addClass ( 'status-online' ) ;
133+ }
134+ } ) ;
135+ }
131136
132137 $ ( "#communication button.listenToChannel" ) . click ( function ( ) {
133138 var channel = $ ( "#communication .listen input.channel" ) . val ( ) ;
0 commit comments