refactor purchases page with states