Skip to content

Commit

Permalink
Merge pull request #347 from shocknet/main
Browse files Browse the repository at this point in the history
up
  • Loading branch information
shocknet-justin authored Nov 18, 2024
2 parents 4333203 + b7fb1bd commit 9112219
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ updates:
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
branch: "test"
target-branch: "test"
3 changes: 2 additions & 1 deletion src/Components/Background.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const Background = () => {
const nostrSpends = useSelector(selectNostrSpends);
const paySource = useSelector((state) => state.paySource)
const { cursor, latestOperation: latestOp, operations: operationGroups, operationsUpdateHook } = useSelector(state => state.history)
const backupState = useSelector(state => state.backupStateSlice)
const nodedUp = useSelector(state => state.nostrPrivateKey);
const dispatch = useDispatch();
const [parsedClipboard, setParsedClipbaord] = useState<Destination>({
Expand Down Expand Up @@ -105,7 +106,7 @@ export const Background = () => {
const otherSpendSources = Object.values(spendSource.sources).filter((e) => !e.pubSource);

if ((nostrSpends.length !== 0 && nostrSpends[0].balance !== "0") || (otherPaySources.length > 0 || otherSpendSources.length > 0)) {
if (localStorage.getItem("isBackUp") == "1") {
if (localStorage.getItem("isBackUp") === "1" || backupState.subbedToBackUp) {
return;
}
dispatch(addNotification({
Expand Down
31 changes: 22 additions & 9 deletions src/Pages/Sources/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const Sources = () => {


const processParsedInput = (destination: Destination) => {
console.log("processing parsed input", destination)
if (
destination.type === InputClassification.LNURL
&&
Expand All @@ -72,6 +73,7 @@ export const Sources = () => {
} else if (destination.data.includes("nprofile") || destination.type === InputClassification.LNURL || destination.type === InputClassification.LN_ADDRESS) {
setSourcePasteField(destination.data);
if (destination.data.includes("nprofile")) {
console.log("fetching beacon")
const data = decodeNprofile(destination.data);
fetchBeacon(data.pubkey, data.relays || NOSTR_RELAYS, 2 * 60).then(beacon => {
if (beacon) {
Expand Down Expand Up @@ -143,8 +145,8 @@ export const Sources = () => {

const EditSourceSpend_Modal = (key: string) => {
const source = spendSources.sources[key];
dispatch(setSourceToEdit({
source: source,
dispatch(setSourceToEdit({
source: source,
type: "spendFrom",
}))

Expand Down Expand Up @@ -182,7 +184,7 @@ export const Sources = () => {
}

const addSource = useCallback(async () => {
console.log("adding")
console.log("adding source", sourcePasteField)
toggle();

if (processingSource) {
Expand All @@ -209,12 +211,19 @@ export const Sources = () => {
if (existingSpendSourceId) {
const spendSource = spendSources.sources[existingSpendSourceId];
if (adminEnrollToken && spendSource && spendSource.adminToken !== adminEnrollToken) {
console.log("resetting admin access to existing source")
setProcessingSource(true)
const client = await getNostrClient(inputSource, spendSource.keys!); // TODO: write migration to remove type override
await client.EnrollAdminToken({ admin_token: adminEnrollToken });
dispatch(editSpendSources({ ...spendSource, adminToken: adminEnrollToken }));
toast.success(<Toast title="Sources" message={`successufly linked admin access to ${inputSource}`} />)
setProcessingSource(false);
dispatch(toggleLoading({ loadingMessage: "" }))
return
}
console.log("source already exists")
setProcessingSource(false);
dispatch(toggleLoading({ loadingMessage: "" }))
toast.error(<Toast title="Error" message="Source already exists." />)
return;
}
Expand All @@ -237,12 +246,13 @@ export const Sources = () => {
if (inputSource.startsWith("nprofile")) {
// nprofile


console.log("generating source pair")
const newSourceKeyPair = generateNewKeyPair();
let vanityName: string | undefined = undefined;

console.log("checking for integration data")
// integration to an existing pub account
if (integrationData.token) {
console.log("linking to existing account")
const res = await (await getNostrClient(inputSource, newSourceKeyPair))
.LinkNPubThroughToken({
token: integrationData.token,
Expand All @@ -256,8 +266,9 @@ export const Sources = () => {
}
vanityName = integrationData.lnAddress;
}

console.log("checking for invite token")
if (inviteToken) {
console.log("using invite token")
const res = await (await getNostrClient(inputSource, newSourceKeyPair))
.UseInviteLink({ invite_token: inviteToken })
if (res.status !== "OK") {
Expand All @@ -267,12 +278,13 @@ export const Sources = () => {
return;
}
}

console.log("checking for admin token")
if (adminEnrollToken) {
console.log("enrolling admin token")
const client = await getNostrClient(inputSource, newSourceKeyPair);
await client.EnrollAdminToken({ admin_token: adminEnrollToken });
}

console.log("adding source")
const resultLnurl = new URL(data!.relays![0]);
const parts = resultLnurl.hostname.split(".");
const sndleveldomain = parts.slice(-2).join('.');
Expand Down Expand Up @@ -356,6 +368,7 @@ export const Sources = () => {
return
}
}
console.log("source added")
toast.success(<Toast title="Sources" message={`${parsed ? parsed.domainName : "Nprofile"} successfuly added to sources`} />)
resetValue();
dispatch(toggleLoading({ loadingMessage: "" }))
Expand Down Expand Up @@ -445,7 +458,7 @@ export const Sources = () => {
<button onClick={addSource}>Add</button>
</div>

</React.Fragment>;
</React.Fragment>;


const notifyContent = <React.Fragment>
Expand Down
10 changes: 8 additions & 2 deletions src/State/bridgeMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ export const bridgeListener = {
const nostrPayTos = Object.values(paySources.sources).filter(source => source.pubSource);
await Promise.all(nostrPayTos.map(async source => enrollToBridge(
source,
(vanityName) => listenerApi.dispatch({ type: "paySources/editPaySources", payload: { ...source, vanityName }, meta: { skipChangelog: true } })
(vanityName) => {
const recentSource = listenerApi.getState().paySource.sources[source.id]
listenerApi.dispatch({ type: "paySources/editPaySources", payload: { ...recentSource, vanityName }, meta: { skipChangelog: true } })
}
)))
return;
}
Expand All @@ -70,7 +73,10 @@ export const bridgeListener = {

await enrollToBridge(
source,
(vanityName) => listenerApi.dispatch({ type: "paySources/editPaySources", payload: { ...source, vanityName }, meta: { skipChangelog: true } })
(vanityName) => {
const recentSource = listenerApi.getState().paySource.sources[source.id]
listenerApi.dispatch({ type: "paySources/editPaySources", payload: { ...recentSource, vanityName }, meta: { skipChangelog: true } })
}
)

}
Expand Down

0 comments on commit 9112219

Please sign in to comment.