Skip to content

Commit

Permalink
ui modal + types
Browse files Browse the repository at this point in the history
  • Loading branch information
trevormil committed Mar 20, 2024
1 parent 234df16 commit 702e87f
Show file tree
Hide file tree
Showing 12 changed files with 1,461 additions and 598 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blockin",
"version": "1.2.107",
"version": "1.2.114",
"description": "",
"files": [
"dist"
Expand Down Expand Up @@ -32,7 +32,7 @@
"build:ui": "rollup --config ./ui-rollup.config.js && npm run postuirollup",
"build:core": "rollup --config ./rollup.config.js && npm run postcorerollup",
"postcorerollup": "cp ./dist/index.d.ts ./dist/index.d.cts",
"postuirollup": "mv ./dist/index* ./dist/ui && cp ./dist/ui/index.d.ts ./dist/ui/index.d.cts",
"postuirollup": "mv ./dist/index.js* ./dist/ui && mv ./dist/index.cjs* ./dist/ui && cp ./dist/ui/index.d.ts ./dist/ui/index.d.cts",
"storybook": "storybook dev -p 6006",
"storybook:export": "storybook build",
"build-storybook": "storybook build"
Expand Down
2 changes: 1 addition & 1 deletion src/types/ChainDriver.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface IGetPublicKey { (address: string): Uint8Array }
export interface IGetAssetDetails { (txnId: string): Promise<any> }
export interface ILookupTransactionById { (txnId: string): Promise<any> }
export interface IGetChallengeStringFromBytesToSign { (originalBytes: Uint8Array): Promise<string> }
export interface IVerifySignature { (message: string, signature: string): Promise<void> }
export interface IVerifySignature { (message: string, signature: string, publicKey?: string): Promise<void> }
export interface IVerifyAssets<T extends NumberType> {
(address: string, resources: string[], assets: AssetConditionGroup<T> | undefined, balancesSnapshot?: object): Promise<any>
}
Expand Down
7 changes: 4 additions & 3 deletions src/types/verify.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type NumberType = string | bigint | number | boolean;
export type NumberType = string | bigint | number;

export interface UintRange<T extends NumberType> {
start: T,
end: T,
Expand Down Expand Up @@ -106,9 +107,9 @@ export function convertAssetConditionGroup<T extends NumberType, U extends Numbe
options: ownershipRequirements.options ? {
numMatchesForVerification:
ownershipRequirements.options.numMatchesForVerification ? convertFunction(ownershipRequirements.options.numMatchesForVerification) :
populateDefaults ? 0 as U : undefined
populateDefaults ? convertFunction(0 as T) : undefined
} : populateDefaults ? {
numMatchesForVerification: 0 as U
numMatchesForVerification: convertFunction(0 as T)
} : undefined
}
}
Expand Down
1 change: 1 addition & 0 deletions src/ui/BlockinUIDisplay/BlockinUIDisplay.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export const SuccessfulSignAndVerify = () => {
// }
// ]}
allowTimeSelect
skipModalStep
/>
</div>
}
Expand Down
20 changes: 17 additions & 3 deletions src/ui/BlockinUIDisplay/BlockinUIDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { CopyOutlined, InfoCircleOutlined } from "@ant-design/icons";
import { Typography, Tooltip } from "antd";
import "./BlockinUIDisplay.scss";
import { NumberType } from "../../types/verify.types";
import { createChallenge } from "../..";

const Link = ({ url, text }: { url: string, text?: string }) => {
return <a className="blockin-link" href={url} target='_blank' rel="noreferrer">{text ? text : url}</a>
Expand Down Expand Up @@ -44,7 +45,8 @@ const BlockinUIDisplay: React.FC<BlockinUIDisplayProps<NumberType>> = ({
hideConnectVsSignInHelper,
allowTimeSelect,
maxTimeInFuture,
customBeforeSigningWarning
customBeforeSigningWarning,
skipModalStep,

}) => {
const [signInModalIsVisible, setSignInModalIsVisible] = useState(false);
Expand Down Expand Up @@ -165,8 +167,20 @@ const BlockinUIDisplay: React.FC<BlockinUIDisplayProps<NumberType>> = ({
</button> :
<>{connected &&
<button className='blockin-button main-button main-display button-style-override' style={buttonStyle} onClick={
() => setSignInModalIsVisible(!signInModalIsVisible)
}>
async () => {
if (skipModalStep) {
if (!challengeParams) {
throw new Error('You must provide challengeParams')
}
if (!signAndVerifyChallenge) {
throw new Error('You must provide signAndVerifyChallenge')
}

await signAndVerifyChallenge(createChallenge(challengeParams));
} else {
setSignInModalIsVisible(!signInModalIsVisible)
}
}}>
Sign In
</button>
}</>
Expand Down
6 changes: 6 additions & 0 deletions src/ui/BlockinUIDisplay/BlockinUIDisplay.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,10 @@ export type BlockinUIDisplayProps<T extends NumberType> = {
* Provide a warning, such as other sites that the signature / authentication code will be given to (i.e. other sites that are to be trusted).
*/
customBeforeSigningWarning?: string


/**
* If true, the modal will not be displayed. We go directly to prompt the user to sign the challenge.
*/
skipModalStep?: boolean
}
1 change: 1 addition & 0 deletions src/ui/SignInModal/SignInModal.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const SuccessfulSignAndVerify = () => {
setModalIsVisible={setModalIsVisible}
selectedChainName={chain}
address={'0xe00dd9d317573f7b4868d8f2578c65544b153a27'}
nonWalletSignIn
customBeforeSigningWarning="This sign-in will also be given to the parent window that sent you here."
signAndVerifyChallenge={async (challenge: string) => {
const signChallengeResponse = await handleSignChallengeSuccess(challenge);
Expand Down
Loading

0 comments on commit 702e87f

Please sign in to comment.