Comments (3)
Hm good point. If you make a PR I can review + merge.
from angular-truffle-starter-dapp.
Yeah will do, trying to figure out the best way to approach callback hell. Using Promises might be the best approach, but don't think .watch() supports them so might need a custom Promise:
sendCoin = () => {
const amount = this.sendingAmount;
const receiver = this.recipientAddress;
let meta;
this.setStatus('Initiating transaction... (please wait)');
this.MetaCoin
.deployed()
.then(instance => {
meta = instance;
return meta.sendCoin(receiver, amount, {
from: this.account
}).then((result) => {
return new Promise((resolve, reject) => {
meta.Transfer({ transactionHash: result.tx }).watch((e, r) => {
if (!e) { resolve(r); } else { reject(e); }
});
});
});
})
.then(() => {
this.setStatus('Transaction complete!');
this.refreshBalance();
})
.catch(e => {
console.log(e);
this.setStatus('Error sending coin; see log.');
});
};
from angular-truffle-starter-dapp.
The Q library has a denodeify
method. It takes a function and converts it into a promise.
Example here: https://stackoverflow.com/questions/22519784/how-do-i-convert-an-existing-callback-api-to-promises
from angular-truffle-starter-dapp.
Related Issues (9)
- angular version HOT 1
- Refactor into Services
- Gets stuck estimating transaction costs HOT 1
- Deploy contract HOT 2
- Error: ParserError: Source file requires different compiler version HOT 3
- MetaMask will not appear in the browser when the transaction needs to be approved HOT 9
- rename truffle.js to truffle-config.js ? HOT 1
- Web3 is always detected as being injected
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-truffle-starter-dapp.