Skip to content

Commit

Permalink
chore(bex): uppercase ownership string + default to the lowest fee
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulMcInnis committed Dec 18, 2024
1 parent 46dfd91 commit 44ec51a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
balancerVaultAbi,
formatUsd,
getSafeNumber,
truncateHash,
useBeraJs,
wrapNativeToken,
type Token,
Expand Down Expand Up @@ -141,10 +142,9 @@ export default function DynamicPoolCreationPreview({
}
}, [isRelayerApprovalError]);

const formattedOwnerAddress = `${ownerAddress.slice(
0,
6,
)}...${ownerAddress.slice(-4)} (${ownershipType})`;
const formattedOwnerAddress = `${ownershipType?.toUpperCase()} (${
ownerAddress && truncateHash(ownerAddress, undefined, undefined, true)
})`;

const poolDetails = [
{ label: "Pool Name", value: poolName },
Expand Down
11 changes: 3 additions & 8 deletions apps/hub/src/app/pools/components/parameters-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ interface OwnershipInputProps {
invalidAddressErrorMessage: string | null;
onSwapFeeChange: (fee: number) => void;
swapFee: number;
predefinedFees: number[];
poolType: PoolType;
}

Expand All @@ -50,20 +51,14 @@ const ParametersInput: React.FC<OwnershipInputProps> = ({
onChangeOwnershipType,
onOwnerChange,
invalidAddressErrorMessage,
swapFee,
onSwapFeeChange,
poolType,
swapFee,
predefinedFees,
}) => {
// NOTE: Balancer support more types of ownership than the ones we are supporting here: Delegated, Fixed and Custom.
// ... you can still create Pools with those types of ownership from the contract, but we are not supporting them in the UI.

let predefinedFees = [0.3, 0.5, 1];
if (
poolType === PoolType.ComposableStable ||
poolType === PoolType.MetaStable
) {
predefinedFees = [0.01, 0.05, 0.1];
}
return (
<section className="flex w-full flex-col gap-4">
{poolType === PoolType.ComposableStable && (
Expand Down
5 changes: 3 additions & 2 deletions apps/hub/src/app/pools/components/pool-creation-summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ const PoolCreationSummary = memo(
label: "Owners Address",
value:
showStep(3) &&
`${ownershipType} (${
ownersAddress && truncateHash(ownersAddress.toUpperCase())
`${ownershipType?.toUpperCase()} (${
ownersAddress &&
truncateHash(ownersAddress, undefined, undefined, true)
})`,
},
// NOTE: strangely, in the final step you will see both what you are typing & and the preview at the same time.
Expand Down
24 changes: 14 additions & 10 deletions apps/hub/src/app/pools/create/CreatePageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,6 @@ const DEFAULT_USD_BACKED_AMPLIFICATION = 2500;
*/
const DEFAULT_ALGORITHMIC_AMPLIFICATION = 200;

/**
* Default swap fee for pools is 0.1 %.
* NOTE: this will change depending on the pool type (weighted/stable).
* @constant {number}
*/
const DEFAULT_SWAP_FEE = 0.1;

/**
* Default pool type for pools is a composable stable pool, which can be referred to as a 'stable pool'.
* @constant {PoolType}
Expand Down Expand Up @@ -162,7 +155,6 @@ export default function CreatePageContent() {
useState<TokenInputType[]>(DEFAULT_LIQUIDITY);

const [poolType, setPoolType] = useState<PoolType>(DEFAULT_POOL_TYPE);
const [swapFee, setSwapFee] = useState<number>(DEFAULT_SWAP_FEE);
const [poolName, setPoolName] = useState<string>("");
const [poolSymbol, setPoolSymbol] = useState<string>("");
const [amplification, setAmplification] = useState<number>(
Expand Down Expand Up @@ -191,6 +183,17 @@ export default function CreatePageContent() {
setStablePoolWithNonStableTokensWarning,
] = useState<string | null>(null);

let predefinedFees = [0.3, 0.5, 1];
let initialFee = 0.3;
if (
poolType === PoolType.ComposableStable ||
poolType === PoolType.MetaStable
) {
predefinedFees = [0.01, 0.05, 0.1];
initialFee = 0.01;
}
const [swapFee, setSwapFee] = useState<number>(initialFee);

useEffect(() => {
const tokenList = tokens?.tokenList ?? [];

Expand Down Expand Up @@ -441,7 +444,7 @@ export default function CreatePageContent() {
setpoolCreateTokens(DEFAULT_TOKENS);
setInitialLiquidityTokens(DEFAULT_LIQUIDITY);
setPoolType(DEFAULT_POOL_TYPE);
setSwapFee(DEFAULT_SWAP_FEE);
setSwapFee(initialFee);
setPoolName("");
setPoolSymbol("");
setAmplification(DEFAULT_AMPLIFICATION);
Expand Down Expand Up @@ -784,9 +787,10 @@ export default function CreatePageContent() {
onChangeOwnershipType={handleOwnershipTypeChange}
onOwnerChange={handleOwnerChange}
invalidAddressErrorMessage={invalidAddressErrorMessage}
swapFee={swapFee}
onSwapFeeChange={setSwapFee}
poolType={poolType}
swapFee={swapFee}
predefinedFees={predefinedFees}
/>
)}
{currentStep === 4 && (
Expand Down
14 changes: 10 additions & 4 deletions packages/berajs/src/utils/truncateHash.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
/**
* Truncate a transaction or address hash
* Truncate a transaction or address hash and optionally format with uppercase letters and a lowercase 'x'.
*/
export const truncateHash = (
address: `0x${string}` | string,
startLength = 4,
endLength = 4,
formatUppercase = false,
) => {
if (!address) return "";

return `${address.substring(0, startLength)}...${address.substring(
address.length - endLength,
)}`;
const formattedAddress = formatUppercase
? address.toUpperCase().replace(/^0X/, "0x")
: address;

return `${formattedAddress.substring(
0,
startLength,
)}...${formattedAddress.substring(formattedAddress.length - endLength)}`;
};

0 comments on commit 44ec51a

Please sign in to comment.