eosHelper.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. let EosHelper = {
  2. transfer: function (from, to, amount, memo, authority) {
  3. let action = 'transfer'
  4. let identity = { authorization: [`${from}@${authority}`] }
  5. if (self !== top) {
  6. return meeAction(action, [from, to, amount, memo, identity])
  7. } else {
  8. return window.EOS[action](from, to, amount, memo, identity)
  9. }
  10. },
  11. getCurrencyBalance: function (code, account, symbol = 'EOS') {
  12. let action = 'getCurrencyBalance'
  13. if (self !== top) {
  14. return meeAction(action, [code, account, symbol])
  15. } else {
  16. return window.EOS.getCurrencyBalance(code, account, symbol)
  17. }
  18. },
  19. async doSymbolTransfer (from, to, amount, memo, authority, contract) {
  20. let action = 'transfer'
  21. let identity = { authorization: [`${from}@${authority}`] }
  22. if (self !== top) {
  23. return meeAction(action, [from, to, amount, memo, identity], contract)
  24. } else {
  25. try {
  26. let _contract = await window.EOS.contract(contract)
  27. let res = await _contract[action](from, to, amount, memo, identity)
  28. return Promise.resolve(res)
  29. } catch (error) {
  30. return Promise.reject(error)
  31. }
  32. }
  33. }
  34. }
  35. function meeAction (action, param, contract = '') {
  36. return window.postMessager.send({
  37. action: 'meechat:eosAction',
  38. data: { action, param, contract }
  39. })
  40. }
  41. export default EosHelper