Skip to content

Commit

Permalink
do-next (ZcashFoundation#21)
Browse files Browse the repository at this point in the history
Fix bugs identified in test/stage of big refactor
  • Loading branch information
skyl authored Nov 20, 2022
1 parent f5854bc commit 9652f90
Show file tree
Hide file tree
Showing 13 changed files with 440 additions and 388 deletions.
1 change: 1 addition & 0 deletions py/dj/apps/g12f/serializers/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class Meta:
'banner_url',
'full_name',
'description',
'p2paddr',
]
model = Creator
extra_fields = []
Expand Down
31 changes: 22 additions & 9 deletions py/dj/apps/g12f/views/zpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from functools import reduce
from unicodedata import category
from django import http
from django.db.utils import IntegrityError

from django.shortcuts import get_object_or_404, render
from rest_framework import (
Expand All @@ -13,8 +14,9 @@
from rest_framework.request import Request
from rest_framework.response import Response
from dj.apps.g12f.serializers import (
zPageListSerializer, zPageCreateSerializer, zPageUpdateSerializer,
zPageDetailSerializer
zPageListSerializer, zPageUpdateSerializer,
zPageDetailSerializer,
zPageCreateSerializer,
)
from rest_framework.views import APIView
from dj.apps.g12f.models import zPage
Expand Down Expand Up @@ -93,7 +95,8 @@ class zPageView(
serializers = {
'list': zPageListSerializer,
'retrieve': zPageDetailSerializer,
'create': zPageCreateSerializer,
# 'create': zPageCreateSerializer,
'create': zPageUpdateSerializer,
'update': zPageUpdateSerializer,
'partial_update': zPageUpdateSerializer,
'destroy': zPageCreateSerializer,
Expand Down Expand Up @@ -209,9 +212,9 @@ def get_serializer_class(self):
# lookup_field =

def create(self, request: Request) -> Response:
# print(dir(request))
# addr = f2z.new_addr()
addr = str(uuid.uuid4())

if request.user.is_anonymous:
raise exceptions.PermissionDenied

Expand All @@ -230,11 +233,21 @@ def create(self, request: Request) -> Response:
# ):
# raise exceptions.PermissionDenied

page = zPage.objects.create(
creator=request.user,
free2zaddr=addr,
is_verified=request.user.is_verified,
)
# serializer = self.get_serializer(
# instance, data=request.data, partial=partial)
# serializer.is_valid(raise_exception=True)
try:
page = zPage.objects.create(
creator=request.user,
free2zaddr=addr,
is_verified=request.user.is_verified,
vanity=request.data.get('vanity'),
)
except IntegrityError:
return Response(
status=status.HTTP_400_BAD_REQUEST,
data="The vanity URL must be unique!"
)

serializer = zPageListSerializer(page)
return Response(serializer.data)
Expand Down
3 changes: 2 additions & 1 deletion ts/react/free2z/src/Begin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function Begin() {
const navigate = useNavigate()

useEffect(() => {
setLoading(true)
axios
.get("/api/auth/user/")
.then((res) => {
Expand All @@ -43,7 +44,7 @@ function Begin() {
.catch((res) => {
setAuth(false)
setLoading(false)
setCreator({} as Creator)
// setCreator({} as Creator)
})
}, [])

Expand Down
9 changes: 8 additions & 1 deletion ts/react/free2z/src/CreatorLoginModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ interface FormDialogProps {

export default function FormDialog(props: FormDialogProps) {
const [_, setSnackbarState] = useGlobalState("snackbar")
const [loading, setLoading] = useGlobalState("loading")

const recaptchaRef = React.createRef() as React.RefObject<ReCAPTCHA>
const [captchaResult, setCaptchaResult] = React.useState<string | null>(null)
Expand All @@ -61,11 +62,12 @@ export default function FormDialog(props: FormDialogProps) {
}

const handleSuccess = () => {
setLoading(false)
navigateCreateOrDashboard(navigate)
}

const handleCreate = () => {

setLoading(true)
const exst = "A user with that username already exists."
const data = {
username: name,
Expand Down Expand Up @@ -97,6 +99,7 @@ export default function FormDialog(props: FormDialogProps) {
severity: "error",
duration: null,
})
setLoading(false)
throw "She's dead, jim"
}

Expand All @@ -112,6 +115,7 @@ export default function FormDialog(props: FormDialogProps) {
severity: "error",
duration: null,
})
setLoading(false)
}
// bad usernname on create
if (resp.data.username[0] !== exst) {
Expand All @@ -121,6 +125,7 @@ export default function FormDialog(props: FormDialogProps) {
severity: "error",
duration: null,
})
setLoading(false)
}

// it's an existing user, log them in
Expand All @@ -146,6 +151,7 @@ export default function FormDialog(props: FormDialogProps) {
severity: "error",
duration: null,
})
setLoading(false)
// console.log(res.data.non_field_errors)
// TODO: stack snackbar ... but these are the best errors
if (res.data.non_field_errors) {
Expand All @@ -158,6 +164,7 @@ export default function FormDialog(props: FormDialogProps) {
res.data.non_field_errors
),
})
setLoading(false)
}
})
}
Expand Down
Loading

0 comments on commit 9652f90

Please sign in to comment.