diff --git a/package.json b/package.json index c8cc23e..9ccff0a 100644 --- a/package.json +++ b/package.json @@ -58,5 +58,6 @@ "vite": "^3.1.8", "vitest": "^0.24.3" }, - "type": "module" -} \ No newline at end of file + "type": "module", + "dependencies": {} +} diff --git a/src/lib/services/events.service.ts b/src/lib/services/events.service.ts index e0a6a5d..294e887 100644 --- a/src/lib/services/events.service.ts +++ b/src/lib/services/events.service.ts @@ -190,7 +190,7 @@ export function createEventsService(iframeUrl: string, authService: AuthService, const quotePayload = payload; - const callback = (quote: Quote) => sendEvent(frame, Events.QUOTE_CHANGED, { quote }); + const callback = (quote: Quote | null, err: any) => sendEvent(frame, Events.QUOTE_CHANGED, { quote, err }); quoteService.startQuote(quotePayload, callback); } @@ -202,10 +202,12 @@ export function createEventsService(iframeUrl: string, authService: AuthService, if (!frame) throw new Error("Iframe not ready"); try { - let paymentInfo = {}; + const paymentInfo = {}; paymentInfo.cardToken = event.data.cardToken; - let data = event.data; + + const data = event.data; data.paymentInfo = paymentInfo; + const txHash = await apiClient.transact(data); sendEvent(frame, Events.RECEIVE_CONFIRM_TRANSACTION, txHash); } catch (error: any) { diff --git a/src/lib/services/quote.service.ts b/src/lib/services/quote.service.ts index c549250..b09eb17 100644 --- a/src/lib/services/quote.service.ts +++ b/src/lib/services/quote.service.ts @@ -3,14 +3,14 @@ import type { ApiClient, TransactionRequest, Quote } from './apiClient.service'; export function createQuoteService(apiClient: ApiClient): QuoteService { let interval: NodeJS.Timer | undefined; - async function startQuote(payload: TransactionRequest, callback: (payload: Quote) => void) { - refreshQuote(payload, callback); + async function startQuote(payload: TransactionRequest, callback: (quote: Quote | null, err: any) => void) { + _refreshQuote(payload, callback); if (interval) { clearInterval(interval); } - interval = setInterval(() => refreshQuote(payload, callback), 10000); + interval = setInterval(() => _refreshQuote(payload, callback), 10000); } function stopQuote() { @@ -18,24 +18,23 @@ export function createQuoteService(apiClient: ApiClient): QuoteService { interval = undefined; } - async function refreshQuote(payload: TransactionRequest, callback: (payload: Quote) => void) { + async function _refreshQuote(payload: TransactionRequest, callback: (quote: Quote | null, err: any) => void) { try { const quote = await apiClient.getQuote(payload); - callback(quote); - } catch (e) { - console.debug('-- refresh quote error --', e); + callback(quote, null); + } catch (err: any) { + console.debug('-- refresh quote error --', err); + callback(null, err); } } return { startQuote, stopQuote, - refreshQuote, }; } export interface QuoteService { - startQuote: (payload: TransactionRequest, callback: (payload: Quote) => void) => Promise; + startQuote: (payload: TransactionRequest, callback: (quote: Quote | null, err: any) => void) => Promise; stopQuote: () => void; - refreshQuote: (payload: TransactionRequest, callback: (payload: Quote) => void) => Promise; } \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index ba7ed79..8a58f3d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1251,15 +1251,10 @@ caniuse-api@^3.0.0: lodash.memoize "^4.1.2" lodash.uniq "^4.5.0" -caniuse-lite@^1.0.0: - version "1.0.30001419" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001419.tgz#3542722d57d567c8210d5e4d0f9f17336b776457" - integrity sha512-aFO1r+g6R7TW+PNQxKzjITwLOyDhVRLjW0LcwS/HCZGUUKTGNp9+IwLC4xyDSZBygVL/mxaFR3HIV6wEKQuSzw== - -caniuse-lite@^1.0.30001400, caniuse-lite@^1.0.30001407: - version "1.0.30001412" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001412.tgz#30f67d55a865da43e0aeec003f073ea8764d5d7c" - integrity sha512-+TeEIee1gS5bYOiuf+PS/kp2mrXic37Hl66VY6EAfxasIk5fELTktK2oOezYed12H8w7jt3s512PpulQidPjwA== +caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001400, caniuse-lite@^1.0.30001407: + version "1.0.30001480" + resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001480.tgz" + integrity sha512-q7cpoPPvZYgtyC4VaBSN0Bt+PJ4c4EYRf0DrduInOz2SkFpHD5p3LnvEpqBp7UnJn+8x1Ogl1s38saUxe+ihQQ== chai@^4.3.6: version "4.3.6"