Skip to content

Commit

Permalink
fix(frontend): 🐛 use swiss grid coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
apttx committed Dec 18, 2024
1 parent 71b14cb commit ea64b84
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
4 changes: 2 additions & 2 deletions frontend/src/lib/certificate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export interface BidiCertificate {
latitude: number
longitude: number
swissGridE: number
swissGridN: number
typeOfNaturalObject: string
locationOwner: string
operationsManager: string
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lib/hedera/getNfts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export const getNfts: GetNfts = async (options): Promise<Nft[]> => {
certificate: {
dateOfWork: '1970-01-01',
effectOnBiodiversity: '',
latitude: 0,
longitude: 0,
swissGridE: 0,
swissGridN: 0,
locationOwner: '',
operationsManager: '',
typeOfNaturalObject: '',
Expand Down
34 changes: 18 additions & 16 deletions frontend/src/routes/dashboard/mint/CertificateCreationForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
import Textarea from '$lib/components/Textarea.svelte'
import { AccountId } from '@hashgraph/sdk'
const coordinatePattern = /\d{3}\s?\d{3}/
let {
onsubmit,
}: {
onsubmit: (options: { certificate: BidiCertificate; recipientAccountId: AccountId }) => void
} = $props()
let latitudeString = $state('')
let longitudeString = $state('')
let swissGridEString = $state('')
const swissGridE = $derived(parseInt(swissGridEString.replace(/\s/g, '')))
let swissGridNString = $state('')
const swissGridN = $derived(parseInt(swissGridNString.replace(/\s/g, '')))
let typeOfNaturalObject = $state('')
let locationOwner = $state('')
let operationsManager = $state('')
Expand All @@ -26,19 +30,17 @@
event.preventDefault()

// TODO: handle errors
const latitude = parseFloat(latitudeString)
if (isNaN(latitude)) {
if (isNaN(swissGridE)) {
return
}

const longitude = parseFloat(longitudeString)
if (isNaN(longitude)) {
if (isNaN(swissGridN)) {
return
}

const certificate: BidiCertificate = {
latitude,
longitude,
swissGridE,
swissGridN,
typeOfNaturalObject,
locationOwner,
operationsManager,
Expand All @@ -60,19 +62,19 @@
<legend>Coordinates:</legend>

<Input
label="Latitude"
placeholder="46.8"
bind:value={latitudeString}
label="E"
placeholder="600 000"
bind:value={swissGridEString}
required
pattern={/\d+(?:\.\d+)?/}
pattern={coordinatePattern}
/>

<Input
label="Longitude"
placeholder="8.233333"
bind:value={longitudeString}
label="N"
placeholder="200 000"
bind:value={swissGridNString}
required
pattern={/\d+(?:\.\d+)?/}
pattern={coordinatePattern}
/>
</fieldset>
</div>
Expand Down

0 comments on commit ea64b84

Please sign in to comment.