1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- import { getNetwork } from '@/util/contract.js'
- let EosHelper = {
- transfer: function (from, to, amount, memo, authority) {
- let action = 'transfer'
- let identity = { authorization: [`${from}@${authority}`] }
- if (self !== top) {
- return meeAction(action, [from, to, amount, memo, identity])
- } else {
- return window.EOS[action](from, to, amount, memo, identity)
- }
- },
- getCurrencyBalance: function (code, account, symbol = 'EOS') {
- let action = 'getCurrencyBalance'
- if (self !== top) {
- return meeAction(action, [code, account, symbol])
- } else {
- return window.EOS.getCurrencyBalance(code, account, symbol)
- }
- },
- async doSymbolTransfer (from, to, amount, memo, authority, contract) {
- let action = 'transfer'
- let identity = { authorization: [`${from}@${authority}`] }
- if (self !== top) {
- return meeAction(action, [from, to, amount, memo, identity], contract)
- } else {
- try {
- let _contract = await window.EOS.contract(contract)
- let res = await _contract[action](from, to, amount, memo, identity)
- return Promise.resolve(res)
- } catch (error) {
- return Promise.reject(error)
- }
- }
- }
- }
- async function meeAction (action, param, contract = '') {
- let network = await getNetwork()
- return window.postMessager.send({
- action: 'meechat:eosAction',
- data: { action, param, contract, network }
- })
- }
- export default EosHelper
|