Skip to content

Commit

Permalink
Merge pull request #1558 from zeitgeistpm/staging
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Jul 14, 2023
2 parents 4846cae + 734aaba commit ca1365a
Show file tree
Hide file tree
Showing 25 changed files with 249 additions and 182 deletions.
30 changes: 18 additions & 12 deletions components/account/AccountButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ const AccountButton: FC<{
selectWallet,
disconnectWallet,
isNovaWallet,
proxyFor,
getProxyFor,
realAddress,
} = useWallet();

const proxy = proxyFor?.[activeAccount?.address];
const proxy = getProxyFor(activeAccount?.address);

const accountModals = useAccountModals();
const { locationAllowed, isUsingVPN } = useUserLocation();
Expand Down Expand Up @@ -266,17 +266,23 @@ const AccountButton: FC<{
<label className="text-purple-900 text-xs italic mb-2">
Account is acting proxy for:
</label>
<div className="flex items-center gap-1">
<div className="text-white text-sm">
{shortenAddress(realAddress, 7, 7)}
{realAddress && (
<div className="flex items-center gap-1">
<div className="text-white text-sm">
{shortenAddress(
realAddress,
7,
7,
)}
</div>
<div className="text-purple-800">
<CopyIcon
size={14}
copyText={realAddress}
/>
</div>
</div>
<div className="text-purple-800">
<CopyIcon
size={14}
copyText={realAddress}
/>
</div>
</div>
)}
</div>
</div>
</div>
Expand Down
3 changes: 1 addition & 2 deletions components/account/AccountModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import { ZTG } from "@zeitgeistpm/sdk-next";
import { useChainConstants } from "lib/hooks/queries/useChainConstants";

const AccountModalContent: FC = () => {
const { activeAccount, disconnectWallet, accounts, selectAccount, proxyFor } =
const { activeAccount, disconnectWallet, accounts, selectAccount } =
useWallet();

const proxy = proxyFor?.[activeAccount?.address];
const { data: activeBalance } = useZtgBalance(activeAccount?.address);
const { data: constants } = useChainConstants();

Expand Down
2 changes: 1 addition & 1 deletion components/create/editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const QuillEditor = dynamic(() => import("components/ui/QuillEditor"), {
const createMarketStateAtom = persistentAtom<MarketDraft.MarketDraftState>({
key: "market-creation-form",
defaultValue: MarketDraft.empty(),
migrations: [],
migrations: [() => MarketDraft.empty()],
});

export const MarketEditor = () => {
Expand Down
18 changes: 9 additions & 9 deletions components/create/editor/Publishing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ export const Publishing = ({ editor }: PublishingProps) => {
const params = useMemo(() => {
let signer = wallet.getSigner();

const real =
wallet.proxyFor?.enabled && wallet.proxyFor?.address
? (wallet.activeAccount as KeyringPairOrExtSigner)
: signer;
if (!editor.isValid || !chainTime || !signer) return;

if (editor.isValid && chainTime && signer) {
const proxy = wallet.getProxyFor(wallet.activeAccount?.address);

if (proxy && proxy.enabled) {
return marketFormDataToExtrinsicParams(
editor.form,
real,
{ address: wallet.realAddress } as KeyringPairOrExtSigner,
chainTime,
signer,
);
}
return;

return marketFormDataToExtrinsicParams(editor.form, signer, chainTime);
}, [editor.form, chainTime, wallet.activeAccount]);

const feesEnabled = !(
Expand Down Expand Up @@ -87,12 +87,12 @@ export const Publishing = ({ editor }: PublishingProps) => {
(a) => a.name === editor.form.currency,
);

const { data: ztgBalance } = useBalance(wallet.activeAccount?.address, {
const { data: ztgBalance } = useBalance(wallet.realAddress, {
Ztg: null,
});

const { data: foreignAssetBalance } = useBalance(
wallet.activeAccount?.address,
wallet.realAddress,
baseCurrency?.assetId,
);

Expand Down
4 changes: 1 addition & 3 deletions components/create/editor/Summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,7 @@ export const MarketSummary = ({ editor }: MarketSummaryProps) => {
: Intl.DateTimeFormat("default", {
dateStyle: "medium",
timeStyle: "short",
}).format(
blockDate(chainTime!, form.gracePeriod?.block!).getTime(),
)}
}).format(new Date(form.gracePeriod?.date!).getTime())}
</div>
</div>
<div className="flex justify-center gap-2 items-center mb-2 md:mb-0">
Expand Down
10 changes: 3 additions & 7 deletions components/create/editor/inputs/BlockPeriod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const BlockPeriodPicker: React.FC<BlockPeriodPickerProps> = ({
name,
value: {
type: "date",
block: dateBlock(chainTime, new Date(event.target.value)),
date: event.target.value,
},
},
});
Expand All @@ -78,7 +78,7 @@ export const BlockPeriodPicker: React.FC<BlockPeriodPickerProps> = ({
name,
value: {
type: "date",
block: dateBlock(chainTime, new Date(event.target.value)),
date: event.target.value,
},
},
});
Expand Down Expand Up @@ -159,11 +159,7 @@ export const BlockPeriodPicker: React.FC<BlockPeriodPickerProps> = ({
}`}
placeholder="Set Custom Date"
isValid={value?.type === "date" && isValid}
value={
chainTime && value?.type === "date"
? blockDate(chainTime, value.block).toISOString()
: undefined
}
value={chainTime && value?.type === "date" ? value.date : undefined}
onChange={handleDateChange}
onBlur={handleDateBlur}
/>
Expand Down
6 changes: 5 additions & 1 deletion components/create/editor/inputs/DateTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ export const DateTimePicker: React.FC<DateTimePickerProps> = ({
ref={inputRef}
name={name}
type="datetime-local"
value={moment(value).format("YYYY-MM-DDTHH:mm")}
value={
value
? moment(value).format("YYYY-MM-DDTHH:mm")
: moment().hours(0).minutes(0).format("YYYY-MM-DDTHH:mm")
}
onChange={handleChange}
onBlurCapture={handleBlur}
/>
Expand Down
36 changes: 21 additions & 15 deletions components/create/editor/inputs/Oracle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const OracleInput = forwardRef(
};

const handleUseConnectedAccount = () => {
if (!wallet?.realAddress) return;
onChange?.({
type: "change",
target: {
Expand All @@ -68,11 +69,11 @@ export const OracleInput = forwardRef(
};

const isSelectedAccount = wallet.realAddress === value;
const proxy = wallet.proxyFor?.[wallet.activeAccount?.address];
const proxy = wallet.getProxyFor(wallet.activeAccount?.address);
const accountname =
proxy && proxy.enabled
proxy && proxy?.enabled
? "Proxied"
: wallet.activeAccount.name ?? "Account";
: wallet.activeAccount?.name ?? "Account";

return (
<div className={`relative ${className}`}>
Expand Down Expand Up @@ -123,18 +124,23 @@ export const OracleInput = forwardRef(
isSelectedAccount ? "bg-nyanza-base" : "bg-gray-200"
}`}
>
<div className="pointer-events-none">
<Avatar address={wallet.realAddress} size={18} />
</div>
<span className="font-semibold center gap-4">
{accountname ? (
<>
{accountname} {shortenAddress(wallet.realAddress, 0, 6)}
</>
) : (
<>{shortenAddress(wallet.realAddress, 6, 6)}</>
)}
</span>
{wallet.realAddress && (
<>
<div className="pointer-events-none">
<Avatar address={wallet.realAddress} size={18} />
</div>
<span className="font-semibold center gap-4">
{accountname ? (
<>
{accountname}{" "}
{shortenAddress(wallet.realAddress, 0, 6)}
</>
) : (
<>{shortenAddress(wallet.realAddress, 6, 6)}</>
)}
</span>
</>
)}
</div>
</button>
</div>
Expand Down
15 changes: 10 additions & 5 deletions components/create/editor/inputs/answers/Categorical.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { MdOutlineDragIndicator } from "react-icons/md";
import { FormEvent } from "../../types";

export type CategoricalAnswersInputProps = {
name?: string;
name: string;
value?: CategoricalAnswers | YesNoAnswers;
onChange?: (event: FormEvent<CategoricalAnswers>) => void;
onBlur?: (event: FormEvent<CategoricalAnswers>) => void;
Expand Down Expand Up @@ -57,7 +57,9 @@ export const CategoricalAnswersInput = ({
value: {
type: "categorical",
answers:
value?.answers.map((v, i) => (i === index ? answer : v)) ?? [],
value?.answers.map((v: string, i: number) =>
i === index ? answer : v,
) ?? [],
},
},
});
Expand Down Expand Up @@ -93,10 +95,12 @@ export const CategoricalAnswersInput = ({
const handleDragEnd = (event: DragEndEvent) => {
const { active, over } = event;

if (active.id !== over.id) {
if (over && active.id !== over.id) {
const oldIndex = value?.answers.findIndex((v) => v === active.id);
const newIndex = value?.answers.findIndex((v) => v === over.id);

if (!oldIndex || !newIndex || !value?.answers) return;

onChange?.({
type: "change",
target: {
Expand All @@ -112,7 +116,8 @@ export const CategoricalAnswersInput = ({

const draggingDisabled =
disabled ||
value?.answers.length < 2 ||
!value?.answers ||
value?.answers?.length < 2 ||
uniq(value?.answers).length < value?.answers.length;

return (
Expand All @@ -135,7 +140,7 @@ export const CategoricalAnswersInput = ({
<AnswerInput
key={index}
id={answer}
disabled={disabled}
disabled={disabled ?? false}
value={answer}
onChange={handleChange(index, onChange)}
onBlur={handleChange(index, onBlur)}
Expand Down
6 changes: 3 additions & 3 deletions components/create/editor/inputs/answers/Scalar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Toggle from "components/ui/Toggle";
import DateTimePicker from "../DateTime";

export type ScalarAnswersInputProps = {
name?: string;
name: string;
value?: ScalarAnswers;
onChange?: (event: FormEvent<ScalarAnswers>) => void;
onBlur?: (event: FormEvent<ScalarAnswers>) => void;
Expand Down Expand Up @@ -50,7 +50,7 @@ export const ScalarAnswersInput = ({
name,
value: {
type: "scalar",
numberType: value.numberType,
numberType: value?.numberType ?? "number",
answers: (value?.answers.map((v, i) =>
i === index ? newValue : v,
) ?? []) as [number, number],
Expand All @@ -75,7 +75,7 @@ export const ScalarAnswersInput = ({
name,
value: {
type: "scalar",
numberType: value.numberType,
numberType: value?.numberType ?? "number",
answers: (value?.answers.map((v, i) =>
i === index ? newValue : v,
) ?? []) as [number, number],
Expand Down
8 changes: 7 additions & 1 deletion components/create/editor/inputs/answers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const AnswersInput = ({
<div>
{value?.type === "categorical" && (
<CategoricalAnswersInput
name="categorical-answers"
value={value}
onBlur={handleBlur}
onChange={handleChange}
Expand All @@ -95,14 +96,19 @@ export const AnswersInput = ({
{value?.type === "scalar" && (
<div className="mb-3">
<ScalarAnswersInput
name="scalar-answers"
value={value}
onBlur={handleBlur}
onChange={handleChange}
/>
</div>
)}
{value?.type === "yes/no" && (
<CategoricalAnswersInput disabled={true} value={value} />
<CategoricalAnswersInput
name="categorical-answers"
disabled={true}
value={value}
/>
)}
</div>
</>
Expand Down
2 changes: 1 addition & 1 deletion components/portfolio/PortfolioIdentity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const PortfolioIdentity = ({ address }: { address: string }) => {
const wallet = useWallet();
const { data: identity } = useIdentity(address);

const proxy = wallet.proxyFor?.[wallet.activeAccount?.address];
const proxy = wallet.getProxyFor(wallet.activeAccount?.address);

const isProxying = Boolean(
proxy && proxy.enabled && proxy.address === address,
Expand Down
7 changes: 4 additions & 3 deletions lib/hooks/useCrossChainExtrinsic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@ export const useCrossChainExtrinsic = <T>(

let extrinsic = extrinsicFn(params);

const proxy = wallet?.proxyFor?.[wallet.activeAccount?.address];
const proxy = wallet?.getProxyFor(wallet.activeAccount?.address);
let signer = wallet.getSigner();

if (proxy?.enabled && proxy?.address) {
if (extrinsic && proxy?.enabled && proxy?.address) {
console.info("Proxying cross chain transaction");
extrinsic = sdk.api.tx.proxy.proxy(proxy?.address, "Any", extrinsic);
}

if (!extrinsic || !sourceChainApi || !destinationChainApi) return;
if (!signer || !extrinsic || !sourceChainApi || !destinationChainApi)
return;
signAndSend(
extrinsic,
signer,
Expand Down
6 changes: 4 additions & 2 deletions lib/hooks/useExtrinsic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ export const useExtrinsic = <T>(
throw new Error("SDK is not RPC");
}

let signer = wallet.getSigner();
if (!signer) return;

setIsLoading(true);

let extrinsic = extrinsicFn(params);
if (!extrinsic) return;

const proxy = wallet?.proxyFor?.[wallet.activeAccount?.address];
let signer = wallet.getSigner();
const proxy = wallet?.getProxyFor(wallet.activeAccount?.address);

if (proxy?.enabled && proxy?.address) {
console.info("Proxying transaction");
Expand Down
Loading

0 comments on commit ca1365a

Please sign in to comment.