Skip to content

Commit

Permalink
Trigger load and monetization events
Browse files Browse the repository at this point in the history
  • Loading branch information
raducristianpopa committed Nov 6, 2023
1 parent 5289732 commit a7fe694
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 56 deletions.
10 changes: 3 additions & 7 deletions src/background/grantFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export class PaymentFlowService {
new URL(this.receivingPaymentPointerUrl).origin + '/incoming-payments',
{
walletAddress: this.receivingPaymentPointerUrl,
expiresAt: new Date(Date.now() + 6000 * 60 * 10).toISOString(),
},
this.getHeaders(this.clientAuthToken),
)
Expand Down Expand Up @@ -218,7 +219,6 @@ export class PaymentFlowService {
}

async getContinuationRequest() {
console.log()
const continuationRequest = await this.axiosInstance.post(
this.outgoingPaymentGrantData.continue.uri,
{
Expand Down Expand Up @@ -299,12 +299,8 @@ export class PaymentFlowService {
}

async sendPayment() {
await this.createQuote().catch(async () => {
await this.rotateToken()
})
await this.runPayment().catch(async () => {
await this.rotateToken()
})
await this.createQuote()
await this.runPayment()
}

async getCurrentActiveTabId() {
Expand Down
2 changes: 1 addition & 1 deletion src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const iconActive34 = runtime.getURL('assets/icons/icon-active-34.png')
const iconActive128 = runtime.getURL('assets/icons/icon-active-128.png')
const iconInactive34 = runtime.getURL('assets/icons/icon-inactive-34.png')
const iconInactive128 = runtime.getURL('assets/icons/icon-inactive-128.png')
//

// const SENDING_PAYMENT_POINTER_URL = 'https://ilp.rafiki.money/wmuser' // cel din extensie al userului
// const RECEIVING_PAYMENT_POINTER_URL = 'https://ilp.rafiki.money/web-page' // cel din dom

Expand Down
35 changes: 16 additions & 19 deletions src/content/messageListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,23 @@ export const onRequest = async (

case 'PAYMENT_SUCCESS': {
const { receiveAmount, incomingPayment, paymentPointer } = msg.data
const monetizationTag = document.querySelector('link[rel="monetization"]')
const eventOptions = {
bubbles: true,
composed: true,
detail: {
amount: '1000000',
assetCode: 'USD',
assetScale: '9',
receipt: null,
amountSent: {
...receiveAmount,
},
paymentPointer,
incomingPayment,
},
}
const customEvent = new CustomEvent('monetization', eventOptions)

// monetizationTag?.dispatchEvent(new CustomEvent('load', eventOptions))
monetizationTag?.dispatchEvent(customEvent)
window.dispatchEvent(
new CustomEvent('monetization-v2', {
detail: {
amount: receiveAmount.value as string,
assetCode: receiveAmount.assetCode as string,
assetScale: receiveAmount.assetScale as number,
amountSent: {
currency: receiveAmount.assetCode as string,
amount: (receiveAmount.value * 10 ** -receiveAmount.assetScale) as number,
},
paymentPointer: paymentPointer as string,
incomingPayment: incomingPayment as string,
receipt: null,
},
}),
)

break
}
Expand Down
7 changes: 5 additions & 2 deletions src/utils/polyfill.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// language=JavaScript
export const wm2Polyfill = `
var monetizationTag = document.querySelector('link[rel="monetization"]');
monetizationTag.dispatchEvent(new Event('load'));
const dbg = () => {
}
dbg('setonmonetization property start')
Expand Down Expand Up @@ -80,9 +82,10 @@ export const wm2Polyfill = `
dbg(
'monetization-v2 event'
)
const monetizationEvent = new MonetizationEvent('monetization', event.detail)
event.target.dispatchEvent(monetizationEvent)
}, { capture: true })
monetizationTag.dispatchEvent(monetizationEvent)
}, { capture: true, bubble: true })
window.addEventListener('onmonetization-attr-changed', (event) => {
dbg('onmonetization-attr-changed', event.detail.attribute)
const { attribute } = event.detail
Expand Down
54 changes: 27 additions & 27 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true,
"noImplicitThis": true,
"baseUrl": "./src",
"esModuleInterop": true,
"module": "commonjs",
"target": "es5",
"allowJs": true,
"jsx": "react",
"sourceMap": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"allowUmdGlobalAccess": true,
"resolveJsonModule": true,
"paths": {
"@/utils/*": ["./utils/*"],
"@/popup/*": ["./popup/*"],
"@/background/*": ["./background/*"],
"@/content/*": ["./content/*"],
"@/assets/*": ["./assets/*"],
"@/components/*": ["./components/*"],
"@/types/*": ["./types/*"],
"@/hooks/*": ["./hooks/*"]
},
"typeRoots": ["node_modules/@types", "./src/types"]
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true,
"noImplicitThis": true,
"baseUrl": "./src",
"esModuleInterop": true,
"module": "commonjs",
"target": "es5",
"allowJs": true,
"jsx": "react",
"sourceMap": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"allowUmdGlobalAccess": true,
"resolveJsonModule": true,
"paths": {
"@/utils/*": ["./utils/*"],
"@/popup/*": ["./popup/*"],
"@/background/*": ["./background/*"],
"@/content/*": ["./content/*"],
"@/assets/*": ["./assets/*"],
"@/components/*": ["./components/*"],
"@/types/*": ["./types/*"],
"@/hooks/*": ["./hooks/*"]
},
"exclude": ["dist", "dev", "temp"]
"typeRoots": ["node_modules/@types", "./src/types"]
},
"exclude": ["dist", "dev", "temp"]
}

0 comments on commit a7fe694

Please sign in to comment.