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

Commit 0f6d49d

Browse files
committed
fix: upload document
1 parent ada60f4 commit 0f6d49d

File tree

3 files changed

+36
-15
lines changed

3 files changed

+36
-15
lines changed

apps/examples/sdk-react/src/app/app.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,30 @@ export function App() {
4444
}
4545
};
4646
fetchData();
47+
48+
const uploadFile = async (file: File) => {
49+
console.log(
50+
'%c file to upload',
51+
'color:white; padding: 30px; background-color: darkgreen',
52+
file
53+
);
54+
55+
const fileUploaded = await monerium?.uploadSupportingDocument(
56+
file as File
57+
);
58+
console.log(
59+
'%c fileUploaded',
60+
'color:white; padding: 30px; background-color: darkgreen',
61+
fileUploaded
62+
);
63+
};
64+
65+
document
66+
?.getElementById('fileInput')
67+
?.addEventListener('change', function (event) {
68+
const file = (event?.target as any)?.files?.[0];
69+
uploadFile(file);
70+
});
4771
}, [monerium, isAuthorized]);
4872

4973
return (
@@ -64,6 +88,7 @@ export function App() {
6488
)}
6589

6690
<p>{authCtx?.name || authCtx?.email}</p>
91+
{isAuthorized && <input type="file" id="fileInput"></input>}
6792
</div>
6893
);
6994
}

libs/sdk/src/client.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -342,16 +342,12 @@ export class MoneriumClient {
342342
* {@link https://monerium.dev/api-docs#operation/supporting-document}
343343
*/
344344
uploadSupportingDocument(document: File): Promise<SupportingDoc> {
345-
const searchParams = urlEncoded(
346-
document as unknown as Record<string, string>
347-
);
345+
const formData = new FormData();
346+
formData.append('file', document as unknown as Blob);
348347

349-
return this.#api<SupportingDoc>(
350-
'post',
351-
'files/supporting-document',
352-
searchParams,
353-
true
354-
);
348+
return rest<SupportingDoc>(`${this.#env.api}/files`, 'post', formData, {
349+
Authorization: this.#authorizationHeader || '',
350+
});
355351
}
356352

357353
// -- Helper Methods

libs/sdk/test/client.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
STORAGE_CODE_VERIFIER,
1515
STORAGE_REFRESH_TOKEN,
1616
} from '../src/constants';
17+
import { rfc3339 } from '../src/utils';
1718
import { Currency, Order, PaymentStandard } from '../src/types';
1819

1920
import {
@@ -254,7 +255,6 @@ describe('MoneriumClient', () => {
254255
expect.objectContaining({
255256
// id: '4b208818-44e3-11ed-adac-b2efc0e6677d',
256257
chain: 'ethereum',
257-
network: 'sepolia',
258258
address: PUBLIC_KEY,
259259
}),
260260
])
@@ -417,7 +417,9 @@ describe('MoneriumClient', () => {
417417
});
418418

419419
const date = new Date().toISOString();
420-
const placeOrderMessage = `Send EUR 10 to GR1601101250000000012300695 at ${date}`;
420+
const rfc3339date = rfc3339(new Date(date));
421+
422+
const placeOrderMessage = `Send EUR 10 to GR1601101250000000012300695 at ${rfc3339date}`;
421423
const placeOrderSignatureHash =
422424
'0x23bf7e1b240d238b13cb293673c3419915402bb34435af62850b1d8e63f82c564fb73ab19691cf248594423dd01e441bb2ccb38ce2e2ecc514dfc3075bea829e1c';
423425

@@ -440,10 +442,9 @@ describe('MoneriumClient', () => {
440442
memo: 'Powered by Monerium SDK',
441443
chainId: 11155111,
442444
chain: 'ethereum',
443-
network: 'sepolia',
444445
})
445446
.catch((err) => {
446-
expect(err.message).toBe('Invalid signature');
447+
expect(err.errors?.signature).toBe('invalid signature');
447448
});
448449
});
449450

@@ -479,11 +480,10 @@ describe('MoneriumClient', () => {
479480
message: placeOrderMessage,
480481
memo: 'Powered by Monerium SDK',
481482
chain: 'ethereum',
482-
network: 'sepolia',
483483
} as any /** to bypass typeerror for chain and network */
484484
)
485485
.catch((err) => {
486-
expect(err.message).toBe('Timestamp is expired');
486+
expect(err.errors?.message).toBe('timestamp is expired');
487487
});
488488
});
489489

0 commit comments

Comments
 (0)