transaction progressor
This commit is contained in:
@@ -37,10 +37,15 @@ export class Transaction {
|
||||
}
|
||||
|
||||
submit() {
|
||||
useWalletStore().transaction = this
|
||||
ensureVault()
|
||||
const ws = useWalletStore();
|
||||
if ( ws.transaction !== null ) {
|
||||
console.error('Transaction already in progress', ws.transaction)
|
||||
return
|
||||
}
|
||||
ws.transaction = this
|
||||
}
|
||||
|
||||
// "propose" means attach the transaction to a specific vault
|
||||
propose(owner, vault) {
|
||||
if (this.vault !== null && this.vault !== vault) {
|
||||
this.failed('proposed vault did not match withdrawl vault', vault, this.vault)
|
||||
@@ -131,13 +136,13 @@ export class Transaction {
|
||||
try {
|
||||
const tx = toRaw(await this.createTx(contract))
|
||||
this.signed(tx)
|
||||
tx.wait().then(this.mined.bind(this)).catch(this.failed.bind(this))
|
||||
console.log(`sent transaction`, tx)
|
||||
}
|
||||
catch (e) {
|
||||
this.failed(e)
|
||||
return null
|
||||
}
|
||||
tx.wait().then(this.mined.bind(this)).catch(this.failed.bind(this))
|
||||
return this.tx
|
||||
}
|
||||
|
||||
@@ -165,19 +170,21 @@ export class PlaceOrderTransaction extends Transaction {
|
||||
|
||||
|
||||
async createTx(vaultContract) {
|
||||
const tries = 3;
|
||||
const tries = 65;
|
||||
let i;
|
||||
for (i=0; i<tries; i++ ) {
|
||||
let success = false
|
||||
for (i=0; !success && i<tries; i++ ) {
|
||||
try {
|
||||
console.error('getting placement fee', vaultContract, this.order)
|
||||
this.fee = await placementFee(vaultContract, this.order)
|
||||
break
|
||||
success = true
|
||||
}
|
||||
catch (e) {
|
||||
console.warn('failed to get placement fee', e)
|
||||
await sleep(1000)
|
||||
}
|
||||
}
|
||||
if (i===tries)
|
||||
if (!success)
|
||||
throw Error('failed to get placement fee')
|
||||
console.log('placing order', this.id, this.fee, this.order)
|
||||
return await vaultContract.placeDexorder(this.order, {value: this.fee.reduce((a, b) => a + b)})
|
||||
|
||||
Reference in New Issue
Block a user