Skip to content
Open
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ REACT_APP_DIMO_IDENTITY_URL=https://identity-api.dev.dimo.zone/query
REACT_APP_DEVICES_API_URL=http://0.0.0.0:8080/https://devices-api.dev.dimo.zone/v1
REACT_APP_DEVICE_DEFINITIONS_URL=https://device-definitions-api.dev.dimo.zone
REACT_APP_POLYGON_RPC_URL=https://polygon-amoy.g.alchemy.com/v2/-0PsUljNtSdA31-XWj-kL_L1Mx2ArYfS
REACT_APP_ZERODEV_BUNDLER_URL=https://rpc.zerodev.app/api/v2/bundler/f4d1596a-edfd-4063-8f99-2d8835e07739
REACT_APP_ZERODEV_PAYMASTER_URL=https://rpc.zerodev.app/api/v2/paymaster/f4d1596a-edfd-4063-8f99-2d8835e07739
REACT_APP_ZERODEV_BUNDLER_URL=https://rpc.zerodev.app/api/v2/bundler/<zero-dev-api-key>
REACT_APP_ZERODEV_PAYMASTER_URL=https://rpc.zerodev.app/api/v2/paymaster/<zero-dev-api-key>
REACT_APP_ENVIRONMENT=dev
REACT_APP_SMARTCAR_CLIENT_ID=f0378698-ab62-40ca-ae37-5e7fd9cab711
REACT_APP_TESLA_CLIENT_ID=194119ca43c7-4528-9415-3116fb5868cd
Expand Down
8 changes: 7 additions & 1 deletion src/hooks/useParamsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { UiStates } from '../enums';
import { setForceEmail } from '../stores/AuthStateStore';
import { parseExpirationDate, getDefaultExpirationDate } from '../utils/dateUtils';

// Params that are handles empty values
const DEFAULTED_PARAMS = ['expirationDate'];

export const useParamsHandler = (DEFAULT_CONTEXT: AllParams) => {
const [devCredentialsState, setDevCredentialsState] =
useState<AllParams>(DEFAULT_CONTEXT);
Expand Down Expand Up @@ -74,12 +77,15 @@ export const useParamsHandler = (DEFAULT_CONTEXT: AllParams) => {
})),
};

const hasValidValue = (key: string, value: unknown) =>
DEFAULTED_PARAMS.includes(key) || value !== undefined;

const applyDevCredentialsConfig = (config: Record<string, unknown>) => {
Object.entries(config).forEach(([key, value]) => {
if (
key in specialSetters &&
specialSetters[key as keyof typeof specialSetters] &&
value !== undefined
hasValidValue(key, value)
) {
specialSetters[key as keyof typeof specialSetters](value);
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/models/__tests__/vehicle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jest.mock('@dimo-network/transactions', () => ({
describe('LocalVehicle', () => {
const mockVehicleNode = {
tokenId: 123,
tokenDID: 'did:erc721:0xbA5738a18d83D41847dfFbDC6101d37C69c9B0cF:123',
imageURI: 'http://image.url',
definition: {
id: 'mock_def_id',
Expand Down Expand Up @@ -49,6 +50,7 @@ describe('LocalVehicle', () => {
it('normalizes vehicle data', () => {
expect(localVehicle.normalize()).toEqual({
tokenId: 123,
tokenDID: 'did:erc721:0xbA5738a18d83D41847dfFbDC6101d37C69c9B0cF:123',
imageURI: 'http://image.url',
make: 'Tesla',
model: 'Model S',
Expand Down
2 changes: 2 additions & 0 deletions src/models/vehicle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { fetchDeviceDefinition, VehicleNode } from '../services';

export interface Vehicle {
tokenId: number;
tokenDID: string;
imageURI: string;
make: string;
model: string;
Expand Down Expand Up @@ -67,6 +68,7 @@ export class LocalVehicle {
normalize() {
return {
tokenId: this.tokenId,
tokenDID: this.vehicleNode.tokenDID,
imageURI: this.vehicleNode.imageURI,
make: this.make,
model: this.model,
Expand Down
4 changes: 4 additions & 0 deletions src/services/__tests__/vehicleService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ beforeEach(() => {
nodes: [
{
tokenId: 1,
tokenDID: 'did:erc721:0xbA5738a18d83D41847dfFbDC6101d37C69c9B0cF:1',
imageURI: 'http://image.url',
definition: {
id: 'tesla_model_3_2019',
Expand All @@ -34,6 +35,7 @@ beforeEach(() => {
},
{
tokenId: 2,
tokenDID: 'did:erc721:0xbA5738a18d83D41847dfFbDC6101d37C69c9B0cF:2',
imageURI: 'http://image.url',
definition: {
id: 'ford_bronco_2023',
Expand Down Expand Up @@ -177,6 +179,7 @@ it('Returns vehicles with the correct shape in compatible and incompatible array
expect(vehicle).toEqual(
expect.objectContaining({
tokenId: expect.any(Number),
tokenDID: expect.any(String),
imageURI: expect.anything(),
shared: expect.any(Boolean),
expiresAt: expect.any(String),
Expand All @@ -201,6 +204,7 @@ it('Returns incompatible vehicles with the correct shape when no compatible vehi
expect(vehicle).toEqual(
expect.objectContaining({
tokenId: expect.any(Number),
tokenDID: expect.any(String),
imageURI: expect.anything(),
shared: expect.any(Boolean),
expiresAt: expect.any(String),
Expand Down
2 changes: 2 additions & 0 deletions src/services/identityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const GET_VEHICLES = gql`
) {
nodes {
tokenId
tokenDID
imageURI
definition {
id
Expand Down Expand Up @@ -62,6 +63,7 @@ const GET_VEHICLES = gql`

export type VehicleNode = {
tokenId: number;
tokenDID: string;
imageURI: string;
definition: {
id: string;
Expand Down