Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Commit

Permalink
fix: upload document
Browse files Browse the repository at this point in the history
  • Loading branch information
einaralex committed Mar 12, 2024
1 parent ada60f4 commit 0f6d49d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
25 changes: 25 additions & 0 deletions apps/examples/sdk-react/src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,30 @@ export function App() {
}
};
fetchData();

const uploadFile = async (file: File) => {
console.log(
'%c file to upload',
'color:white; padding: 30px; background-color: darkgreen',
file
);

const fileUploaded = await monerium?.uploadSupportingDocument(
file as File
);
console.log(
'%c fileUploaded',
'color:white; padding: 30px; background-color: darkgreen',
fileUploaded
);
};

document
?.getElementById('fileInput')
?.addEventListener('change', function (event) {
const file = (event?.target as any)?.files?.[0];
uploadFile(file);
});
}, [monerium, isAuthorized]);

return (
Expand All @@ -64,6 +88,7 @@ export function App() {
)}

<p>{authCtx?.name || authCtx?.email}</p>
{isAuthorized && <input type="file" id="fileInput"></input>}
</div>
);
}
Expand Down
14 changes: 5 additions & 9 deletions libs/sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,16 +342,12 @@ export class MoneriumClient {
* {@link https://monerium.dev/api-docs#operation/supporting-document}
*/
uploadSupportingDocument(document: File): Promise<SupportingDoc> {
const searchParams = urlEncoded(
document as unknown as Record<string, string>
);
const formData = new FormData();
formData.append('file', document as unknown as Blob);

return this.#api<SupportingDoc>(
'post',
'files/supporting-document',
searchParams,
true
);
return rest<SupportingDoc>(`${this.#env.api}/files`, 'post', formData, {
Authorization: this.#authorizationHeader || '',
});
}

// -- Helper Methods
Expand Down
12 changes: 6 additions & 6 deletions libs/sdk/test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
STORAGE_CODE_VERIFIER,
STORAGE_REFRESH_TOKEN,
} from '../src/constants';
import { rfc3339 } from '../src/utils';
import { Currency, Order, PaymentStandard } from '../src/types';

import {
Expand Down Expand Up @@ -254,7 +255,6 @@ describe('MoneriumClient', () => {
expect.objectContaining({
// id: '4b208818-44e3-11ed-adac-b2efc0e6677d',
chain: 'ethereum',
network: 'sepolia',
address: PUBLIC_KEY,
}),
])
Expand Down Expand Up @@ -417,7 +417,9 @@ describe('MoneriumClient', () => {
});

const date = new Date().toISOString();
const placeOrderMessage = `Send EUR 10 to GR1601101250000000012300695 at ${date}`;
const rfc3339date = rfc3339(new Date(date));

const placeOrderMessage = `Send EUR 10 to GR1601101250000000012300695 at ${rfc3339date}`;
const placeOrderSignatureHash =
'0x23bf7e1b240d238b13cb293673c3419915402bb34435af62850b1d8e63f82c564fb73ab19691cf248594423dd01e441bb2ccb38ce2e2ecc514dfc3075bea829e1c';

Expand All @@ -440,10 +442,9 @@ describe('MoneriumClient', () => {
memo: 'Powered by Monerium SDK',
chainId: 11155111,
chain: 'ethereum',
network: 'sepolia',
})
.catch((err) => {
expect(err.message).toBe('Invalid signature');
expect(err.errors?.signature).toBe('invalid signature');
});
});

Expand Down Expand Up @@ -479,11 +480,10 @@ describe('MoneriumClient', () => {
message: placeOrderMessage,
memo: 'Powered by Monerium SDK',
chain: 'ethereum',
network: 'sepolia',
} as any /** to bypass typeerror for chain and network */
)
.catch((err) => {
expect(err.message).toBe('Timestamp is expired');
expect(err.errors?.message).toBe('timestamp is expired');
});
});

Expand Down

0 comments on commit 0f6d49d

Please sign in to comment.