Skip to content

Commit

Permalink
Merge branch 'main' into ev/iss709
Browse files Browse the repository at this point in the history
  • Loading branch information
evvvritt authored Oct 17, 2023
2 parents e267a2f + 941ae61 commit d01a370
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 89 deletions.
6 changes: 4 additions & 2 deletions src/lib/components/head-meta/head-meta.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
</script>

<svelte:head>
<title>{title}{title.startsWith('Drips') ? '' : ' | Drips'}</title>
{#if title}
<title>{title}{title.startsWith('Drips') ? '' : ' | Drips'}</title>
<meta property="og:title" content="{title}{title.startsWith('Drips') ? '' : ' | Drips'}" />
{/if}
<meta name="description" content={description} />
<meta property="og:title" content="{title}{title.startsWith('Drips') ? '' : ' | Drips'}" />
<meta property="og:image" content="https://{$page.url.host}{image}" />
<meta property="og:description" content={description} />
<meta name="twitter:title" content="Drips" />
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/search-bar/components/result.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<div class="highlighted">
<span style="color: var(--color-foreground)">
{#if !item.item.name && !item.item.address && item.item.dripsAccountId}
Jump to user ID:
Jump to account ID:
{/if}
</span>
{@html highlighted}
Expand Down
33 changes: 20 additions & 13 deletions src/lib/flows/delete-stream-flow/methods/delete-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,22 @@ export default function (
assert(assetConfig, "App hasnʼt yet fetched user's own account");

const metadataMgr = new AddressDriverMetadataManager();

const metadata = metadataMgr.buildAccountMetadata({ forAccount: ownAccount, address });
const assetConfigIndex = metadata.assetConfigs.findIndex(
(mac) => mac.tokenAddress.toLowerCase() === tokenAddress.toLowerCase(),
);
const streamIndex = metadata.assetConfigs[assetConfigIndex].streams.findIndex(
(ms) => ms.id === stream.id,
);

metadata.assetConfigs[assetConfigIndex].streams.splice(streamIndex, 1);
// If the stream isn't managed, it didn't have any metadata, so we don't need to make any changes to it.
if (stream.managed) {
const assetConfigIndex = metadata.assetConfigs.findIndex(
(mac) => mac.tokenAddress.toLowerCase() === tokenAddress.toLowerCase(),
);
const streamIndex = metadata.assetConfigs[assetConfigIndex].streams.findIndex(
(ms) => ms.id === stream.id,
);

if (metadata.assetConfigs[assetConfigIndex].streams.length === 0) {
metadata.assetConfigs.splice(assetConfigIndex, 1);
metadata.assetConfigs[assetConfigIndex].streams.splice(streamIndex, 1);

if (metadata.assetConfigs[assetConfigIndex].streams.length === 0) {
metadata.assetConfigs.splice(assetConfigIndex, 1);
}
}

const newHash = await metadataMgr.pinAccountMetadata(metadata);
Expand All @@ -71,6 +74,10 @@ export default function (

const { ADDRESS_DRIVER } = getNetworkConfig();

/*
Pretty confusing that this is a "createStream" preset, but all it is does is 1) call setStreams, and
2) update metadata. Since we need to do exactly this also for deleting streams, we can use it here.
*/
const createStreamBatchPreset = await AddressDriverPresets.Presets.createNewStreamFlow({
signer,
driverAddress: ADDRESS_DRIVER,
Expand Down Expand Up @@ -102,9 +109,9 @@ export default function (

after: async (_, transactContext) => {
/*
We wait up to five seconds for `refreshUserAccount` to update the user's own
account's `lastIpfsHash` to the new hash we just published.
*/
We wait up to five seconds for `refreshUserAccount` to update the user's own
account's `lastIpfsHash` to the new hash we just published.
*/
await expect(
streams.refreshUserAccount,
() =>
Expand Down
99 changes: 99 additions & 0 deletions src/lib/utils/decode-universal-account-id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import ens from '$lib/stores/ens';
import { getAddressDriverClient } from '$lib/utils/get-drips-clients';
import { isAddress } from 'ethers/lib/utils';
import { AddressDriverClient, Utils } from 'radicle-drips';
import { get } from 'svelte/store';

interface AddressDriverResult {
driver: 'address';
address: string;
dripsAccountId: string;
}

interface RepoDriverResult {
driver: 'repo';
dripsAccountId: string;
}

interface NFTDriverResult {
driver: 'nft';
dripsAccountId: string;
}

/**
* "universalAcccountIdentifier" is either an .ens name, an ETH address, or a Drips User ID (any supported driver).
* This utility takes such an identifier (which e.g. may be navigated to via drips.network/<universalAcccountIdentifier>),
* figures out which of the options it is, and returns an object describing the target.
* @param universalAcccountIdentifier
*/
export default async function (
universalAcccountIdentifier: string,
): Promise<AddressDriverResult | RepoDriverResult | NFTDriverResult> {
if (isAddress(universalAcccountIdentifier)) {
const address = universalAcccountIdentifier;
const dripsAccountId = await (
await getAddressDriverClient()
).getAccountIdByAddress(universalAcccountIdentifier);

return {
driver: 'address',
address,
dripsAccountId,
};
} else if (universalAcccountIdentifier.endsWith('.eth')) {
// Subscribe to ens.connected store and wait until it's true

const ensConnected = ens.connected;

if (!get(ensConnected)) {
await new Promise((resolve) => {
const unsubscribe = ensConnected.subscribe((connected) => {
if (connected) {
unsubscribe();
resolve(undefined);
}
});
});
}

const lookup = await ens.reverseLookup(universalAcccountIdentifier);
if (lookup) {
const dripsAccountId = await (await getAddressDriverClient()).getAccountIdByAddress(lookup);
const address = lookup;

return {
driver: 'address',
address,
dripsAccountId,
};
} else {
throw new Error('Not found');
}
} else if (/^\d+$/.test(universalAcccountIdentifier)) {
// User ID param has only numbers and is probably a drips user ID
const dripsAccountId = universalAcccountIdentifier;

const driver = Utils.AccountId.getDriver(dripsAccountId);

if (driver === 'address') {
const address = AddressDriverClient.getUserAddress(universalAcccountIdentifier);

return {
driver: 'address',
address,
dripsAccountId,
};
} else {
if (driver === 'immutableSplits') {
throw new Error('Unsupported Driver');
}

return {
driver,
dripsAccountId,
};
}
} else {
throw new Error('Not found.');
}
}
59 changes: 0 additions & 59 deletions src/lib/utils/decode-user-id.ts

This file was deleted.

44 changes: 33 additions & 11 deletions src/routes/app/(app)/[accountId]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@
import unreachable from '$lib/utils/unreachable';
import SectionSkeleton from '$lib/components/section-skeleton/section-skeleton.svelte';
import { fade, fly } from 'svelte/transition';
import decodeAccountId from '$lib/utils/decode-user-id';
import decodeUniversalAccountId from '$lib/utils/decode-universal-account-id';
import dismissablesStore from '$lib/stores/dismissables/dismissables.store';
import DripsV1Logo from '$lib/components/illustrations/drips-v1-logo.svelte';
import Banner from '$lib/components/banner/banner.svelte';
import HeadMeta from '$lib/components/head-meta/head-meta.svelte';
import ProjectsSection from '$lib/components/projects-section/projects-section.svelte';
import DripListsSection from '$lib/components/drip-lists-section/drip-lists-section.svelte';
import Developer from '$lib/components/developer-section/developer.section.svelte';
import { goto } from '$app/navigation';
$: accountId = $page.params.accountId;
let dripsAccountId: string | undefined;
let address: string | undefined;
let error: Error | undefined;
let error: 'is-repo-driver-account-id' | true | undefined;
const ensRecords = ['description', 'url', 'com.twitter', 'com.github'] as const;
const socialLinks = ['com.twitter', 'com.github', 'url'] as const;
Expand Down Expand Up @@ -70,12 +71,27 @@
onMount(async () => {
try {
const decodedAccountId = await decodeAccountId(accountId);
address = decodedAccountId.address;
dripsAccountId = decodedAccountId.dripsAccountId;
const decodedAccountId = await decodeUniversalAccountId(accountId);
switch (decodedAccountId.driver) {
case 'address': {
address = decodedAccountId.address;
dripsAccountId = decodedAccountId.dripsAccountId;
break;
}
case 'nft': {
goto(`/app/drip-lists/${decodedAccountId.dripsAccountId}`);
break;
}
case 'repo': {
error = 'is-repo-driver-account-id';
break;
}
}
} catch (e) {
error = e instanceof Error ? e : new Error();
// eslint-disable-next-line no-console
console.error(e);
error = true;
}
});
Expand All @@ -94,7 +110,7 @@
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
error = e instanceof Error ? e : new Error('Unable to fetch account');
error = true;
}
}
Expand All @@ -107,11 +123,17 @@

<HeadMeta title={(address && $ens[address]?.name) ?? address ?? accountId} />

{#if error}
{#if error === 'is-repo-driver-account-id'}
<LargeEmptyState
emoji="🕸️"
headline="Unable to jump to projects by account ID"
description="Sorry, but jumping to a Drips Project by its account ID is currently not supported."
/>
{:else if error}
<LargeEmptyState
emoji="🕸️"
headline="Unable to show profile"
description="We werenʼt able to find that profile."
headline="Something went wrong"
description="There may be more information in the developer console."
/>
{:else}
<div class="profile">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import wallet from '$lib/stores/wallet/wallet.store';
import guardConnected from '$lib/utils/guard-connected';
import checkIsUser from '$lib/utils/check-is-user';
import decodeAccountId from '$lib/utils/decode-user-id';
import decodeAccountId from '$lib/utils/decode-universal-account-id';
import LargeEmptyState from '$lib/components/large-empty-state/large-empty-state.svelte';
import collectFlowSteps from '$lib/flows/collect-flow/collect-flow-steps';
import getWithdrawSteps from '$lib/flows/withdraw-flow/withdraw-flow-steps';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Spinner from '$lib/components/spinner/spinner.svelte';
import StreamVisual from '$lib/components/stream-visual/stream-visual.svelte';
import balances from '$lib/stores/balances';
import decodeAccountId from '$lib/utils/decode-user-id';
import decodeAccountId from '$lib/utils/decode-universal-account-id';
import unreachable from '$lib/utils/unreachable';
import FormattedAmount from '$lib/components/formatted-amount/formatted-amount.svelte';
import tokens from '$lib/stores/tokens';
Expand Down
4 changes: 3 additions & 1 deletion src/routes/app/(app)/drip-lists/[listId]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
$: streamsFetched = $streamsFetchStatusses[ownerAccountId] === 'fetched';
</script>

<HeadMeta title={data.dripList.name} />
{#if data.dripList.name}
<HeadMeta title={data.dripList.name} />
{/if}

<article class="drip-list-page">
<section class="flex flex-col gap-6">
Expand Down

0 comments on commit d01a370

Please sign in to comment.