Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update web sdk #381

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .github/workflows/build-lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ on:
# Allows us to run the workflow manually from the Actions tab
workflow_dispatch:

env:
NODE_VERSION: 18

jobs:
dependencies:
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -45,7 +48,7 @@ jobs:
- uses: actions/setup-node@v2
if: steps.fetch-dependencies.outputs.cache-hit != 'true'
with:
node-version: '16.20.2'
node-version: ${{ env.NODE_VERSION }}

- name: Download dependencies
if: steps.fetch-dependencies.outputs.cache-hit != 'true'
Expand All @@ -61,7 +64,7 @@ jobs:
submodules: 'recursive'
- uses: actions/setup-node@v2
with:
node-version: '16.20.2'
node-version: ${{ env.NODE_VERSION }}

- name: Get cached dependencies
uses: actions/cache@v2
Expand Down Expand Up @@ -95,7 +98,7 @@ jobs:
submodules: 'recursive'
- uses: actions/setup-node@v2
with:
node-version: '16.20.2'
node-version: ${{ env.NODE_VERSION }}

- name: Get cached dependencies
uses: actions/cache@v2
Expand Down Expand Up @@ -129,7 +132,7 @@ jobs:
submodules: 'recursive'
- uses: actions/setup-node@v2
with:
node-version: '16.20.2'
node-version: ${{ env.NODE_VERSION }}

- name: Get cached dependencies
uses: actions/cache@v2
Expand Down
12 changes: 10 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ build/Release
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
.pnp.*
.yarn/*
app/.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# OSX
.DS_Store
Expand All @@ -47,7 +55,7 @@ dll
out
storybook-static
app/1.preload.dev.worker.js
app/crypto.wasm
app/*.wasm
app/preload.dev.worker.js

.idea
Expand All @@ -70,4 +78,4 @@ target/

# Generated license disclaimer
scripts/disclaimer.rst
scripts/disclaimer.txt
scripts/disclaimer.txt
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16.20.2
v18
26 changes: 26 additions & 0 deletions .yarn/patches/@noble-hashes-npm-1.7.1-4106ab26c5.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
diff --git a/cryptoNode.js b/cryptoNode.js
index eba1a1ffb613251dad55ca8edb8f70308fc17ad9..065158bae18c506d8dced56be18e28f98465e055 100644
--- a/cryptoNode.js
+++ b/cryptoNode.js
@@ -9,7 +9,7 @@ exports.crypto = void 0;
* @module
*/
// @ts-ignore
-const nc = require("node:crypto");
+const nc = require("crypto");
exports.crypto = nc && typeof nc === 'object' && 'webcrypto' in nc
? nc.webcrypto
: nc && typeof nc === 'object' && 'randomBytes' in nc
diff --git a/esm/cryptoNode.js b/esm/cryptoNode.js
index 4f77e8f46c5e242e1e3cb92712dc65e95a8b8eb0..e1f13ada280e3d57c318098a749e5cefaa3bbe1a 100644
--- a/esm/cryptoNode.js
+++ b/esm/cryptoNode.js
@@ -6,7 +6,7 @@
* @module
*/
// @ts-ignore
-import * as nc from 'node:crypto';
+import * as nc from 'crypto';
export const crypto = nc && typeof nc === 'object' && 'webcrypto' in nc
? nc.webcrypto
: nc && typeof nc === 'object' && 'randomBytes' in nc
17 changes: 17 additions & 0 deletions .yarn/patches/react-hook-form-npm-6.15.8-53520bbd17.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
diff --git a/package.json b/package.json
index edfef9bf10ac54ba0b39f80e73eb1100a44cee68..cf15f1516d060024e425686c4dd80ef99f5908bf 100644
--- a/package.json
+++ b/package.json
@@ -18,10 +18,12 @@
"./package.json": "./package.json",
".": {
"import": "./dist/index.esm.js",
+ "types": "./dist/index.d.ts",
"require": "./dist/index.js"
},
"./dist/index.ie11": {
"import": "./dist/index.ie11.js",
+ "types": "./dist/index.d.ts",
"require": "./dist/index.ie11.js"
}
},
934 changes: 934 additions & 0 deletions .yarn/releases/yarn-4.6.0.cjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.6.0.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { displayTargetNet, getTargetNet, Net } from '~/utils/ConfigHelper';
import genesisBlocks from '~/constants/genesis.json';

import styles from './ConnectionSettingElement.module.scss';
import { nodeConsensusAndGlobal } from '~/node/nodeRequests';

interface Props {
displayText: string;
Expand Down Expand Up @@ -50,11 +51,7 @@ async function getConsensusAndGlobalFromNode(
port: string,
useSsl: boolean
) {
const result = await window.grpc.nodeConsensusAndGlobal(
address,
port,
useSsl
);
const result = await nodeConsensusAndGlobal(address, port, useSsl);
if (!result.successful) {
throw new Error(
'The node consensus status and cryptographic parameters could not be retrieved'
Expand Down Expand Up @@ -109,7 +106,10 @@ export default function ConnectionSetting({
} = await getConsensusAndGlobalFromNode(address, port, useSsl);
const genesis = await getGenesis();
if (genesis) {
if (consensusStatus.genesisBlock !== genesis.genesisBlock) {
if (
consensusStatus.genesisBlock.toString() !==
genesis.genesisBlock
) {
setFailedMessage(
'Connecting to a node running on a separate blockchain is not allowed'
);
Expand All @@ -122,7 +122,10 @@ export default function ConnectionSetting({

const targetNet = getTargetNet();
if (
!isMatchingGenesisBlock(consensusStatus.genesisBlock, targetNet)
!isMatchingGenesisBlock(
consensusStatus.genesisBlock.toString(),
targetNet
)
) {
setFailedMessage(
`The node is not part of ${displayTargetNet(
Expand All @@ -137,7 +140,7 @@ export default function ConnectionSetting({

if (!global && !genesis) {
await window.database.genesisAndGlobal.setValue(
consensusStatus.genesisBlock,
consensusStatus.genesisBlock.toString(),
nodeGlobal
);
}
Expand Down
14 changes: 8 additions & 6 deletions app/components/PickBakerStakeAmount.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import clsx from 'clsx';
import React, { useCallback } from 'react';
import { useFormContext, Validate } from 'react-hook-form';
import { isRewardStatusV1, isBakerAccount } from '@concordium/web-sdk';
import { AccountInfoType } from '@concordium/web-sdk';

import { collapseFraction, noOp } from '~/utils/basicHelpers';
import {
Expand Down Expand Up @@ -65,22 +65,24 @@ function useCapitalBoundCheck(
!capitalBound ||
!isValidCcdString(stake) ||
!rewardStatus ||
!isRewardStatusV1(rewardStatus)
rewardStatus.version !== 1
) {
return { showWarning: false };
}
const newStake = ccdToMicroCcd(stake);
const currentStake =
accountInfo && isBakerAccount(accountInfo)
? accountInfo.accountBaker.stakedAmount
accountInfo && accountInfo.type === AccountInfoType.Baker
? accountInfo.accountBaker.stakedAmount.microCcdAmount
: 0n;
const newTotalStake =
rewardStatus.totalStakedCapital - currentStake + newStake;
rewardStatus.totalStakedCapital.microCcdAmount -
currentStake +
newStake;
const limitAfterUpdate =
(newTotalStake *
BigInt(capitalBound * updateConstants.rewardFractionResolution)) /
BigInt(updateConstants.rewardFractionResolution) -
(poolStatus?.delegatedCapital || 0n);
(poolStatus?.delegatedCapital?.microCcdAmount || 0n);
if (limitAfterUpdate < newStake) {
return { showWarning: true, limitAfterUpdate };
}
Expand Down
6 changes: 3 additions & 3 deletions app/components/StakePendingChange.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import type { StakePendingChange as PendingChange } from '@concordium/web-sdk';
import { isRemovalPendingChange } from '@concordium/web-sdk';
import { StakePendingChangeType } from '@concordium/web-sdk';
import { useBlockChainParameters, useConsensusStatus } from '~/utils/dataHooks';
import { displayAsCcd } from '~/utils/ccd';
import {
Expand All @@ -22,7 +22,7 @@ export default function StakePendingChange({ pending }: Props) {
const rs = useAsyncMemo(
async () =>
cs !== undefined
? getRewardStatus(cs.lastFinalizedBlock)
? getRewardStatus(cs.lastFinalizedBlock.toString())
: undefined,
noOp,
[cs]
Expand All @@ -40,7 +40,7 @@ export default function StakePendingChange({ pending }: Props) {
);
const formattedDate = getFormattedDateString(changeAtDate);

return isRemovalPendingChange(pending) ? (
return pending.change === StakePendingChangeType.RemoveStake ? (
<>
Stake is being removed on
<br />
Expand Down
9 changes: 6 additions & 3 deletions app/components/Transfers/PickRecipient/PickRecipient.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import clsx from 'clsx';

import { AccountAddress, isAlias } from '@concordium/web-sdk';
import { AccountAddress } from '@concordium/web-sdk';

import { AddressBookEntry } from '~/utils/types';
import AddressBookEntryButton from '~/components/AddressBookEntryButton';
Expand All @@ -28,9 +28,12 @@ export default function PickRecipient({
}: Props) {
let filter;
if (senderAddress) {
const senderAccountAddress = new AccountAddress(senderAddress);
const senderAccountAddress = AccountAddress.fromBase58(senderAddress);
filter = (entry: AddressBookEntry) =>
!isAlias(senderAccountAddress, new AccountAddress(entry.address));
!AccountAddress.isAlias(
senderAccountAddress,
AccountAddress.fromBase58(entry.address)
);
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React, { useCallback, useMemo } from 'react';
import { useForm, useFormContext, Validate } from 'react-hook-form';
import { Redirect } from 'react-router';
import clsx from 'clsx';
import { isDelegatorAccount } from '@concordium/web-sdk';
import { AccountInfoType } from '@concordium/web-sdk';

import AccountCard from '~/components/AccountCard';
import Form from '~/components/Form';
import ErrorMessage from '~/components/Form/ErrorMessage';
Expand Down Expand Up @@ -163,7 +164,8 @@ export default function DelegationAmountPage({
const existing = getExistingDelegationValues(accountInfo);

const pendingChange =
accountInfo !== undefined && isDelegatorAccount(accountInfo)
accountInfo !== undefined &&
accountInfo.type === AccountInfoType.Delegator
? accountInfo.accountDelegation.pendingChange
: undefined;
const defaultValues: SubState = {
Expand Down Expand Up @@ -246,17 +248,23 @@ export default function DelegationAmountPage({
{poolInfo && (
<div className="body2 mV30">
<Label className="mB5">Target pool status</Label>
<SidedRow
left="Current pool:"
right={`${displayAsCcd(poolInfo.delegatedCapital)}`}
/>
<SidedRow
className="mT5"
left="Pool limit:"
right={`${displayAsCcd(
poolInfo.delegatedCapitalCap
)}`}
/>
{poolInfo.delegatedCapital !== undefined && (
<SidedRow
left="Current pool:"
right={`${displayAsCcd(
poolInfo.delegatedCapital
)}`}
/>
)}
{poolInfo.delegatedCapitalCap !== undefined && (
<SidedRow
className="mT5"
left="Pool limit:"
right={`${displayAsCcd(
poolInfo.delegatedCapitalCap
)}`}
/>
)}
</div>
)}
{showAccountCard && (
Expand All @@ -266,7 +274,11 @@ export default function DelegationAmountPage({
accountInfo={accountInfo}
existing={existing?.delegate?.amount}
estimatedFee={estimatedFee}
max={poolInfo ? poolInfo.delegatedCapitalCap : undefined}
max={
poolInfo?.delegatedCapitalCap
? poolInfo.delegatedCapitalCap.microCcdAmount
: undefined
}
hasPendingChange={pendingChange !== undefined}
/>
<p className="mB30">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { useForm, Validate } from 'react-hook-form';
import { OpenStatusText, isDelegatorAccount } from '@concordium/web-sdk';
import { AccountInfoType, OpenStatusText } from '@concordium/web-sdk';

import Form from '~/components/Form';
import ExternalLink from '~/components/ExternalLink';
Expand Down Expand Up @@ -62,14 +62,23 @@ export default function DelegationTargetPage({
// Throws if response is undefined.
const poolStatus = await getPoolInfo(bakerId);

if (
poolStatus.poolInfo === undefined ||
poolStatus.delegatedCapitalCap === undefined ||
poolStatus.delegatedCapital === undefined
) {
throw new Error();
}

if (poolStatus.poolInfo.openStatus !== OpenStatusText.OpenForAll) {
return 'Targeted validator does not allow new delegators';
}

if (
isDelegatorAccount(accountInfo) &&
poolStatus.delegatedCapitalCap - poolStatus.delegatedCapital <
accountInfo.accountDelegation.stakedAmount
accountInfo.type === AccountInfoType.Delegator &&
poolStatus.delegatedCapitalCap.microCcdAmount -
poolStatus.delegatedCapital.microCcdAmount <
accountInfo.accountDelegation.stakedAmount.microCcdAmount
) {
return "Your current stake would violate the targeted validator's cap";
}
Expand Down
2 changes: 1 addition & 1 deletion app/components/Transfers/withNonce.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function withNonce<TProps extends AccountAndNonce>(

useEffect(() => {
getNextAccountNonce(account.address)
.then((accountNonce) => setNonce(accountNonce.nonce))
.then((accountNonce) => setNonce(accountNonce.nonce.value))
.catch(() => setShowError(true));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Expand Down
Loading
Loading