Skip to content

Commit

Permalink
feat: add the possibility of overriding button error texts (#1584)
Browse files Browse the repository at this point in the history
* feat: adding possibility of override error texts

* feat: improve shield button text
  • Loading branch information
pedrorezende authored Jan 27, 2025
1 parent 4ee780f commit 58bb84d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 26 deletions.
3 changes: 3 additions & 0 deletions apps/namadillo/src/App/Masp/MaspShield.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ export const MaspShield: React.FC = () => {
isSubmitting={isPerformingTransfer}
errorMessage={generalErrorMessage}
onSubmitTransfer={onSubmitTransfer}
buttonTextErrors={{
NoAmount: "Define an amount to shield",
}}
/>
</Panel>
);
Expand Down
3 changes: 3 additions & 0 deletions apps/namadillo/src/App/Masp/MaspUnshield.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ export const MaspUnshield: React.FC = () => {
isSubmitting={isPerformingTransfer}
errorMessage={generalErrorMessage}
onSubmitTransfer={onSubmitTransfer}
buttonTextErrors={{
NoAmount: "Define an amount to unshield",
}}
/>
</Panel>
);
Expand Down
59 changes: 33 additions & 26 deletions apps/namadillo/src/App/Transfer/TransferModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export type TransferModuleProps = {
isSubmitting?: boolean;
errorMessage?: string;
onSubmitTransfer: (params: OnSubmitTransferParams) => void;
buttonTextErrors?: Partial<Record<ValidationResult, string>>;
} & (
| { isIbcTransfer?: false; ibcOptions?: undefined }
| { isIbcTransfer: true; ibcOptions: IbcOptions }
Expand Down Expand Up @@ -101,6 +102,7 @@ export const TransferModule = ({
requiresIbcChannels,
onSubmitTransfer,
errorMessage,
buttonTextErrors = {},
}: TransferModuleProps): JSX.Element => {
const [walletSelectorModalOpen, setWalletSelectorModalOpen] = useState(false);
const [sourceChainModalOpen, setSourceChainModalOpen] = useState(false);
Expand Down Expand Up @@ -213,44 +215,49 @@ export const TransferModule = ({
setWalletSelectorModalOpen(true);
};

const getButtonTextError = (
id: ValidationResult,
defaultText: string
): string => {
if (buttonTextErrors.hasOwnProperty(id) && buttonTextErrors[id]) {
return buttonTextErrors[id];
}

return defaultText;
};

const getButtonText = (): string => {
if (isSubmitting) {
return submittingText || "Submitting...";
}

if (validationResult === "NoSourceWallet") {
return "Select Wallet";
}
const getText = getButtonTextError.bind(null, validationResult);
switch (validationResult) {
case "NoSourceWallet":
return getText("Select Wallet");

if (
validationResult === "NoSourceChain" ||
validationResult === "NoDestinationChain"
) {
return "Select Chain";
}
case "NoSourceChain":
case "NoDestinationChain":
return getText("Select Chain");

if (
validationResult === "NoSelectedAsset" &&
source.onChangeSelectedAsset
) {
return "Select Asset";
}
case "NoSelectedAsset":
return getText("Select Asset");

// TODO: this should be updated for nfts
if (validationResult === "NoAmount") {
return "Define an amount to transfer";
}
case "NoDestinationWallet":
return getText("Select Destination Wallet");

if (!availableAmountMinusFees) {
return "Wallet amount not available";
}
case "NoAmount":
return getText("Define an amount to transfer");

if (validationResult === "NoTransactionFee") {
return "No transaction fee is set";
case "NoTransactionFee":
return getText("No transaction fee is set");

case "NotEnoughBalance":
return getText("Not enough balance");
}

if (validationResult === "NotEnoughBalance") {
return "Not enough balance";
if (!availableAmountMinusFees) {
return getText("Wallet amount not available");
}

return "Submit";
Expand Down

0 comments on commit 58bb84d

Please sign in to comment.