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

feat: upgrade to record v2 #30

Merged
merged 5 commits into from
Dec 23, 2023
Merged
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
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#000000"
},
"versionCode": 7
"versionCode": 10
},
"owner": "sns-manager"
}
Expand Down
12 changes: 12 additions & 0 deletions eas.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@
"SOLANA_RPC_URL": "https://helius-proxy.bonfida.com"
}
},
"solana-store": {
"distribution": "store",
"node": "18.15.0",
"autoIncrement": false,
"android": {
"buildType": "apk"
},
"env": {
"SOLANA_RPC_URL": "https://helius-proxy.bonfida.com"
}
},

"production": {
"extends": "base",
"distribution": "store",
Expand Down
66 changes: 10 additions & 56 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"build:mobile:preview:local": "eas build -p android --profile preview --local",
"build:mobile:prod": "eas build -p android --profile production",
"build:mobile:prod:local": "eas build -p android --profile production --local",
"build:mobile:prod:solana-store": "eas build -p android --profile solana-store",
"start": "npm run build:xnt && npx xnft web",
"bundle": "npm run build:xnft && npx xnft bundle",
"dev": "GENERATE_SOURCEMAP=false expo start --clear --web & npx xnft --iframe http://localhost:19006",
Expand All @@ -27,8 +28,9 @@
"@bonfida/name-offers": "0.0.10",
"@bonfida/name-tokenizer": "0.0.12",
"@bonfida/sns-emitter": "0.1.7",
"@bonfida/sns-react": "2.0.2",
"@bonfida/spl-name-service": "2.0.3",
"@bonfida/sns-react": "2.0.3",
"@bonfida/sns-records": "0.0.1-alpha.8",
"@bonfida/spl-name-service": "2.0.4",
"@coral-xyz/common-public": "0.2.0-latest.3375",
"@expo-google-fonts/dev": "*",
"@expo/html-elements": "0.5.1",
Expand Down
4 changes: 2 additions & 2 deletions publishing/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ app:
- purpose: icon
uri: ../assets/dapp-store/fida-icon-512x512.png
release:
address: ELyJgn72Kxn6gMSk46eTREP6MVi82JLbuowRA8XBG6Kp
address: 3hLUYLTWWa3uktaCq4NcYRfJK9LBqa73wiVr4PWzmbuo
media:
- purpose: icon
uri: ../assets/dapp-store/fida-icon-512x512.png
Expand All @@ -35,7 +35,7 @@ release:
uri: ../assets/dapp-store/screenshots/cart-payment-1080x1920.png
files:
- purpose: install
uri: build-1696412787473.apk
uri: ../application-b76ef173-b792-4037-8d3b-98ef6ba99ea6.apk
catalog:
en-US:
name: SNS Manager
Expand Down
2 changes: 1 addition & 1 deletion publishing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@solana-mobile/dapp-store-cli": "^0.5.2"
"@solana-mobile/dapp-store-cli": "^0.6.0"
}
}
21 changes: 11 additions & 10 deletions publishing/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { NavigatorTabsParamList } from "@src/types";
import { LanguageHeader } from "@src/components/Header";
import { SolanaProvider } from "@src/providers/SolanaProvider";
import ErrorBoundary from "react-native-error-boundary";
import { RecordV2BadgeExplanationModal } from "./components/RecordV2Badge";

const xnftjson = require("../xnft.json");

Expand All @@ -65,6 +66,7 @@ const modalConfig = {
DomainSizeModal: DomainSizeModal,
LanguageModal: LanguageModal,
TokenizeModal: TokenizeModal,
RecordV2BadgeExplanationModal: RecordV2BadgeExplanationModal,
};

const stackModal = createModalStack(modalConfig);
Expand Down
92 changes: 28 additions & 64 deletions src/components/EditPicture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@ import * as ImagePicker from "expo-image-picker";
import {
Record,
getDomainKeySync,
NameRegistryState,
transferInstruction,
NAME_PROGRAM_ID,
createNameRegistry,
updateInstruction,
Numberu32,
NAME_OFFERS_ID,
getRecordV2Key,
createRecordV2Instruction,
updateRecordV2Instruction,
validateRecordV2Content,
} from "@bonfida/spl-name-service";
import { registerFavourite } from "@bonfida/name-offers";
import { isTokenized } from "@bonfida/name-tokenizer";
import { t } from "@lingui/macro";
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
import { useStatusModalContext } from "@src/contexts/StatusModalContext";
import { useSolanaConnection } from "@src/hooks/xnft-hooks";
import { removeZeroRight } from "@src/utils/record/zero";
import { sendTx } from "@src/utils/send-tx";
import { WrapModal } from "./WrapModal";
import { unwrap } from "@src/utils/unwrap";
Expand Down Expand Up @@ -51,10 +48,7 @@ export const EditPicture = ({
try {
setLoading(true);
const ixs: TransactionInstruction[] = [];
const { pubkey, parent } = getDomainKeySync(
Record.Pic + "." + domain,
true,
);
const recordKey = getRecordV2Key(domain, Record.Pic);

try {
new URL(pic);
Expand All @@ -81,67 +75,37 @@ export const EditPicture = ({
}

// Check if exists
const info = await connection.getAccountInfo(pubkey);
const info = await connection.getAccountInfo(recordKey);
if (!info?.data) {
const space = 2_000;
const lamports = await connection.getMinimumBalanceForRentExemption(
space + NameRegistryState.HEADER_LEN,
);
const ix = await createNameRegistry(
connection,
Buffer.from([1]).toString() + Record.Pic,
space, // Hardcode space to 2kB
new PublicKey(publicKey),
new PublicKey(publicKey),
lamports,
undefined,
parent,
const ix = createRecordV2Instruction(
domain,
Record.Pic,
pic,
publicKey,
publicKey,
);
ixs.push(ix);
} else {
// Zero the data stored
const { registry } = await NameRegistryState.retrieve(
connection,
pubkey,
const ix = updateRecordV2Instruction(
domain,
Record.Pic,
pic,
publicKey,
publicKey,
);

if (!registry.owner.equals(new PublicKey(publicKey))) {
// Record was created before domain was transfered
const ix = transferInstruction(
NAME_PROGRAM_ID,
pubkey,
new PublicKey(publicKey),
registry.owner,
undefined,
parent,
new PublicKey(publicKey),
);
ixs.push(ix);
}

if (registry.data) {
const trimmed = removeZeroRight(registry.data);
const zero = Buffer.alloc(trimmed.length);
const ix = updateInstruction(
NAME_PROGRAM_ID,
pubkey,
new Numberu32(0),
zero,
new PublicKey(publicKey),
);
ixs.push(ix);
}
ixs.push(ix);
}

const data = Buffer.from(pic, "utf-8");
const ix = updateInstruction(
NAME_PROGRAM_ID,
pubkey,
new Numberu32(0),
data,
new PublicKey(publicKey),
ixs.push(
validateRecordV2Content(
true,
domain,
Record.Pic,
publicKey,
publicKey,
publicKey,
),
);
ixs.push(ix);

const sig = await sendTx(
connection,
Expand Down
Loading
Loading