Two years later it joined the United Provinces of Central America , but this federation disintegrated in 1838 , at which time Costa Rica proclaimed its sovereignty and independence .