mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 16:02:26 +00:00
feat: show provider metadata in saved profiles
This commit is contained in:
1 parent
3532c212f3
commit
6d84d6be4e
8 files changed
+362
-29
No files matched your search
@@ -440,12 +440,16 @@ for (const _ of [0]) {
|
||||
npub: 'npub1abcdefghijkmnopqrstuvwxyz1234567890example',
|
||||
name: '',
|
||||
picture: '',
|
||||
providerId: 'nip07',
|
||||
authType: 'nip07',
|
||||
},
|
||||
{
|
||||
pubkey: 'b'.repeat(64),
|
||||
npub: 'npub1zyxwvutsrqponmlkjihgfedcba1234567890sample',
|
||||
name: '',
|
||||
picture: '',
|
||||
providerId: 'nsec',
|
||||
authType: 'nsec',
|
||||
},
|
||||
];
|
||||
|
||||
@@ -470,6 +474,62 @@ for (const _ of [0]) {
|
||||
const expectedSwitcher = formatShortNpub(sampleProfiles[1].npub);
|
||||
assert.equal(switcherNpubEl.textContent, expectedSwitcher);
|
||||
});
|
||||
|
||||
test('renderSavedProfiles applies provider metadata', async () => {
|
||||
const sampleProfiles = [
|
||||
{
|
||||
pubkey: defaultActorHex,
|
||||
npub: 'npub1abcdefghijkmnopqrstuvwxyz1234567890example',
|
||||
name: 'Primary Account',
|
||||
picture: '',
|
||||
providerId: 'nip07',
|
||||
authType: 'nip07',
|
||||
},
|
||||
{
|
||||
pubkey: 'b'.repeat(64),
|
||||
npub: 'npub1zyxwvutsrqponmlkjihgfedcba1234567890sample',
|
||||
name: 'Backup',
|
||||
picture: '',
|
||||
providerId: 'nsec',
|
||||
authType: 'nsec',
|
||||
},
|
||||
];
|
||||
|
||||
const controller = createController({
|
||||
services: {
|
||||
formatShortNpub,
|
||||
},
|
||||
});
|
||||
|
||||
await controller.load();
|
||||
|
||||
controller.state.setSavedProfiles(sampleProfiles);
|
||||
controller.state.setActivePubkey(null);
|
||||
|
||||
controller.renderSavedProfiles();
|
||||
|
||||
const buttons = Array.from(
|
||||
controller.switcherList.querySelectorAll('button[data-provider-id]'),
|
||||
);
|
||||
|
||||
assert.equal(buttons.length, 2, 'expected two provider entries in the switcher');
|
||||
|
||||
const [extensionButton, directKeyButton] = buttons;
|
||||
|
||||
assert.equal(extensionButton.dataset.providerId, 'nip07');
|
||||
const extensionLabel = extensionButton.querySelector('[data-provider-variant]');
|
||||
assert.ok(extensionLabel, 'extension entry should include a provider badge');
|
||||
assert.equal(extensionLabel.textContent, 'Login with Extension');
|
||||
assert.equal(extensionLabel.dataset.providerVariant, 'info');
|
||||
assert.equal(extensionButton.getAttribute('aria-pressed'), 'false');
|
||||
|
||||
assert.equal(directKeyButton.dataset.providerId, 'nsec');
|
||||
const directKeyLabel = directKeyButton.querySelector('[data-provider-variant]');
|
||||
assert.ok(directKeyLabel, 'direct key entry should include a provider badge');
|
||||
assert.equal(directKeyLabel.textContent, 'Direct key');
|
||||
assert.equal(directKeyLabel.dataset.providerVariant, 'warning');
|
||||
assert.equal(directKeyButton.getAttribute('aria-pressed'), 'false');
|
||||
});
|
||||
}
|
||||
|
||||
test('load() injects markup and caches expected elements', async () => {
|
||||
|
||||
@@ -42,6 +42,7 @@ test("persistSavedProfiles preserves custom authType strings", () => {
|
||||
name: "",
|
||||
picture: "",
|
||||
authType: "custom-wallet",
|
||||
providerId: "custom-wallet",
|
||||
},
|
||||
],
|
||||
{ persist: false, persistActive: false },
|
||||
@@ -55,6 +56,7 @@ test("persistSavedProfiles preserves custom authType strings", () => {
|
||||
const stored = JSON.parse(storedRaw);
|
||||
assert.equal(stored.entries.length, 1);
|
||||
assert.equal(stored.entries[0].authType, "custom-wallet");
|
||||
assert.equal(stored.entries[0].providerId, "custom-wallet");
|
||||
});
|
||||
|
||||
test("loadSavedProfilesFromStorage retains custom provider authType", () => {
|
||||
@@ -71,6 +73,7 @@ test("loadSavedProfilesFromStorage retains custom provider authType", () => {
|
||||
name: "",
|
||||
picture: "",
|
||||
authType: "nostr-wallet-connect",
|
||||
providerId: "nostr-wallet-connect",
|
||||
},
|
||||
],
|
||||
activePubkey: null,
|
||||
@@ -80,9 +83,11 @@ test("loadSavedProfilesFromStorage retains custom provider authType", () => {
|
||||
const { profiles } = loadSavedProfilesFromStorage();
|
||||
assert.equal(profiles.length, 1);
|
||||
assert.equal(profiles[0].authType, "nostr-wallet-connect");
|
||||
assert.equal(profiles[0].providerId, "nostr-wallet-connect");
|
||||
|
||||
const stored = JSON.parse(localStorage.getItem(STORAGE_KEY));
|
||||
assert.equal(stored.entries[0].authType, "nostr-wallet-connect");
|
||||
assert.equal(stored.entries[0].providerId, "nostr-wallet-connect");
|
||||
});
|
||||
|
||||
test("loadSavedProfilesFromStorage migrates missing authType to nip07", () => {
|
||||
@@ -107,9 +112,11 @@ test("loadSavedProfilesFromStorage migrates missing authType to nip07", () => {
|
||||
const { profiles } = loadSavedProfilesFromStorage();
|
||||
assert.equal(profiles.length, 1);
|
||||
assert.equal(profiles[0].authType, "nip07");
|
||||
assert.equal(profiles[0].providerId, "nip07");
|
||||
|
||||
const stored = JSON.parse(localStorage.getItem(STORAGE_KEY));
|
||||
assert.equal(stored.entries[0].authType, "nip07");
|
||||
assert.equal(stored.entries[0].providerId, "nip07");
|
||||
});
|
||||
|
||||
test("loadSavedProfilesFromStorage trims stored authType values", () => {
|
||||
@@ -126,6 +133,7 @@ test("loadSavedProfilesFromStorage trims stored authType values", () => {
|
||||
name: "",
|
||||
picture: "",
|
||||
authType: " extension-provider ",
|
||||
providerId: " extension-provider ",
|
||||
},
|
||||
],
|
||||
activePubkey: null,
|
||||
@@ -135,7 +143,9 @@ test("loadSavedProfilesFromStorage trims stored authType values", () => {
|
||||
const { profiles } = loadSavedProfilesFromStorage();
|
||||
assert.equal(profiles.length, 1);
|
||||
assert.equal(profiles[0].authType, "extension-provider");
|
||||
assert.equal(profiles[0].providerId, "extension-provider");
|
||||
|
||||
const stored = JSON.parse(localStorage.getItem(STORAGE_KEY));
|
||||
assert.equal(stored.entries[0].authType, "extension-provider");
|
||||
assert.equal(stored.entries[0].providerId, "extension-provider");
|
||||
});
|
||||
Reference in new issue
Block a user