Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Too many tokens to sign #157

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 58 additions & 79 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export const App = () => {
data: wcSdk.session.peer,
tokens: {
container: {},
object: {}
object: null
}
});
onPopup('success', 'Wallet connected');
Expand Down Expand Up @@ -197,8 +197,15 @@ export const App = () => {
}
}
}
if (type === 'object') {
walletDataTemp.tokens[type] = {
...params,
token: msg,
signature: response.data + response.salt,
};
}
if (bearer) {
walletDataTemp.tokens[type][operation].bearer = bearer;
walletDataTemp.tokens[type].bearer = bearer;
}
if (!walletDataTemp.expiry || walletDataTemp.expiry < new Date().getTime()) {
walletDataTemp.expiry = new Date().getTime() + 7200000;
Expand All @@ -217,7 +224,23 @@ export const App = () => {
} else if (type === 'object') {
body = [{
"object": [{
"operation": operation,
"operation": 'GET',
"action": "ALLOW",
"filters": [],
"targets": [{
"role": "OTHERS",
"keys": []
}]
}, {
"operation": 'PUT',
"action": "ALLOW",
"filters": [],
"targets": [{
"role": "OTHERS",
"keys": []
}]
}, {
"operation": 'DELETE',
"action": "ALLOW",
"filters": [],
"targets": [{
Expand Down Expand Up @@ -402,7 +425,7 @@ export const App = () => {
attributes.map((attribute) => attributesHeaders[`X-Attribute-${attribute.key}`] = attribute.value);
api('POST', `/upload/${containerId}`, formdata, {
'Content-Type': "multipart/form-data",
[AuthorizationHeader]: `Bearer ${walletData.tokens.object.PUT.bearer}`,
[AuthorizationHeader]: `Bearer ${walletData.tokens.object.bearer}`,
...attributesHeaders,
}).then((e) => {
setLoadingForm(false);
Expand Down Expand Up @@ -432,14 +455,14 @@ export const App = () => {
};

const onDeleteObject = (containerId, objectId) => {
if (walletData.tokens.object.DELETE) {
if (walletData.tokens.object) {
setError({ active: false, type: [], text: '' });
setLoadingForm(true);
api('DELETE', `/objects/${containerId}/${objectId}?walletConnect=true`, {}, {
[ContentTypeHeader]: "application/json",
[AuthorizationHeader]: `Bearer ${walletData.tokens.object.DELETE.token}`,
[AuthorizationHeader]: `Bearer ${walletData.tokens.object.token}`,
[BearerOwnerIdHeader]: walletData.account,
[BearerSignatureHeader]: walletData.tokens.object.DELETE.signature,
[BearerSignatureHeader]: walletData.tokens.object.signature,
[BearerSignatureKeyHeader]: walletData.publicKey,
}).then((e) => {
setLoadingForm(false);
Expand All @@ -451,7 +474,7 @@ export const App = () => {
}
});
} else {
onModal('signTokens', 'object.DELETE');
onModal('signTokens', 'object');
}
};

Expand Down Expand Up @@ -634,76 +657,32 @@ export const App = () => {
)}
</Columns.Column>
)}
{(modal.text === '' || modal.text === 'object.PUT' || modal.text === 'object.DELETE' || modal.text === 'object.GET') && (
{(modal.text === '' || modal.text === 'object') && (
<Columns.Column>
{(modal.text === '' || modal.text === 'object.PUT') && (
<div className="token_status_panel">
<Heading size={6} style={{ margin: '0 10px 0 0' }}>Sign token to unlock create&nbsp;operation</Heading>
{walletData && walletData.tokens.object.PUT ? (
<img
src="/img/icons/success.svg"
height={25}
width={25}
alt="success"
/>
) : (
<Button
color="primary"
size="small"
onClick={() => onAuth('object', 'PUT')}
>
Sign
</Button>
)}
</div>
)}
{(modal.text === '' || modal.text === 'object.DELETE') && (
<div className="token_status_panel">
<Heading size={6} style={{ margin: '0 10px 0 0' }}>Sign token to unlock delete&nbsp;operation</Heading>
{walletData && walletData.tokens.object.DELETE ? (
<img
src="/img/icons/success.svg"
height={25}
width={25}
alt="success"
/>
) : (
<Button
color="primary"
size="small"
onClick={() => onAuth('object', 'DELETE')}
>
Sign
</Button>
)}
</div>
)}
{(modal.text === '' || modal.text === 'object.GET') && (
<div className="token_status_panel">
<Heading size={6} style={{ margin: '0 10px 0 0' }}>Sign token to unlock get&nbsp;operation</Heading>
{walletData && walletData.tokens.object.GET ? (
<img
src="/img/icons/success.svg"
height={25}
width={25}
alt="success"
/>
) : (
<Button
color="primary"
size="small"
onClick={() => onAuth('object', 'GET', modal.params)}
>
Sign
</Button>
)}
</div>
)}
<div className="token_status_panel">
<Heading size={6} style={{ margin: '0 10px 0 0' }}>Sign token to unlock object&nbsp;operations</Heading>
{walletData && walletData.tokens.object ? (
<img
src="/img/icons/success.svg"
height={25}
width={25}
alt="success"
/>
) : (
<Button
color="primary"
size="small"
onClick={() => onAuth('object', null, modal.params)}
>
Sign
</Button>
)}
</div>
</Columns.Column>
)}
</Columns>
{walletData && walletData.tokens.container.PUT && walletData.tokens.container.DELETE && walletData.tokens.container.SETEACL
&& walletData.tokens.object.PUT && walletData.tokens.object.DELETE && walletData.tokens.object.GET && (
&& walletData.tokens.object && (
<Button
color="primary"
onClick={onModal}
Expand Down Expand Up @@ -1169,13 +1148,13 @@ export const App = () => {
{isError.text}
</Notification>
)}
{!walletData.tokens.object.PUT ? (
{!walletData.tokens.object ? (
<div className="token_status_panel" style={{ marginTop: '25px' }}>
<Heading size={6} style={{ margin: '0 10px 0 0' }}>Sign token to unlock create&nbsp;operation</Heading>
<Heading size={6} style={{ margin: '0 10px 0 0' }}>Sign token to unlock object&nbsp;operations</Heading>
<Button
color="primary"
size="small"
onClick={() => onAuth('object', 'PUT')}
onClick={() => onAuth('object')}
>
Sign
</Button>
Expand Down Expand Up @@ -1239,13 +1218,13 @@ export const App = () => {
{isError.text}
</Notification>
)}
{!walletData.tokens.object.DELETE ? (
{!walletData.tokens.object ? (
<div className="token_status_panel">
<Heading size={6} style={{ margin: '0 10px 0 0' }}>Sign token to unlock delete&nbsp;operation</Heading>
<Heading size={6} style={{ margin: '0 10px 0 0' }}>Sign token to unlock object&nbsp;operations</Heading>
<Button
color="primary"
size="small"
onClick={() => onAuth('object', 'DELETE')}
onClick={() => onAuth('object')}
>
Sign
</Button>
Expand Down
15 changes: 6 additions & 9 deletions src/Components/ContainerItem/ContainerItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function ContainerItem({
}, [isLoadContainers]); // eslint-disable-line react-hooks/exhaustive-deps

useEffect(() => {
if (walletData.tokens.object.GET && walletData.tokens.object.GET.containerId === containerItem.containerId) {
if (walletData.tokens.object && walletData.tokens.object.containerId === containerItem.containerId) {
setActivePanel('objects');
onGetObjects(containerItem.containerId);
onModal();
Expand All @@ -57,10 +57,7 @@ export default function ContainerItem({
...walletData.tokens,
object: {
...walletData.tokens.object,
GET: {
...walletData.tokens.object.GET,
containerId: null,
}
containerId: null,
}
}
});
Expand Down Expand Up @@ -90,9 +87,9 @@ export default function ContainerItem({
"filters": [],
}, {
[ContentTypeHeader]: "application/json",
[AuthorizationHeader]: `Bearer ${walletData.tokens.object.GET.token}`,
[AuthorizationHeader]: `Bearer ${walletData.tokens.object.token}`,
[BearerOwnerIdHeader]: walletData.account,
[BearerSignatureHeader]: walletData.tokens.object.GET.signature,
[BearerSignatureHeader]: walletData.tokens.object.signature,
[BearerSignatureKeyHeader]: walletData.publicKey,
}).then((e) => {
setLoadingObjects(false);
Expand Down Expand Up @@ -283,8 +280,8 @@ export default function ContainerItem({
size={6}
weight="bolder"
onClick={() => {
if (!walletData.tokens.object.GET) {
onModal('signTokens', 'object.GET', { containerId: containerItem.containerId });
if (!walletData.tokens.object) {
onModal('signTokens', 'object', { containerId: containerItem.containerId });
} else if (activePanel === 'objects') {
setActivePanel('');
} else {
Expand Down
12 changes: 6 additions & 6 deletions src/Components/TreeView/TreeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ const File = ({
if (!isOpen) {
api('GET', `/objects/${containerItem.containerId}/${objectItem.address.objectId}?walletConnect=true`, {}, {
[ContentTypeHeader]: "application/json",
[AuthorizationHeader]: `Bearer ${walletData.tokens.object.GET.token}`,
[AuthorizationHeader]: `Bearer ${walletData.tokens.object.token}`,
[BearerOwnerIdHeader]: walletData.account,
[BearerSignatureHeader]: walletData.tokens.object.GET.signature,
[BearerSignatureHeader]: walletData.tokens.object.signature,
[BearerSignatureKeyHeader]: walletData.publicKey,
}).then((e) => {
setObjectDate(e);
Expand Down Expand Up @@ -185,9 +185,9 @@ const File = ({
onModal('loading');
api('GET', `/get/${containerItem.containerId}/${objectItem.address.objectId}`, {}, {
[ContentTypeHeader]: "application/json",
[AuthorizationHeader]: `Bearer ${walletData.tokens.object.GET.token}`,
[AuthorizationHeader]: `Bearer ${walletData.tokens.object.token}`,
[BearerOwnerIdHeader]: walletData.account,
[BearerSignatureHeader]: walletData.tokens.object.GET.signature,
[BearerSignatureHeader]: walletData.tokens.object.signature,
[BearerSignatureKeyHeader]: walletData.publicKey,
}).then((data) => {
if (data.status !== 200) {
Expand Down Expand Up @@ -223,7 +223,7 @@ const File = ({
onModal('loading');
api('GET', `/get/${containerItem.containerId}/${objectItem.address.objectId}`, {}, {
[ContentTypeHeader]: "application/json",
[AuthorizationHeader]: `Bearer ${walletData.tokens.object.GET.bearer}`,
[AuthorizationHeader]: `Bearer ${walletData.tokens.object.bearer}`,
}).then((data) => {
if (data.status !== 200) {
onModal('failed', 'Something went wrong, try again');
Expand Down Expand Up @@ -258,7 +258,7 @@ const File = ({
onModal('loading');
api('GET', `/get/${containerItem.containerId}/${objectItem.address.objectId}`, {}, {
[ContentTypeHeader]: "application/json",
[AuthorizationHeader]: `Bearer ${walletData.tokens.object.GET.bearer}`,
[AuthorizationHeader]: `Bearer ${walletData.tokens.object.bearer}`,
}).then((data) => {
const a = document.createElement('a');
document.body.appendChild(a);
Expand Down
Loading