Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
22_23-J 16
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
22_23-J 16
22_23-J 16
Commits
362fe9dc
Commit
362fe9dc
authored
May 17, 2023
by
Ishini Kiridena
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
view and send NFT completed
parent
9ab56074
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
157 additions
and
5 deletions
+157
-5
ExpressBackend/route/patient-routes/view-nft-requests-route.js
...ssBackend/route/patient-routes/view-nft-requests-route.js
+45
-0
ExpressBackend/route/practitioner-routes/get-assetcode-practitioner-route.js
...e/practitioner-routes/get-assetcode-practitioner-route.js
+1
-1
emma-frontend/components/patientscreens/nftRequests.js
emma-frontend/components/patientscreens/nftRequests.js
+111
-4
No files found.
ExpressBackend/route/patient-routes/view-nft-requests-route.js
0 → 100644
View file @
362fe9dc
const
express
=
require
(
"
express
"
);
const
router
=
express
.
Router
();
const
Patient
=
require
(
"
./../../model/patient/patient
"
);
const
NFTRequest
=
require
(
"
./../../model/stellar/nftRequests
"
);
router
.
get
(
"
/:patientKey
"
,
async
(
req
,
res
)
=>
{
const
patientKey
=
req
.
params
.
patientKey
;
try
{
const
issuerData
=
await
Patient
.
findOne
({
publickey
:
patientKey
,
});
//get the NFT requests
try
{
const
NFTrequests
=
await
NFTRequest
.
find
({
issuerpk
:
issuerData
.
issuerpk
,
});
res
.
status
(
200
).
json
({
data
:
NFTrequests
,
});
console
.
log
(
"
Data taken successfully
"
);
}
catch
(
errorWhenGettingTheNftRrquests
)
{
console
.
log
(
"
Error when getting the NFT requests :
"
,
errorWhenGettingTheNftRrquests
);
res
.
status
(
500
).
json
({
error
:
"
Error when getting the NFT requests :
"
,
errorWhenGettingTheNftRrquests
,
});
}
}
catch
(
errorWhenGettingTheIssuerKey
)
{
console
.
log
(
"
Error when getting the issuer key :
"
,
errorWhenGettingTheIssuerKey
);
res
.
status
(
500
).
json
({
error
:
"
Error when getting the issuer key :
"
,
errorWhenGettingTheIssuerKey
,
});
}
});
module
.
exports
=
router
;
ExpressBackend/route/practitioner-routes/get-assetcode-practitioner-route.js
View file @
362fe9dc
...
...
@@ -2,7 +2,7 @@ const express = require("express");
const
router
=
express
.
Router
();
const
AssetCodeWithPractitioner
=
require
(
"
./../../model/stellar/assetCodeWithPractitioner
"
);
router
.
get
(
"
.
/:practitionerKey
"
,
async
(
req
,
res
)
=>
{
router
.
get
(
"
/:practitionerKey
"
,
async
(
req
,
res
)
=>
{
const
practitionerKey
=
req
.
params
.
practitionerKey
;
try
{
...
...
emma-frontend/components/patientscreens/nftRequests.js
View file @
362fe9dc
import
React
from
"
react
"
;
import
{
View
,
Text
,
StyleSheet
}
from
"
react-native
"
;
import
{
useEffect
,
useState
}
from
"
react
"
;
import
{
LOCALBACKEND
}
from
"
../../env
"
;
import
{
Button
,
StyleSheet
,
View
,
Text
,
Alert
}
from
"
react-native
"
;
import
AsyncStorage
from
"
@react-native-async-storage/async-storage
"
;
import
EncryptWithServerKey
from
"
../../services/encryptByServerKey
"
;
import
Toast
from
"
react-native-toast-message
"
;
export
default
function
PatientNFTRequests
({
navigation
})
{
const
[
data
,
setData
]
=
useState
([]);
const
[
assetData
,
setAssetData
]
=
useState
();
useEffect
(()
=>
{
fetchRequests
();
},
[]);
const
fetchRequests
=
async
()
=>
{
//get key from async storage
try
{
const
patientKey
=
await
AsyncStorage
.
getItem
(
"
patientStellarPublicKey
"
);
const
patientSeed
=
await
AsyncStorage
.
getItem
(
"
patientStellarSecretKey
"
);
try
{
const
requestUrl
=
LOCALBACKEND
+
`/nftrequests/
${
patientKey
}
`
;
console
.
log
(
requestUrl
);
const
response
=
await
fetch
(
requestUrl
);
const
json
=
await
response
.
json
();
setData
(
json
.
data
);
}
catch
(
errorFetchingRequests
)
{
console
.
log
(
"
Error when fetching request data :
"
,
errorFetchingRequests
);
}
}
catch
(
errorWhenGettingKey
)
{
console
.
log
(
"
Error when getting the public key from the async storage :
"
,
errorWhenGettingKey
);
}
};
const
renderItem
=
(
item
)
=>
{
return
(
<
View
key
=
{
item
.
_id
}
>
<
Text
>
Key
:
{
item
.
requesterpk
}
<
/Text
>
<
Button
title
=
"
Send NFT
"
onPress
=
{()
=>
handleSendNFT
(
item
)}
><
/Button
>
<
/View
>
);
};
const
handleSendNFT
=
async
(
item
)
=>
{
//get the asset code for the specific practitioner
try
{
const
patientKey
=
await
AsyncStorage
.
getItem
(
"
patientStellarPublicKey
"
);
const
patientSeed
=
await
AsyncStorage
.
getItem
(
"
patientStellarSecretKey
"
);
try
{
const
assetUrl
=
LOCALBACKEND
+
`/practitioner/getassetcode/
${
item
.
requesterpk
}
`
;
const
response
=
await
fetch
(
assetUrl
);
const
json
=
await
response
.
json
();
setAssetData
(
json
.
assetcode
);
//send the NFT
const
practitionerPubKey
=
item
.
requesterpk
;
const
practitionerRsaKey
=
item
.
requesterrsa
;
const
assetCode
=
assetData
;
const
sendNFTObj
=
{
patientkey
:
patientKey
,
patientseed
:
patientSeed
,
practitioner
:
practitionerPubKey
,
practitionerrsa
:
practitionerRsaKey
,
assetcode
:
assetCode
,
};
const
nftUrl
=
LOCALBACKEND
+
`/patient/createnft`
;
try
{
const
nftResponse
=
await
fetch
(
nftUrl
,
{
method
:
"
POST
"
,
headers
:
{
"
Content-Type
"
:
"
application/json
"
,
},
body
:
JSON
.
stringify
(
sendNFTObj
),
});
const
nftResponseData
=
await
nftResponse
.
json
();
Toast
.
show
({
type
:
"
success
"
,
// 'success', 'error', 'info', 'warning'
text1
:
"
EHR sent
"
,
visibilityTime
:
3000
,
// Duration to show the toast in milliseconds
autoHide
:
true
,
});
}
catch
(
errorWhenSendingNft
)
{
console
.
error
(
"
Error when sending NFT :
"
,
errorWhenSendingNft
);
}
}
catch
(
errorWhenGettingAssetCode
)
{
console
.
error
(
"
Error when getting the asset code :
"
,
errorWhenGettingAssetCode
);
}
}
catch
(
errorWhenGettingKeyPair
)
{
console
.
error
(
"
Error when getting key pair :
"
,
errorWhenGettingKeyPair
);
}
};
export
default
function
PatientNFTRequests
({
navigation
,
router
})
{
return
(
<
View
style
=
{
styles
.
container
}
>
<
Text
style
=
{
styles
.
text
}
>
All
NFTrequests
<
/Text
>
{
data
.
map
((
item
)
=>
renderItem
(
item
))}
<
Toast
ref
=
{(
ref
)
=>
Toast
.
setRef
(
ref
)}
/
>
<
/View
>
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment