Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent 2nd eth approval if another lock already pending #3

Merged
merged 4 commits into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .yarn/versions/97953207.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
releases:
"@near-eth/nep141-erc20": patch
11 changes: 10 additions & 1 deletion packages/nep141-erc20/src/natural-erc20/sendToNear/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import BN from 'bn.js'
import { Decimal } from 'decimal.js'
import getRevertReason from 'eth-revert-reason'
import Web3 from 'web3'
import { track } from '@near-eth/client'
import { track, get } from '@near-eth/client'
import { stepsFor } from '@near-eth/client/dist/i18nHelpers'
import * as status from '@near-eth/client/dist/statuses'
import { getEthProvider, getNearAccount, formatLargeNum } from '@near-eth/client/dist/utils'
Expand Down Expand Up @@ -137,6 +137,15 @@ export async function initiate ({
}

async function approve (transfer) {
// Check if a transfer is pending lock: we don't want to override the approval of a previous transfer.
const transfers = await get(
{ filter: t => t.sourceToken === transfer.sourceToken && (!t.completedStep || t.completedStep === APPROVE) }
)
if (transfers.length > 0) {
throw new Error(
'Another transfer is already in progress, please complete the "Lock" step and try again'
)
}
const web3 = new Web3(getEthProvider())

const erc20Contract = new web3.eth.Contract(
Expand Down