aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src/utils/asset_wrapper.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-06-20 19:56:27 +0800
committerFabio Berger <me@fabioberger.com>2018-06-20 19:56:27 +0800
commitfb7d425244fd754c478f432c5a64d52917071fbc (patch)
tree6a2659b02c2220346cdcde31eedb83b9d661ec15 /packages/contracts/src/utils/asset_wrapper.ts
parent3fab40efe553446770c8858afd0020f613ca4d4c (diff)
downloaddexon-sol-tools-fb7d425244fd754c478f432c5a64d52917071fbc.tar
dexon-sol-tools-fb7d425244fd754c478f432c5a64d52917071fbc.tar.gz
dexon-sol-tools-fb7d425244fd754c478f432c5a64d52917071fbc.tar.bz2
dexon-sol-tools-fb7d425244fd754c478f432c5a64d52917071fbc.tar.lz
dexon-sol-tools-fb7d425244fd754c478f432c5a64d52917071fbc.tar.xz
dexon-sol-tools-fb7d425244fd754c478f432c5a64d52917071fbc.tar.zst
dexon-sol-tools-fb7d425244fd754c478f432c5a64d52917071fbc.zip
Add support for setting allowance to unlimited
Diffstat (limited to 'packages/contracts/src/utils/asset_wrapper.ts')
-rw-r--r--packages/contracts/src/utils/asset_wrapper.ts31
1 files changed, 24 insertions, 7 deletions
diff --git a/packages/contracts/src/utils/asset_wrapper.ts b/packages/contracts/src/utils/asset_wrapper.ts
index 11697eca8..fd543621f 100644
--- a/packages/contracts/src/utils/asset_wrapper.ts
+++ b/packages/contracts/src/utils/asset_wrapper.ts
@@ -139,8 +139,14 @@ export class AssetWrapper {
return;
}
case constants.ERC721_PROXY_ID: {
- if (!desiredAllowance.eq(0) && !desiredAllowance.eq(1)) {
- throw new Error(`Allowance for ERC721 token can only be set to 0 or 1. Got: ${desiredAllowance}`);
+ if (
+ !desiredAllowance.eq(0) &&
+ !desiredAllowance.eq(1) &&
+ !desiredAllowance.eq(constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS)
+ ) {
+ throw new Error(
+ `Allowance for ERC721 token can only be set to 0, 1 or 2^256-1. Got: ${desiredAllowance}`,
+ );
}
const erc721Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper;
const assetProxyData = assetProxyUtils.decodeERC721AssetData(assetData);
@@ -161,11 +167,22 @@ export class AssetWrapper {
assetProxyData.tokenAddress,
assetProxyData.tokenId,
);
- // HACK: We do not currently support ApprovedForAll when setting proxy allowance
- // This was intentional since unsetting ApprovedForAll, will unset approval for unrelated
- // tokens other then the one specified in the call to this method.
- if (isProxyApprovedForAll) {
- throw new Error(`We don't currently support the use of "approveAll" functionality for ERC721.`);
+ if (!isProxyApprovedForAll && desiredAllowance.eq(constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS)) {
+ const isApproved = true;
+ await erc721Wrapper.approveProxyForAllAsync(
+ assetProxyData.tokenAddress,
+ assetProxyData.tokenId,
+ isApproved,
+ );
+ } else if (isProxyApprovedForAll && desiredAllowance.eq(0)) {
+ const isApproved = false;
+ await erc721Wrapper.approveProxyForAllAsync(
+ assetProxyData.tokenAddress,
+ assetProxyData.tokenId,
+ isApproved,
+ );
+ } else if (isProxyApprovedForAll && desiredAllowance.eq(constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS)) {
+ return; // Noop
}
const isProxyApproved = await erc721Wrapper.isProxyApprovedAsync(