Skip to content

Commit

Permalink
Merge pull request #384 from greymass/multisig
Browse files Browse the repository at this point in the history
Adding support for multisig accounts
  • Loading branch information
aaroncox authored Feb 24, 2025
2 parents cb1136e + 39af9c9 commit 5f83e6a
Show file tree
Hide file tree
Showing 45 changed files with 949 additions and 248 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ $(CONTRACTS)/delphioracle.ts:
$(CONTRACTS)/unicove.ts:
bunx @wharfkit/cli generate -u $(CONTRACTS_API) -f $(CONTRACTS)/unicove.ts unicove.gm

codegen: $(CONTRACTS)/system.ts $(CONTRACTS)/token.ts $(CONTRACTS)/msig.ts $(CONTRACTS)/delphioracle.ts $(CONTRACTS)/unicove.ts
$(CONTRACTS)/eosntime.ts:
bunx @wharfkit/cli generate -u $(CONTRACTS_API) -f $(CONTRACTS)/eosntime.ts time.eosn

codegen: $(CONTRACTS)/system.ts $(CONTRACTS)/token.ts $(CONTRACTS)/msig.ts $(CONTRACTS)/delphioracle.ts $(CONTRACTS)/unicove.ts $(CONTRACTS)/eosntime.ts
mkdir -p $(CONTRACTS)

.PHONY: clean
Expand Down
5 changes: 5 additions & 0 deletions messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
"common_about_something": "About {thing}",
"common_account": "Actor",
"common_account_balance": "Account Balance",
"common_account_multisig_using_account": "multisig using {account}",
"common_action": "Action",
"common_actions": "Actions",
"common_actor": "Actor",
"common_add_account": "Add Account",
"common_add_funds": "Add Funds",
"common_amount": "Amount",
"common_amount_exceeds_balance": "Amount exceeds available balance.",
Expand All @@ -41,12 +43,14 @@
"common_breakdown": "Breakdown",
"common_buy": "Buy",
"common_bytes": "Bytes",
"common_cancel": "Cancel",
"common_claim": "Claim",
"common_clear": "Clear",
"common_close": "Close",
"common_complete": "Complete",
"common_confirm": "Confirm",
"common_connect_wallet": "Connect Wallet",
"common_connect_wallet_login": "Connect your wallet to login",
"common_contract": "Contract",
"common_copied_result": "Copied!",
"common_copy": "Copy",
Expand All @@ -73,6 +77,7 @@
"common_labeled_unit_staked": "{unit} Staked",
"common_labeled_unit_value": "{unit} Value",
"common_login": "Login",
"common_login_to_unicove": "Login to Unicove",
"common_market_cap": "Market Cap",
"common_memo": "Memo",
"common_must_be_logged_in": "You must be logged in with an account to use this feature.",
Expand Down
3 changes: 3 additions & 0 deletions scripts/env/default/chains.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"features": {
"delphioracle": true,
"directfunding": true,
"eosntime": true,
"giftedram": false,
"lightapi": true,
"metamask": true,
Expand Down Expand Up @@ -42,6 +43,7 @@
"features": {
"delphioracle": false,
"directfunding": false,
"eosntime": false,
"giftedram": true,
"lightapi": false,
"metamask": true,
Expand Down Expand Up @@ -76,6 +78,7 @@
"features": {
"delphioracle": false,
"directfunding": false,
"eosntime": false,
"lightapi": false,
"metamask": false,
"powerup": true,
Expand Down
2 changes: 1 addition & 1 deletion src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<link rel="icon" type="image/svg+xml" href="/favicon.svg" sizes="any" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
<meta name="apple-mobile-web-app-title" content="Unicove" />
<link rel="manifest" href="/site.webmanifest" />
<!-- <link rel="manifest" href="/site.webmanifest" /> -->
<style>
@font-face {
font-family: 'Inter';
Expand Down
77 changes: 46 additions & 31 deletions src/lib/components/accountswitch.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
import UserCheck from 'lucide-svelte/icons/user-check';
import UserPlus from 'lucide-svelte/icons/user-plus';
import Search from 'lucide-svelte/icons/search';
import { goto } from '$app/navigation';
import { languageTag } from '$lib/paraglide/runtime';
import { goto } from '$lib/utils';
import { cn } from '$lib/utils/style';
import Button from './button/button.svelte';
import Text from './input/text.svelte';
Expand Down Expand Up @@ -84,7 +83,7 @@
function redirect(account: NameType) {
if (!context.settings.data.preventAccountPageSwitching) {
goto(`/${languageTag()}/${network}/account/${account}`);
goto(`/${network}/account/${account}`);
}
}
Expand All @@ -94,17 +93,20 @@
closeDrawer();
}
function removeSession(session?: Session | SerializedSession) {
async function removeSession(session?: Session | SerializedSession) {
if (session) {
context.wharf.logout(session);
await context.wharf.logout(session);
if (currentSession) {
redirect(currentSession.actor);
}
}
}
async function connectWallet(wallet: WalletPlugin) {
const options: LoginOptions = {
walletPlugin: wallet.id
};
if (wallet.id !== 'cleos') {
if (wallet.id !== 'cleos' && wallet.id !== 'wallet-plugin-multisig') {
options.chain = context.network.chain;
}
const session = await context.wharf.login(options);
Expand Down Expand Up @@ -207,7 +209,7 @@
<Button onclick={addAccount} variant="secondary" class="grow-0 text-white">
<div class="flex items-center gap-2">
<UserPlus class="mb-0.5 size-5" />
<span>Add Account</span>
<span>{m.common_add_account()}</span>
</div>
</Button>

Expand All @@ -232,7 +234,9 @@

<ul class="grid gap-2">
{#each chainSessions as session}
{@const isCurrent = currentSession?.actor.toString() === session.actor}
{@const isCurrent =
currentSession?.actor.equals(session.actor) &&
currentSession?.permission.equals(session.permission)}
<li class="grid grid-cols-[1fr_auto] gap-2">
<button
data-current={isCurrent}
Expand All @@ -252,9 +256,16 @@
{/if}
</div>

<span class="font-medium">
{session.actor}@{session.permission}
</span>
<div class="text-left font-medium">
<div>{session.actor}@{session.permission}</div>
{#if session.walletPlugin.id === 'wallet-plugin-multisig'}
<div class="text-xs">
↳ {m.common_account_multisig_using_account({
account: session.walletPlugin.data.session.actor
})}
</div>
{/if}
</div>
</button>
<button
onclick={() => removeSession(session)}
Expand Down Expand Up @@ -285,38 +296,42 @@
<hr class="border-mineShaft-900" />

<header class="grid justify-center gap-2 py-4 text-center">
<span class="h4">Login to Unicove</span>
<span class="text-muted text-sm font-medium">Connect your wallet to login</span>
<span class="h4">{m.common_login_to_unicove()}</span>
<span class="text-muted text-sm font-medium">{m.common_connect_wallet_login()}</span>
</header>

{#if context.wharf.sessionKit}
<ul class="grid grid-cols-[auto_1fr_auto]">
{#each context.wharf.sessionKit?.walletPlugins as wallet}
<li class="table-row-background table-row-border col-span-full grid grid-cols-subgrid">
<button
class="col-span-full grid grid-cols-subgrid gap-4 px-2 py-4 font-semibold text-white"
onclick={() => connectWallet(wallet)}
>
{#if wallet.metadata.logo}
<img
class="size-6"
src={wallet.metadata.logo.toString()}
alt={wallet.metadata.name}
/>
{:else}
<Wallet class="size-6" />
{/if}
<span class="text-left">{wallet.metadata.name}</span>
</button>
</li>
{#if wallet.id !== 'wallet-plugin-multisig'}
<li class="table-row-background table-row-border col-span-full grid grid-cols-subgrid">
<button
class="col-span-full grid grid-cols-subgrid gap-4 px-2 py-4 font-semibold text-white"
onclick={() => connectWallet(wallet)}
>
{#if wallet.metadata.logo}
<img
class="size-6"
src={wallet.metadata.logo.toString()}
alt={wallet.metadata.name}
/>
{:else}
<Wallet class="size-6" />
{/if}
<span class="text-left">{wallet.metadata.name}</span>
</button>
</li>
{/if}
{/each}
</ul>
{/if}
<div class="grid">
<!-- <Button href={`/${network}/signup`} onclick={closeDrawer} variant="primary"> -->
<!-- Create account -->
<!-- </Button> -->
<Button class="text-white" onclick={closeAddingAccount} variant="secondary">Cancel</Button>
<Button class="text-white" onclick={closeAddingAccount} variant="secondary"
>{m.common_cancel()}</Button
>
</div>
</div>
{/snippet}
27 changes: 27 additions & 0 deletions src/lib/components/elements/link.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<script lang="ts">
import { cn } from '$lib/utils';
import { type Snippet } from 'svelte';
import type { HTMLAnchorAttributes } from 'svelte/elements';
interface Props extends HTMLAnchorAttributes {
href: string;
children?: Snippet;
text?: string;
}
let { href, text = '', children, ...props }: Props = $props();
</script>

<a
{href}
class={cn(
'inline-flex items-center gap-2 text-skyBlue-500 hover:text-skyBlue-400 focus-visible:outline focus-visible:outline-solar-500 ',
props.class
)}
>
{#if children}
{@render children()}
{:else}
{text}
{/if}
</a>
2 changes: 1 addition & 1 deletion src/lib/components/elements/resourceCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

<p class="*:block">
<span class="font-semibold text-white">
<NumberFormat number={props.value} />
<NumberFormat number={props.value.dividing(1000)} />
{unit}
</span>
<span>{m.common_available()}</span>
Expand Down
84 changes: 84 additions & 0 deletions src/lib/components/input/datetime.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<script lang="ts">
import { cn } from '$lib/utils/style';
import type { Snippet } from 'svelte';
import type { HTMLInputAttributes } from 'svelte/elements';
import Code from '../code.svelte';
interface DatetimeInputProps extends HTMLInputAttributes {
date?: Date;
value?: string;
min?: string;
children?: Snippet;
debug?: boolean;
}
var now = new Date();
now.setMinutes(now.getMinutes() - now.getTimezoneOffset());
function dateToInputString(date: Date) {
return date.toISOString().slice(0, 16);
}
let {
date = $bindable(),
value = $bindable(),
min = dateToInputString(now),
class: className,
debug = false,
...props
}: DatetimeInputProps = $props();
value = undefined;
if (date) {
const utc = new Date(date);
utc.setMinutes(utc.getMinutes() - utc.getTimezoneOffset());
value = dateToInputString(utc);
}
/** Set the input value from a parent */
export function set(date: Date | undefined) {
if (!date) {
value = undefined;
} else {
value = dateToInputString(date);
}
}
$effect(() => {
if (value) {
date = new Date(`${value}:00.000`);
} else {
date = undefined;
}
});
</script>

<div
class={cn(
'relative flex h-12 gap-2 rounded-lg border-2 border-mineShaft-600 px-4 *:content-center focus-within:border-skyBlue-500 focus-within:ring focus-within:ring-1 focus-within:ring-inset focus-within:ring-skyBlue-500',
className
)}
>
<input
class="placeholder:text-muted w-full rounded-lg bg-transparent font-medium focus:outline-none"
type="datetime-local"
{min}
bind:value
{...props}
/>
<div class="text-muted select-none">
{@render props.children?.()}
</div>
</div>

{#if debug}
<div class="mt-4">
<h3>Component State</h3>
<!-- prettier-ignore -->
<Code>
date: {date}
value: {value}
min: {min}
</Code>
</div>
{/if}
5 changes: 2 additions & 3 deletions src/lib/components/networkswitch.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import { createSelect, melt, type CreateSelectProps } from '@melt-ui/svelte';
import { fade } from 'svelte/transition';
import { chainMap } from '$lib/wharf/chains';
import { goto } from '$app/navigation';
import { languageTag } from '$lib/paraglide/runtime';
import { goto } from '$lib/utils';
import type { NetworkState } from '$lib/state/network.svelte';
import * as m from '$lib/paraglide/messages';
Expand Down Expand Up @@ -37,7 +36,7 @@
);
const onSelectedChange: CreateSelectProps<string>['onSelectedChange'] = ({ next }) => {
if (next !== undefined) goto(`/${languageTag()}/${next.label}`);
if (next !== undefined) goto(`/${next.label}`);
return next;
};
Expand Down
Loading

0 comments on commit 5f83e6a

Please sign in to comment.