intrepidshape/elm-web3-ui/2.0.0

NOTE: the latest version is 4.0.0

Web3.Ui.SlippageInput

Slippage tolerance picker for trade UIs. Renders a row of preset chips (0.1% / 0.5% / 1%) plus a custom input. Returns the chosen value as basis points so the caller can compute minTokensOut / minPlsOut.

Web3.Ui.SlippageInput.view
    { valueBps = model.slippageBps
    , onChange = SlippageChanged
    , presetsBps = [ 10, 50, 100 ]   -- 0.1%, 0.5%, 1%
    }


-- Helper: derive the minOut value given an expected amount and slippage.
let
    minOut =
        Web3.Ui.SlippageInput.minOutFromBps model.slippageBps expectedAmount
in
contractCall { ..., minOut = minOut }

Style classes: web3-slippage, web3-slippage__chip, web3-slippage__chip--active, web3-slippage__custom.

view : Config msg -> Html msg

Render the picker.

type alias Config msg =
{ valueBps : Int
, onChange : Int -> msg
, presetsBps : List Int
}
minOutFromBps : Int -> BigInt -> BigInt

Compute expected * (10000 - slippageBps) / 10000 in BigInt arithmetic. Returns BigInt.zero if the slippage exceeds 100%.