Migrate grateWizard from React/Next.js to native Nuxt integration
- Port all React components to Vue 3 (GwTabs, GwMN, GwCRA, GwCRS, GwMap, GwRelations, GwPerimeterList) - Port hooks to Vue composables (useCesiumProfiles, useSavedPerimeters) - Copy pure TS services and utils (duniter/, ss58, gratewizard utils) - Add Leaflet + Geoman + MarkerCluster dependencies - Serve grateWizard as popup via /gratewizard?popup (layout: false) and info page on /gratewizard (with Librodrome layout) - Remove public/gratewizard-app/ static Next.js export - Refine UI: compact tabs, buttons, inputs, cards, perimeter list - Use Ğ1 breve everywhere, French locale for all dates and amounts - Rename roles: vendeur→offre / acheteur→reçoit le produit ou service - Rename prix→évaluation in all visible text - Add calculated result column in CRA and CRS relation tables - DU/Ğ1 selector uses toggle switch (same as role toggle) - Auto-scroll to monetary data card on polygon selection Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
68
app/services/duniter/v2.ts
Normal file
68
app/services/duniter/v2.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { ss58ToV1Pubkey } from '~/utils/ss58';
|
||||
import type { DuniterAdapter, MonetaryData } from './types';
|
||||
|
||||
const SQUID_URL = 'https://gt-squid.axiom-team.fr/v1/graphql';
|
||||
|
||||
async function gql<T>(query: string): Promise<T> {
|
||||
const res = await fetch(SQUID_URL, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ query }),
|
||||
});
|
||||
const json = await res.json();
|
||||
if (json.errors) throw new Error(json.errors[0].message);
|
||||
return json.data;
|
||||
}
|
||||
|
||||
export const v2Adapter: DuniterAdapter = {
|
||||
async fetchMonetary(): Promise<MonetaryData> {
|
||||
const data = await gql<{
|
||||
universalDividends: { nodes: (Omit<MonetaryData, 'udBlockNumbers'> & Record<string, unknown>)[] };
|
||||
}>(`{
|
||||
universalDividends(first: 1, orderBy: BLOCK_NUMBER_DESC) {
|
||||
nodes { monetaryMass membersCount amount timestamp blockNumber }
|
||||
}
|
||||
}`);
|
||||
return { ...data.universalDividends.nodes[0], udBlockNumbers: [] };
|
||||
},
|
||||
|
||||
async fetchMemberPubkeys(): Promise<string[]> {
|
||||
const accountIds: string[] = [];
|
||||
let offset = 0;
|
||||
const pageSize = 1000;
|
||||
|
||||
while (true) {
|
||||
const data = await gql<{
|
||||
identities: { nodes: { accountId: string }[] };
|
||||
}>(`{
|
||||
identities(first: ${pageSize}, offset: ${offset}, filter: { isMember: { equalTo: true } }) {
|
||||
nodes { accountId }
|
||||
}
|
||||
}`);
|
||||
|
||||
const nodes = data.identities.nodes;
|
||||
for (const node of nodes) {
|
||||
accountIds.push(node.accountId);
|
||||
}
|
||||
|
||||
if (nodes.length < pageSize) break;
|
||||
offset += pageSize;
|
||||
}
|
||||
|
||||
// Convert SS58 accountIds to Cesium+ v1 base58 pubkeys
|
||||
const pubkeys: string[] = [];
|
||||
for (const id of accountIds) {
|
||||
try {
|
||||
pubkeys.push(ss58ToV1Pubkey(id));
|
||||
} catch {
|
||||
// Skip invalid addresses
|
||||
}
|
||||
}
|
||||
return pubkeys;
|
||||
},
|
||||
|
||||
async fetchMemberJoinBlocks(_pubkeys: string[]): Promise<Map<string, number>> {
|
||||
// TODO: implement using squid GraphQL after v2 migration
|
||||
return new Map();
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user