出于某种原因,我的 for of 循环在 1 次迭代后继续停止。
我希望得到一个包含 2 个资产 ID 和 2 个价格的 console.log,但是我只得到 1 个资产 ID 和 1 个价格。然后,我可以获得适合的响应的唯一方法是当我通过刷新重新运行函数时(b/c 它检查我的 localStorage 并看到旧值已经存在)任何想法为什么它在一次迭代后停止?
main = async () => {
await eth.connect({
provider: "https://mainnet.infura.io/[key-goes-here]",
contracts: [landRegistry, marketplace]
});
const response = await axios.get(
"https://api.decentraland.org/parcels?status=open"
);
const viableProperties = response.data.data.parcels.filter(parcel => parcel.publication.price <= this.state.landPrice);
for(let [key, value] of viableProperties.entries()) {
const cost = value.publication.price;
const asset = value.publication.asset_id;
const commaPos = asset.indexOf(",");
const coordinatesLat = parseFloat(asset.substring(0, commaPos));
const coordinatesLong = parseFloat(
asset.substring(commaPos + 1, asset.length)
);
const price = eth.utils.toWei(cost);
const oldProperty = localStorage.getItem(asset)
if (cost <= this.state.landPrice && oldProperty == null) {
localStorage.setItem(asset, key);
const assetId = await landRegistry.encodeTokenId(
coordinatesLat,
coordinatesLong
);
await marketplace.executeOrder(assetId, price)
}
}
};
**** 编辑 **** - 我目前有 await marketplace.executeOrder ...我曾经有 console.log(asset, price)