diff --git a/store/chain.js b/store/chain.js index 1cc8153d1..7f0046f83 100755 --- a/store/chain.js +++ b/store/chain.js @@ -217,19 +217,10 @@ export const actions = { enough_cpu = false } - let cosignpayer = '' let index = 0 let enough_bank_wax = false - let ms = 1 - if (actions[0].data.to == 'alcorammswap') { - cosignpayer = 'alcorammswap' - index = 1 - } - if (actions[0].data.to == 'alcordexmain') { - cosignpayer = 'alcordexmain' - index = 0 - ms = 2 - } + let cosignpayer = 'alcordexmain' + let ms = 2 try { const bank_wax = await rpcWAX.get_table_rows({ json: true, // Get the response as json @@ -313,66 +304,65 @@ export const actions = { ], } actions = [cosign, cosignpay, ...actions] - if (state.currentWallet == 'anchor') { - const transaction = await apiWAX.transact( - { - max_cpu_usage_ms: ms, - max_net_usage_words: 1000 * ms, - actions, - }, - { - broadcast: false, - sign: false, - blocksBehind: 5, - expireSeconds: 1200, - } - ) - const deserializedTransaction = await apiWAX.deserializeTransaction( - transaction.serializedTransaction - ) - const abis = await apiWAX.getTransactionAbis( - deserializedTransaction + const transaction = await apiWAX.transact( + { + max_cpu_usage_ms: ms, + max_net_usage_words: 1000 * ms, + actions, + }, + { + broadcast: false, + sign: false, + blocksBehind: 5, + expireSeconds: 1200, + } + ) + const deserializedTransaction = await apiWAX.deserializeTransaction( + transaction.serializedTransaction + ) + const serializedContextFreeData = + await apiWAX.serializeContextFreeData( + deserializedTransaction.context_free_data ) - const serializedContextFreeData = - await apiWAX.serializeContextFreeData( - deserializedTransaction.context_free_data - ) + const serializedTransaction = transaction.serializedTransaction - const chainId = rootState.network.chainId - const requiredKeys = - await getters.wallet.sessionProvider.getAvailableKeys() - const serializedTransaction = transaction.serializedTransaction - const signedTransaction = await getters.wallet.sign( - deserializedTransaction - ) + const request = { + transaction: Array.from(serializedTransaction), + } - const request = { - transaction: Array.from(serializedTransaction), + const response = await fetch( + rootState.network.LIMITLESS_WAX_ENDPOINT + 'cpu-rent', + { + method: 'POST', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + }, + body: JSON.stringify(request), } + ) - const response = await fetch( - rootState.network.LIMITLESS_WAX_ENDPOINT + 'cpu-rent', - { - method: 'POST', - headers: { - Accept: 'application/json', - 'Content-Type': 'application/json', - }, - body: JSON.stringify(request), - } - ) + if (!response.ok) { + const body = await response.json() + console.log(body.reason || 'Failed to connect to endpoint') + return await getters.wallet.transact(original_actions) + } - if (!response.ok) { - const body = await response.json() - throw new Error(body.reason || 'Failed to connect to endpoint') - } + const json = await response.json() - const json = await response.json() + if (!json.isOk) { + console.log(json.reason) + return await getters.wallet.transact(original_actions) + } - if (!json.isOk) { - throw new Error(json.reason) - } + if (json.signature == 'limit reached') { + return await getters.wallet.transact(original_actions) + } + if (state.currentWallet == 'anchor') { + const signedTransaction = await getters.wallet.sign( + deserializedTransaction + ) const sigs = [] if (json.signature) { sigs.push(json.signature[0])