Skip to content

Commit

Permalink
Merge branch 'main' into feat/rwa/addfirebase
Browse files Browse the repository at this point in the history
  • Loading branch information
sstraatemans committed Nov 26, 2024
2 parents c939b76 + fd2e172 commit 26db24d
Show file tree
Hide file tree
Showing 40 changed files with 817 additions and 310 deletions.
5 changes: 5 additions & 0 deletions .changeset/tidy-bears-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@kadena/graph': patch
---

Disable `relationJoins` until nix' package for prisma-engines is updated
2 changes: 2 additions & 0 deletions .changeset/wise-clocks-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
2 changes: 1 addition & 1 deletion packages/apps/dev-wallet-desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"devDependencies": {
"@tauri-apps/cli": "^1.4.0"
}
}
}
2 changes: 1 addition & 1 deletion packages/apps/dev-wallet-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
"eslint": "^8.45.0",
"eslint-config-next": "13.4.5"
}
}
}
2 changes: 1 addition & 1 deletion packages/apps/dev-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"@types/react": "^18.2.79",
"@types/react-dom": "^18.2.25",
"@vanilla-extract/esbuild-plugin": "^2.3.5",
"@vanilla-extract/vite-plugin": "4.0.7",
"@vanilla-extract/vite-plugin": "4.0.17",
"@vitejs/plugin-react-swc": "^3.3.2",
"chokidar-cli": "^3.0.0",
"concurrently": "^8.2.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"@types/react-dom": "^18.2.25",
"@types/xml2js": "^0.4.14",
"@vanilla-extract/next-plugin": "2.4.0",
"@vanilla-extract/vite-plugin": "4.0.7",
"@vanilla-extract/vite-plugin": "4.0.17",
"@vanilla-extract/webpack-plugin": "2.3.7",
"@vitest/coverage-v8": "^1.6.0",
"chalk": "^5.2.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/apps/docs/src/docs/learn/accounts-keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ In simple terms, an **account name** is a unique name on the blockchain that can

## Defining a keyset

A keyset is a specific type of **guard** that consists of one or public keys and a **predicate** that specifies how many of the keys are required to perform an operation. In JSON, a keyset looks similar to the following example:
A keyset is a specific type of **guard** that consists of one or more public keys and a **predicate** that specifies how many of the keys are required to perform an operation. In JSON, a keyset looks similar to the following example:

```json
{
Expand Down Expand Up @@ -121,13 +121,13 @@ There are two main ways to move Kadena tokens (KDA) between accounts:
- Transfer coins between accounts on the same chain.
- Transfer coins between accounts on different chains

The primary different between these two types of transfers is who pays the transaction fee to have the transaction included in a block.
The primary difference between these two types of transfers is who pays the transaction fee to have the transaction included in a block.

- With same-chain transfers, the sender must pay the transaction fee.
- With cross-chain transfers, the sender and the recipient must both pay a transaction fee.

With a cross-chain transfer, you interact with two different blockchains, which requires two separate transactions, one on each chain.

If you attempt to send a cross-chain transfer to a recipient with no funds on the destination chain, the transfer operation won't be able to complete. However, anyone with funds on the destination chain can help to pay the required fee, allowing the transfer to finish as intended. Kadena has also set up **gas stations** cover the cost of transaction fees for cross-chain transfers. If you have an incomplete cross-chain transfer, you can use the [Transfer assistant](https://transfer.chainweb.com) to finish the transaction on the destination chain.
If you attempt to send a cross-chain transfer to a recipient with no funds on the destination chain, the transfer operation won't be able to complete. However, anyone with funds on the destination chain can help to pay the required fee, allowing the transfer to finish as intended. Kadena has also set up **gas stations** to cover the cost of transaction fees for cross-chain transfers. If you have an incomplete cross-chain transfer, you can use the [Transfer assistant](https://transfer.chainweb.com) to finish the transaction on the destination chain.

To learn more about transfers in Kadena, see [Getting started with transfers](https://medium.com/kadena-io/kadena-public-blockchain-getting-started-with-transfers-153bf87d6824).
3 changes: 2 additions & 1 deletion packages/apps/graph/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
generator client {
provider = "prisma-client-js"
previewFeatures = ["views", "relationJoins"]
previewFeatures = ["views"]
// , "relationJoins"] disabled because nix prisma-engines isn't updated
}

generator pothos {
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/marmalade-marketplace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@types/webpack-env": "^1.18.5",
"@vanilla-extract/css": "1.14.2",
"@vanilla-extract/next-plugin": "2.4.0",
"@vanilla-extract/vite-plugin": "4.0.7",
"@vanilla-extract/vite-plugin": "4.0.17",
"@vitejs/plugin-react": "^4.3.1",
"@vitest/coverage-v8": "^1.6.0",
"dotenv": "~16.4.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/proof-of-us/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"@types/react-dom": "^18.2.25",
"@types/uuid": "^9.0.8",
"@vanilla-extract/next-plugin": "2.4.0",
"@vanilla-extract/vite-plugin": "4.0.7",
"@vanilla-extract/vite-plugin": "4.0.17",
"@vanilla-extract/webpack-plugin": "2.3.7",
"@vitest/coverage-v8": "^1.6.0",
"cache-sh": "^1.2.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/rwa-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"@types/node": "^20.12.7",
"@types/react": "^18.2.79",
"@types/react-dom": "^18.2.25",
"@vanilla-extract/vite-plugin": "4.0.7",
"@vanilla-extract/vite-plugin": "4.0.17",
"@vanilla-extract/webpack-plugin": "2.3.7",
"@vitejs/plugin-react": "^4.3.1",
"@vitest/coverage-v8": "^1.6.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,28 @@

import { DistributionForm } from '@/components/DistributionForm/DistributionForm';
import { FreezeInvestor } from '@/components/FreezeInvestor/FreezeInvestor';
import { InvestorBalance } from '@/components/InvestorBalance/InvestorBalance';
import { InvestorInfo } from '@/components/InvestorInfo/InvestorInfo';
import { SideBarBreadcrumbs } from '@/components/SideBarBreadcrumbs/SideBarBreadcrumbs';
import { TransferForm } from '@/components/TransferForm/TransferForm';
import { useAccount } from '@/hooks/account';
import { isFrozen } from '@/services/isFrozen';
import { MonoAdd, MonoCompareArrows } from '@kadena/kode-icons';
import { Button, Heading, Stack } from '@kadena/kode-ui';
import { useAsset } from '@/hooks/asset';
import { useFreeze } from '@/hooks/freeze';
import { MonoAdd } from '@kadena/kode-icons';
import { Button, Stack } from '@kadena/kode-ui';
import { SideBarBreadcrumbsItem, useLayout } from '@kadena/kode-ui/patterns';
import { useParams } from 'next/navigation';
import { useEffect, useState } from 'react';
import { useState } from 'react';

const InvestorPage = () => {
const { isRightAsideExpanded, setIsRightAsideExpanded } = useLayout();
const { account } = useAccount();
const { paused } = useAsset();
const params = useParams();
const [hasOpenDistributeForm, setHasOpenDistributeForm] = useState(false);
const [hasOpenTransferForm, setHasOpenTransferForm] = useState(false);
const investorAccount = decodeURIComponent(params.investorAccount as string);
const [frozen, setFrozen] = useState(false);
const { frozen } = useFreeze({ investorAccount });

const handleDistributeTokens = () => {
setIsRightAsideExpanded(true);
setHasOpenDistributeForm(true);
};
const handleTransferTokens = () => {
setIsRightAsideExpanded(true);
setHasOpenTransferForm(true);
};

const init = async () => {
const res = await isFrozen({
investorAccount: investorAccount,
account: account!,
});

if (typeof res === 'boolean') {
setFrozen(res);
}
};

useEffect(() => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
init();
}, []);

const handlePauseChange = (pausedResult: boolean) => setFrozen(pausedResult);

return (
<>
Expand All @@ -66,38 +42,18 @@ const InvestorPage = () => {
}}
/>
)}
{isRightAsideExpanded && hasOpenTransferForm && (
<TransferForm
investorAccount={investorAccount}
onClose={() => {
setIsRightAsideExpanded(false);
setHasOpenTransferForm(false);
}}
/>
)}

<Stack width="100%" flexDirection="column">
<Heading>Investor: {investorAccount}</Heading>
<InvestorBalance investorAccount={investorAccount} />
<InvestorInfo investorAccount={investorAccount} />
<Stack gap="sm">
<Button
startVisual={<MonoCompareArrows />}
onPress={handleTransferTokens}
isDisabled={frozen}
>
Transfer tokens
</Button>
<Button
startVisual={<MonoAdd />}
onPress={handleDistributeTokens}
isDisabled={frozen}
isDisabled={frozen || paused}
>
Distribute Tokens
</Button>
<FreezeInvestor
investorAccount={investorAccount}
onChanged={handlePauseChange}
/>
<FreezeInvestor investorAccount={investorAccount} />
</Stack>
</Stack>
</>
Expand Down
5 changes: 3 additions & 2 deletions packages/apps/rwa-demo/src/app/(app)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use client';
import { SideBarLayout } from '@kadena/kode-ui/patterns';

import { AssetInfo } from '@/components/AssetInfo/AssetInfo';
import { AssetForm } from '@/components/AssetSwitch/AssetForm';
import { SupplyCount } from '@/components/SupplyCount/SupplyCount';
import { getAsset } from '@/utils/getAsset';
import { Heading, Link, Stack } from '@kadena/kode-ui';
import React from 'react';
Expand Down Expand Up @@ -41,7 +41,8 @@ const RootLayout = ({
sidebar={<SideBar />}
>
<Stack width="100%" flexDirection="column" gap="sm">
<SupplyCount />
<AssetInfo />

{children}
</Stack>
</SideBarLayout>
Expand Down
4 changes: 3 additions & 1 deletion packages/apps/rwa-demo/src/app/(app)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
'use client';

import { AgentRootPage } from '@/components/HomePage/AgentRootPage';
import { InvestorRootPage } from '@/components/HomePage/InvestorRootPage';
import { OwnerRootPage } from '@/components/HomePage/OwnerRootPage';
import { useAccount } from '@/hooks/account';
import { getAsset } from '@/utils/getAsset';

const Home = () => {
const { isAgent } = useAccount();
const { isAgent, isInvestor } = useAccount();

console.log('asset', getAsset());
return (
<>
{!isAgent && <OwnerRootPage />}
{isAgent && <AgentRootPage />}
{isInvestor && <InvestorRootPage />}
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
'use client';
import { getBalance as getBalanceFnc } from '@/services/getBalance';
import { isAgent } from '@/services/isAgent';
import { isFrozen } from '@/services/isFrozen';
import { isInvestor } from '@/services/isInvestor';
import { getAccountCookieName } from '@/utils/getAccountCookieName';
import type { ICommand, IUnsignedCommand } from '@kadena/client';
import { useRouter } from 'next/navigation';
Expand All @@ -21,7 +24,10 @@ export interface IAccountContext {
logout: () => void;
sign: (tx: IUnsignedCommand) => Promise<ICommand | undefined>;
isAgent: boolean;
isInvestor: boolean;
isFrozen: boolean;
selectAccount: (account: IWalletAccount) => void;
getBalance: () => Promise<number>;
}

export const AccountContext = createContext<IAccountContext>({
Expand All @@ -32,21 +38,40 @@ export const AccountContext = createContext<IAccountContext>({
logout: () => {},
sign: async () => undefined,
isAgent: false,
isInvestor: false,
isFrozen: false,
selectAccount: () => {},
getBalance: async () => 0,
});

export const AccountProvider: FC<PropsWithChildren> = ({ children }) => {
const [account, setAccount] = useState<IWalletAccount>();
const [accounts, setAccounts] = useState<IWalletAccount[]>();
const [isMounted, setIsMounted] = useState(false);
const [isAgentState, setIsAgentState] = useState(false);
const [isInvestorState, setIsInvestorState] = useState(false);
const [isFrozenState, setIsFrozenState] = useState(false);

const router = useRouter();

const checkIsAgent = async (account: IWalletAccount) => {
const resIsAgent = await isAgent({ agent: account.address });
setIsAgentState(!!resIsAgent);
};
const checkIsInvestor = async (account: IWalletAccount) => {
const resIsInvestor = await isInvestor({ account });
setIsInvestorState(!!resIsInvestor);
};
const checkIsFrozen = async (account: IWalletAccount) => {
const res = await isFrozen({
investorAccount: account.address,
account: account!,
});

if (typeof res === 'boolean') {
setIsFrozenState(res);
}
};

const selectAccount = (account: IWalletAccount) => {
setAccount(account);
Expand Down Expand Up @@ -76,7 +101,12 @@ export const AccountProvider: FC<PropsWithChildren> = ({ children }) => {

setAccounts(undefined);
setAccount(payload.accounts[0]);
localStorage.setItem(
getAccountCookieName(),
JSON.stringify(payload.accounts[0]),
);
close();
router.replace('/');
}, [router]);

const logout = useCallback(() => {
Expand All @@ -102,11 +132,16 @@ export const AccountProvider: FC<PropsWithChildren> = ({ children }) => {
useEffect(() => {
if (!account) {
setIsAgentState(false);
setIsInvestorState(false);
return;
}

// eslint-disable-next-line @typescript-eslint/no-floating-promises
checkIsAgent(account);
// eslint-disable-next-line @typescript-eslint/no-floating-promises
checkIsInvestor(account);
// eslint-disable-next-line @typescript-eslint/no-floating-promises
checkIsFrozen(account);
}, [account]);

const sign = async (tx: IUnsignedCommand): Promise<ICommand | undefined> => {
Expand All @@ -121,6 +156,17 @@ export const AccountProvider: FC<PropsWithChildren> = ({ children }) => {
return payload.transaction;
};

const getBalance = async () => {
if (!account) return 0;
const res = await getBalanceFnc({
investorAccount: account.address,
account,
});

if (typeof res !== 'number') return 0;
return res;
};

return (
<AccountContext.Provider
value={{
Expand All @@ -131,7 +177,10 @@ export const AccountProvider: FC<PropsWithChildren> = ({ children }) => {
sign,
isMounted,
isAgent: isAgentState,
isInvestor: isInvestorState,
isFrozen: isFrozenState,
selectAccount,
getBalance,
}}
>
{children}
Expand Down
Loading

0 comments on commit 26db24d

Please sign in to comment.