Skip to content

Commit

Permalink
Merge pull request #203 from polywrap/nerfzael-bugfixing
Browse files Browse the repository at this point in the history
Selection and transaction error fixes
  • Loading branch information
dOrgJelli committed Feb 20, 2024
2 parents 5c17707 + debee00 commit 0c98b0b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
1 change: 1 addition & 0 deletions web/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const Button = ({
return (
<Popover className='relative'>
<Popover.Button
disabled={disabled}
className={clsx(
"text-shadow-md relative inline-flex items-center justify-center space-x-2 rounded-full border-2 transition-all duration-500",
hierarchyClasses[hierarchy],
Expand Down
2 changes: 1 addition & 1 deletion web/components/Strategy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export default function Strategy(props: {
</div>
<Button
disabled={
selectedStrategiesLength === 0 || amount === "0" || amount === ""
selectedStrategiesLength === 0 || amount === "0" || amount === "" || isTransactionPending
}
onClick={executeTransaction}>
{isTransactionPending ? (
Expand Down
14 changes: 11 additions & 3 deletions web/components/StrategyTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ const InputWithTooltip = forwardRef(
)
);

declare global {
interface Window {
getSelection: () => Selection | null;
}
}

function WeightInput({
selected,
index,
Expand Down Expand Up @@ -106,7 +112,10 @@ export function StrategyTable(props: StrategiesHandler & { network: NetworkName
.filter((s) => !s.disabled)
.some((s) => s.selected);

function openProjectDetails(strategy: StrategyInformation) {
function openProjectDetails(strategy: StrategyInformation){
// Do not open the project details if the user is trying to select the project
if (window.getSelection()?.type === "Range") return;

setShowStrategyDetails({
show: true,
strategy,
Expand Down Expand Up @@ -155,7 +164,6 @@ export function StrategyTable(props: StrategiesHandler & { network: NetworkName
);
};


return (
<>
<div className='space-y-2'>
Expand Down Expand Up @@ -188,7 +196,7 @@ export function StrategyTable(props: StrategiesHandler & { network: NetworkName
className={clsx(
"bg-indigo-50 border-2 border-indigo-300 hover:bg-white transition-colors duration-200 w-full rounded-2xl shadow-sm hover:shadow-lg shadow-primary-shadow/20 p-4 col-span-12 space-y-3 cursor-pointer"
)}
onClick={() => openProjectDetails(entry)}>
onClick={(e) => openProjectDetails(entry)}>
<div className='grid gap-4 grid-cols-12'>
<div className='flex space-x-4 items-center w-full col-span-12 md:col-span-6'>
<div
Expand Down
34 changes: 21 additions & 13 deletions web/hooks/useDonation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,20 @@ export function useDonation() {
setIsTransactionPending(true);

const { network: selectedNetwork, token: selectedToken, donations } = plan;
const filteredDonations = donations.filter((d) => Number(d.amount) > 0);

const token = getTokensForNetwork(selectedNetwork).find(
(t) => t.name == selectedToken.name
);

if (!token) {
throw new Error(`Token with name: ${selectedToken} is not valid`);
}
const amounts = donations.map((d) => Number(d.amount));
const amounts = filteredDonations.map((d) => Number(d.amount));
console.log(plan, amounts, signer, token);
try {
await splitTransferFunds(
donations.map((d) => d.recipient),
filteredDonations.map((d) => d.recipient),
amounts,
signer,
selectedNetwork,
Expand Down Expand Up @@ -97,17 +99,23 @@ export function useDonation() {
amount: string,
network: NetworkName
) => {
const ethersProvider = new ethers.providers.Web3Provider(
wallet.provider,
"any"
);
const signer = ethersProvider.getSigner();
const tokenContract = new ethers.Contract(token.address, ERC20_ABI, signer);

const contractAddress = DISPERSE_CONTRACT_ADDRESSES[network];
const amountInDecimals = ethers.utils.parseUnits(amount.toString(), token.decimals);
const approveTx = await tokenContract.approve(contractAddress, amountInDecimals);
await approveTx.wait(1);
setIsTransactionPending(true);

try {
const ethersProvider = new ethers.providers.Web3Provider(
wallet.provider,
"any"
);
const signer = ethersProvider.getSigner();
const tokenContract = new ethers.Contract(token.address, ERC20_ABI, signer);

const contractAddress = DISPERSE_CONTRACT_ADDRESSES[network];
const amountInDecimals = ethers.utils.parseUnits(amount.toString(), token.decimals);
const approveTx = await tokenContract.approve(contractAddress, amountInDecimals);
await approveTx.wait(1);
} finally {
setIsTransactionPending(false);
}
};

return {
Expand Down

0 comments on commit 0c98b0b

Please sign in to comment.