Skip to content

Commit

Permalink
Merge pull request #60 from studydefi/cancel-ux
Browse files Browse the repository at this point in the history
handle logic if tx fails or if user cancels tx
  • Loading branch information
adrianmcli authored Apr 8, 2020
2 parents b8ec02b + 66e83fe commit d5c2b3f
Show file tree
Hide file tree
Showing 9 changed files with 428 additions and 217 deletions.
75 changes: 47 additions & 28 deletions packages/frontend/containers/DACProxy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,53 @@ function useDACProxy() {
dedgeCompoundManager,
} = contracts;
setLoading(true);
const tx = await dedgeHelpers.proxyFactory.buildAndEnterMarkets(
dacProxyFactory,
dedgeCompoundManager.address,
[
cEther.address,
cDai.address,
cRep.address,
cZrx.address,
cBat.address,
cUsdc.address,
cWbtc.address,
],
);

window.toastProvider.addMessage("Creating Smart Wallet...", {
secondaryMessage: "Check progress on Etherscan",
actionHref: `https://etherscan.io/tx/${tx.hash}`,
actionText: "Check",
variant: "processing",
});

await tx.wait();

window.toastProvider.addMessage("Smart Wallet created", {
variant: "success",
});
setLoading(false);

let tx = null;
try {
tx = await dedgeHelpers.proxyFactory.buildAndEnterMarkets(
dacProxyFactory,
dedgeCompoundManager.address,
[
cEther.address,
cDai.address,
cRep.address,
cZrx.address,
cBat.address,
cUsdc.address,
cWbtc.address,
]
);

window.toastProvider.addMessage("Creating Smart Wallet...", {
secondaryMessage: "Check progress on Etherscan",
actionHref: `https://etherscan.io/tx/${tx.hash}`,
actionText: "Check",
variant: "processing",
});

await tx.wait();

window.toastProvider.addMessage("Smart Wallet created", {
variant: "success",
});
} catch (e) {
if (tx === null) {
window.toastProvider.addMessage(`Transaction cancelled`, {
variant: "failure",
});
} else {
window.toastProvider.addMessage(`Failed to create wallet...`, {
secondaryMessage: "Check reason on Etherscan",
actionHref: `https://etherscan.io/tx/${tx.hash}`,
actionText: "Check",
variant: "failure",
});
}
setLoading(false);
return;
}

setLoading(false);
fetchProxyAddress();
};

Expand All @@ -86,7 +105,7 @@ function useDACProxy() {
if (proxyAddress) {
const { abi } = legos.dappsys.dsProxy;
const proxyContract = new ethers.Contract(proxyAddress, abi, signer);
window.analytics.identify(proxyAddress)
window.analytics.identify(proxyAddress);
setProxyContract(proxyContract);
}
}, [proxyAddress, signer]);
Expand Down
63 changes: 42 additions & 21 deletions packages/frontend/features/exit-position/ExitPosition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,29 +87,50 @@ const ExitPositionsButton = () => {
collateralMarkets,
} = await dedgeHelpers.exit.getExitPositionParameters(
signer,
proxy.address,
proxy.address
);

const tx = await dedgeHelpers.exit.exitPositionToETH(
address,
etherToBorrowWeiBN,
proxy,
dedgeAddressRegistry.address,
dedgeExitManager.address,
debtMarkets,
collateralMarkets,
);
window.toastProvider.addMessage(`Exiting positions...`, {
secondaryMessage: "Check progress on Etherscan",
actionHref: `https://etherscan.io/tx/${tx.hash}`,
actionText: "Check",
variant: "processing",
});
await tx.wait();

window.toastProvider.addMessage(`Exited Positions!`, {
variant: "success",
});
let tx = null;
try {
tx = await dedgeHelpers.exit.exitPositionToETH(
address,
etherToBorrowWeiBN,
proxy,
dedgeAddressRegistry.address,
dedgeExitManager.address,
debtMarkets,
collateralMarkets
);
window.toastProvider.addMessage(`Exiting positions...`, {
secondaryMessage: "Check progress on Etherscan",
actionHref: `https://etherscan.io/tx/${tx.hash}`,
actionText: "Check",
variant: "processing",
});
await tx.wait();

window.toastProvider.addMessage(`Exited Positions!`, {
variant: "success",
});
} catch (e) {
if (tx === null) {
window.toastProvider.addMessage(`Transaction cancelled`, {
variant: "failure",
});
} else {
window.toastProvider.addMessage(
`Failed to exit poisitions...`,
{
secondaryMessage: "Check reason on Etherscan",
actionHref: `https://etherscan.io/tx/${tx.hash}`,
actionText: "Check",
variant: "failure",
}
);
}
setLoading(false);
return;
}

window.analytics.track("Exit Positions Success");
setLoading(false);
Expand Down
64 changes: 40 additions & 24 deletions packages/frontend/features/import-vault/useAllowVaultTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const useAllowVaultTransfer = (selectedVaultId: number) => {
const allowed = await dedgeHelpers.maker.isUserAllowedVault(
proxy.address,
selectedVaultId,
makerCdpManager,
makerCdpManager
);

setImportAllowed(Boolean(allowed));
Expand All @@ -44,31 +44,47 @@ const useAllowVaultTransfer = (selectedVaultId: number) => {
const makerDsProxyContract = new ethers.Contract(
userMakerdaoProxyAddress,
legos.dappsys.dsProxy.abi,
signer,
);

const tx = await dedgeHelpers.maker.dsProxyCdpAllowDacProxy(
makerDsProxyContract,
proxyAddress,
makerCdpManager.address,
makerProxyActions.address,
selectedVaultId.toString(),
signer
);

window.toastProvider.addMessage(`Allowing vault #${selectedVaultId}...`, {
secondaryMessage: "Check progress on Etherscan",
actionHref: `https://etherscan.io/tx/${tx.hash}`,
actionText: "Check",
variant: "processing",
});

await tx.wait();

window.toastProvider.addMessage(
`Vault #${selectedVaultId} allowance approved`,
{ variant: "success" },
);
window.analytics.track("Allow Vault Success", { selectedVaultId });
let tx = null;
try {
tx = await dedgeHelpers.maker.dsProxyCdpAllowDacProxy(
makerDsProxyContract,
proxyAddress,
makerCdpManager.address,
makerProxyActions.address,
selectedVaultId.toString()
);
window.toastProvider.addMessage(`Allowing vault #${selectedVaultId}...`, {
secondaryMessage: "Check progress on Etherscan",
actionHref: `https://etherscan.io/tx/${tx.hash}`,
actionText: "Check",
variant: "processing",
});
await tx.wait();

window.toastProvider.addMessage(
`Vault #${selectedVaultId} allowance approved`,
{ variant: "success" }
);
window.analytics.track("Allow Vault Success", { selectedVaultId });
} catch (e) {
if (tx === null) {
window.toastProvider.addMessage(`Transaction cancelled`, {
variant: "failure",
});
} else {
window.toastProvider.addMessage(`Failed to allow vault...`, {
secondaryMessage: "Check reason on Etherscan",
actionHref: `https://etherscan.io/tx/${tx.hash}`,
actionText: "Check",
variant: "failure",
});
}
setLoading(false);
return;
}

setLoading(false);
getAllowStatus();
Expand Down
61 changes: 41 additions & 20 deletions packages/frontend/features/import-vault/useImportVault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,49 @@ const useImportVault = (selectedVaultId) => {
console.error("Invalid ilk", ilk);
}

const tx = await dedgeHelpers.maker.importMakerVault(
proxy,
dedgeMakerManager.address,
dedgeAddressRegistry.address,
selectedVaultId.toString(),
ilkCTokenEquilavent,
ilkJoinAddress,
decimals,
);
let tx = null;
try {
tx = await dedgeHelpers.maker.importMakerVault(
proxy,
dedgeMakerManager.address,
dedgeAddressRegistry.address,
selectedVaultId.toString(),
ilkCTokenEquilavent,
ilkJoinAddress,
decimals
);

window.toastProvider.addMessage(`Importing vault #${selectedVaultId}...`, {
secondaryMessage: "Check progress on Etherscan",
actionHref: `https://etherscan.io/tx/${tx.hash}`,
actionText: "Check",
variant: "processing",
});
window.toastProvider.addMessage(
`Importing vault #${selectedVaultId}...`,
{
secondaryMessage: "Check progress on Etherscan",
actionHref: `https://etherscan.io/tx/${tx.hash}`,
actionText: "Check",
variant: "processing",
}
);

await tx.wait();
window.toastProvider.addMessage(`Vault #${selectedVaultId} imported!`, {
variant: "success",
});
window.analytics.track("Import Vault Success", { selectedVaultId });
await tx.wait();
window.toastProvider.addMessage(`Vault #${selectedVaultId} imported!`, {
variant: "success",
});
window.analytics.track("Import Vault Success", { selectedVaultId });
} catch (e) {
if (tx === null) {
window.toastProvider.addMessage(`Transaction cancelled`, {
variant: "failure",
});
} else {
window.toastProvider.addMessage(`Failed to import vault...`, {
secondaryMessage: "Check reason on Etherscan",
actionHref: `https://etherscan.io/tx/${tx.hash}`,
actionText: "Check",
variant: "failure",
});
}
setLoading(false);
return;
}

setLoading(false);
getVaults();
Expand Down
57 changes: 38 additions & 19 deletions packages/frontend/features/position/BorrowCoin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,45 @@ const BorrowCoin = ({ coin, hide }) => {
setLoading(true);

const { dedgeCompoundManager } = contracts;
const tx = await dedgeHelpers.compound.borrowThroughProxy(
proxy,
dedgeCompoundManager.address,
coin.cTokenEquilaventAddress,
ethers.utils.parseUnits(amount, coin.decimals),
);
window.toastProvider.addMessage(`Borrowing ${coin.symbol}...`, {
secondaryMessage: "Check progress on Etherscan",
actionHref: `https://etherscan.io/tx/${tx.hash}`,
actionText: "Check",
variant: "processing",
});
await tx.wait();
let tx = null;

window.toastProvider.addMessage(
`Successfully borrowed ${coin.symbol}!`,
{
variant: "success",
},
);
try {
tx = await dedgeHelpers.compound.borrowThroughProxy(
proxy,
dedgeCompoundManager.address,
coin.cTokenEquilaventAddress,
ethers.utils.parseUnits(amount, coin.decimals)
);
window.toastProvider.addMessage(`Borrowing ${coin.symbol}...`, {
secondaryMessage: "Check progress on Etherscan",
actionHref: `https://etherscan.io/tx/${tx.hash}`,
actionText: "Check",
variant: "processing",
});
await tx.wait();

window.toastProvider.addMessage(
`Successfully borrowed ${coin.symbol}!`,
{
variant: "success",
}
);
} catch (e) {
if (tx === null) {
window.toastProvider.addMessage(`Transaction cancelled`, {
variant: "failure",
});
} else {
window.toastProvider.addMessage(`Failed to borrow...`, {
secondaryMessage: "Check reason on Etherscan",
actionHref: `https://etherscan.io/tx/${tx.hash}`,
actionText: "Check",
variant: "failure",
});
}
setLoading(false);
return;
}

setLoading(false);
getBalances();
Expand Down
Loading

1 comment on commit d5c2b3f

@vercel
Copy link

@vercel vercel bot commented on d5c2b3f Apr 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.