-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #326 from snake-eaterr/debit-improvements
ndebit discoverable checkbox
- Loading branch information
Showing
9 changed files
with
277 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { createListenerMiddleware, ListenerEffectAPI, PayloadAction, TypedStartListening } from "@reduxjs/toolkit"; | ||
import { flipSourceNdebitDiscoverable } from "./Slices/paySourcesSlice"; | ||
import { AppDispatch, State } from "./store"; | ||
import { PayTo } from "../globalTypes"; | ||
import Bridge from "../Api/bridge"; | ||
import { Buffer } from "buffer"; | ||
|
||
import { finalizeEvent, nip98 } from 'nostr-tools' | ||
const { getToken } = nip98 | ||
|
||
|
||
|
||
|
||
|
||
|
||
export const ndebitDiscoverableListener = { | ||
actionCreator: flipSourceNdebitDiscoverable, | ||
effect: async (action: PayloadAction<PayTo>, listenerApi: ListenerEffectAPI<State, AppDispatch>) => { | ||
const paySource = action.payload; | ||
const counterpartSpendSource = listenerApi.getState().spendSource.sources[paySource.id]; | ||
if (paySource.bridgeUrl) { | ||
if (paySource.isNdebitDiscoverable && counterpartSpendSource.ndebit) { | ||
const payload = { ndebit: counterpartSpendSource.ndebit } | ||
const nostrHeader = await getToken(`${paySource.bridgeUrl}/api/v1/noffer/update/ndebit`, "POST", e => finalizeEvent(e, Buffer.from(paySource.keys.privateKey, 'hex')), true, payload) | ||
const bridgeHandler = new Bridge(paySource.bridgeUrl, nostrHeader); | ||
const res = await bridgeHandler.UpdateMappingNdebit(payload) | ||
if (res.status !== "OK") { | ||
throw new Error(res.reason); | ||
} | ||
} else if (!paySource.isNdebitDiscoverable) { | ||
const payload = {} | ||
const nostrHeader = await getToken(`${paySource.bridgeUrl}/api/v1/noffer/update/ndebit`, "POST", e => finalizeEvent(e, Buffer.from(paySource.keys.privateKey, 'hex')), true, payload) | ||
const bridgeHandler = new Bridge(paySource.bridgeUrl, nostrHeader); | ||
const res = await bridgeHandler.UpdateMappingNdebit(payload) | ||
if (res.status !== "OK") { | ||
throw new Error(res.reason); | ||
} | ||
} | ||
} | ||
|
||
|
||
} | ||
} | ||
|
||
export const ndebitMiddleware = createListenerMiddleware() | ||
const typedStartListening = ndebitMiddleware.startListening as TypedStartListening<State, AppDispatch> | ||
typedStartListening(ndebitDiscoverableListener); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters