diff --git a/.changeset/funny-jokes-hide.md b/.changeset/funny-jokes-hide.md new file mode 100644 index 00000000..7300e5bc --- /dev/null +++ b/.changeset/funny-jokes-hide.md @@ -0,0 +1,5 @@ +--- +'@reservoir0x/relay-kit-ui': patch +--- + +Added a buffer of 0.02 minimum when selecting max for a Solana balance diff --git a/packages/ui/src/components/widgets/SwapWidget/index.tsx b/packages/ui/src/components/widgets/SwapWidget/index.tsx index db7ea6cc..5ef5d0f5 100644 --- a/packages/ui/src/components/widgets/SwapWidget/index.tsx +++ b/packages/ui/src/components/widgets/SwapWidget/index.tsx @@ -317,8 +317,8 @@ const SwapWidget: FC = ({ tradeType === 'EXACT_INPUT' ? amountInputValue : amountInputValue - ? formatFixedLength(amountInputValue, 8) - : amountInputValue + ? formatFixedLength(amountInputValue, 8) + : amountInputValue } setValue={(e) => { setAmountInputValue(e) @@ -429,11 +429,22 @@ const SwapWidget: FC = ({ aria-label="MAX" css={{ fontSize: 12 }} onClick={() => { + const percentageBuffer = (fromBalance * 1n) / 100n // 1% of the balance + const fixedBuffer = BigInt( + 0.02 * 10 ** (fromToken?.decimals ?? 18) + ) // Fixed buffer of 0.02 tokens + const solanaBuffer = + percentageBuffer > fixedBuffer + ? percentageBuffer + : fixedBuffer + if (fromToken) { setAmountInputValue( formatUnits( isFromNative - ? (fromBalance * 99n) / 100n + ? isSvmSwap + ? fromBalance - solanaBuffer + : fromBalance - percentageBuffer : fromBalance, fromToken?.decimals ) @@ -589,8 +600,8 @@ const SwapWidget: FC = ({ tradeType === 'EXACT_OUTPUT' ? amountOutputValue : amountOutputValue - ? formatFixedLength(amountOutputValue, 8) - : amountOutputValue + ? formatFixedLength(amountOutputValue, 8) + : amountOutputValue } setValue={(e) => { setAmountOutputValue(e)