{"action":"created","issue":{"url":"https://api.github.com/repos/Nikhil22/angular4-truffle-starter-dapp/issues/11","repository_url":"https://api.github.com/repos/Nikhil22/angular4-truffle-starter-dapp","labels_url":"https://api.github.com/repos/Nikhil22/angular4-truffle-starter-dapp/issues/11/labels{/name}","comments_url":"https://api.github.com/repos/Nikhil22/angular4-truffle-starter-dapp/issues/11/comments","events_url":"https://api.github.com/repos/Nikhil22/angular4-truffle-starter-dapp/issues/11/events","html_url":"https://github.com/Nikhil22/angular4-truffle-starter-dapp/issues/11","id":300474639,"number":11,"title":"Transaction event?","user":{"login":"kmturley","id":1710493,"avatar_url":"https://avatars2.githubusercontent.com/u/1710493?v=4","gravatar_id":"","url":"https://api.github.com/users/kmturley","html_url":"https://github.com/kmturley","followers_url":"https://api.github.com/users/kmturley/followers","following_url":"https://api.github.com/users/kmturley/following{/other_user}","gists_url":"https://api.github.com/users/kmturley/gists{/gist_id}","starred_url":"https://api.github.com/users/kmturley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kmturley/subscriptions","organizations_url":"https://api.github.com/users/kmturley/orgs","repos_url":"https://api.github.com/users/kmturley/repos","events_url":"https://api.github.com/users/kmturley/events{/privacy}","received_events_url":"https://api.github.com/users/kmturley/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-02-27T02:49:04Z","updated_at":"2018-02-27T03:42:31Z","closed_at":null,"author_association":"NONE","body":"When calling the sendCoin method you are returning a Promise:\r\nhttps://github.com/Nikhil22/angular4-truffle-starter-dapp/blob/master/src/app/app.component.ts#L118\r\n\r\nBut as far as I can see that will only confirm the transaction was sent, returning a transaction ID. But not when it was actually completed.\r\n\r\nLooks like you need to listen for an event. It seems as thought there is an event in the contract called Transfer:\r\nhttps://github.com/Nikhil22/angular4-truffle-starter-dapp/blob/master/contracts/MetaCoin.sol#L23\r\n\r\nWhich you could listen to using a variation of:\r\n```\r\nthis.MetaCoin.deployed().Transfer().watch(function(error, result) {\r\n  if (!error) {\r\n    console.log(result);\r\n  } else {\r\n    console.log(error);\r\n  }\r\n});\r\n```"},"comment":{"url":"https://api.github.com/repos/Nikhil22/angular4-truffle-starter-dapp/issues/comments/368737466","html_url":"https://github.com/Nikhil22/angular4-truffle-starter-dapp/issues/11#issuecomment-368737466","issue_url":"https://api.github.com/repos/Nikhil22/angular4-truffle-starter-dapp/issues/11","id":368737466,"user":{"login":"kmturley","id":1710493,"avatar_url":"https://avatars2.githubusercontent.com/u/1710493?v=4","gravatar_id":"","url":"https://api.github.com/users/kmturley","html_url":"https://github.com/kmturley","followers_url":"https://api.github.com/users/kmturley/followers","following_url":"https://api.github.com/users/kmturley/following{/other_user}","gists_url":"https://api.github.com/users/kmturley/gists{/gist_id}","starred_url":"https://api.github.com/users/kmturley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kmturley/subscriptions","organizations_url":"https://api.github.com/users/kmturley/orgs","repos_url":"https://api.github.com/users/kmturley/repos","events_url":"https://api.github.com/users/kmturley/events{/privacy}","received_events_url":"https://api.github.com/users/kmturley/received_events","type":"User","site_admin":false},"created_at":"2018-02-27T03:42:31Z","updated_at":"2018-02-27T03:42:31Z","author_association":"NONE","body":"Yeah will do, trying to figure out the best way to approach callback hell. Using Promisesmight be the best approach, but don't think .watch() supports them so might need a custom Promise:\r\n\r\nsendCoin = () => {\r\n  const amount = this.sendingAmount;\r\n  const receiver = this.recipientAddress;\r\n  let meta;\r\n\r\n  this.setStatus('Initiating transaction... (please wait)');\r\n\r\n  this.MetaCoin\r\n    .deployed()\r\n    .then(instance => {\r\n      meta = instance;\r\n      return meta.sendCoin(receiver, amount, {\r\n        from: this.account\r\n      }).then((result) => {\r\n        return new Promise((resolve, reject) => {\r\n          meta.Transfer({ transactionHash: result.tx }).watch((e, r) => {\r\n            if (!e) { resolve(r); } else { reject(e); }\r\n          });\r\n        });\r\n      });\r\n    })\r\n    .then(() => {\r\n      this.setStatus('Transaction complete!');\r\n      this.refreshBalance();\r\n    })\r\n    .catch(e => {\r\n      console.log(e);\r\n      this.setStatus('Error sending coin; see log.');\r\n    });\r\n};"}}
{"actor":{"display_login":"kmturley"}}