eosHelper.js 1.4 KB

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